Calling curl command using byte buffer in Arduino
I'm currently working on Arduino devices and tying to use "process library" to call my REST API. Here's my code snippet.
void api_send_cell(uint8_t* data)
{
Process p;
p.begin("curl");
p.addParameter("-X Post");
p.addParameter("-H content-type: multipart/form-data");
p.addParameter("-k " + url);
p.addParameter("-F data=");
p.addParameter(buf);
p.run();
}
But the thing is that my data (uin8_t buffer
) is a series of raw data which are just numbers from 0 to 255. Because the process needs string for parameter just like real command, I couldn't just put my data to addParamter
function.
So, I think I have to convert those bytes to string representation (for example, hex string) somehow.
Is there any solution for this problem?
curl arduino arduino-yun
add a comment |
I'm currently working on Arduino devices and tying to use "process library" to call my REST API. Here's my code snippet.
void api_send_cell(uint8_t* data)
{
Process p;
p.begin("curl");
p.addParameter("-X Post");
p.addParameter("-H content-type: multipart/form-data");
p.addParameter("-k " + url);
p.addParameter("-F data=");
p.addParameter(buf);
p.run();
}
But the thing is that my data (uin8_t buffer
) is a series of raw data which are just numbers from 0 to 255. Because the process needs string for parameter just like real command, I couldn't just put my data to addParamter
function.
So, I think I have to convert those bytes to string representation (for example, hex string) somehow.
Is there any solution for this problem?
curl arduino arduino-yun
do you have a Yun board? this is not the way to do network communication in Atmega of Arduino Yun. use the Bridge library.
– Juraj
Nov 23 '18 at 9:01
You can improve your question by specifying the format of the string you need. Should the numbers be separated by spaces, commas, tabs, or something else?
– jfowkes
Nov 23 '18 at 12:08
@Juraj I'm using dragino LG01, and I thought it is ok to use process library because there are some example codes using that library.
– goofcode
Nov 23 '18 at 17:22
add a comment |
I'm currently working on Arduino devices and tying to use "process library" to call my REST API. Here's my code snippet.
void api_send_cell(uint8_t* data)
{
Process p;
p.begin("curl");
p.addParameter("-X Post");
p.addParameter("-H content-type: multipart/form-data");
p.addParameter("-k " + url);
p.addParameter("-F data=");
p.addParameter(buf);
p.run();
}
But the thing is that my data (uin8_t buffer
) is a series of raw data which are just numbers from 0 to 255. Because the process needs string for parameter just like real command, I couldn't just put my data to addParamter
function.
So, I think I have to convert those bytes to string representation (for example, hex string) somehow.
Is there any solution for this problem?
curl arduino arduino-yun
I'm currently working on Arduino devices and tying to use "process library" to call my REST API. Here's my code snippet.
void api_send_cell(uint8_t* data)
{
Process p;
p.begin("curl");
p.addParameter("-X Post");
p.addParameter("-H content-type: multipart/form-data");
p.addParameter("-k " + url);
p.addParameter("-F data=");
p.addParameter(buf);
p.run();
}
But the thing is that my data (uin8_t buffer
) is a series of raw data which are just numbers from 0 to 255. Because the process needs string for parameter just like real command, I couldn't just put my data to addParamter
function.
So, I think I have to convert those bytes to string representation (for example, hex string) somehow.
Is there any solution for this problem?
curl arduino arduino-yun
curl arduino arduino-yun
edited Nov 23 '18 at 17:12
gre_gor
4,06792631
4,06792631
asked Nov 23 '18 at 4:22
goofcode
105
105
do you have a Yun board? this is not the way to do network communication in Atmega of Arduino Yun. use the Bridge library.
– Juraj
Nov 23 '18 at 9:01
You can improve your question by specifying the format of the string you need. Should the numbers be separated by spaces, commas, tabs, or something else?
– jfowkes
Nov 23 '18 at 12:08
@Juraj I'm using dragino LG01, and I thought it is ok to use process library because there are some example codes using that library.
– goofcode
Nov 23 '18 at 17:22
add a comment |
do you have a Yun board? this is not the way to do network communication in Atmega of Arduino Yun. use the Bridge library.
– Juraj
Nov 23 '18 at 9:01
You can improve your question by specifying the format of the string you need. Should the numbers be separated by spaces, commas, tabs, or something else?
– jfowkes
Nov 23 '18 at 12:08
@Juraj I'm using dragino LG01, and I thought it is ok to use process library because there are some example codes using that library.
– goofcode
Nov 23 '18 at 17:22
do you have a Yun board? this is not the way to do network communication in Atmega of Arduino Yun. use the Bridge library.
– Juraj
Nov 23 '18 at 9:01
do you have a Yun board? this is not the way to do network communication in Atmega of Arduino Yun. use the Bridge library.
– Juraj
Nov 23 '18 at 9:01
You can improve your question by specifying the format of the string you need. Should the numbers be separated by spaces, commas, tabs, or something else?
– jfowkes
Nov 23 '18 at 12:08
You can improve your question by specifying the format of the string you need. Should the numbers be separated by spaces, commas, tabs, or something else?
– jfowkes
Nov 23 '18 at 12:08
@Juraj I'm using dragino LG01, and I thought it is ok to use process library because there are some example codes using that library.
– goofcode
Nov 23 '18 at 17:22
@Juraj I'm using dragino LG01, and I thought it is ok to use process library because there are some example codes using that library.
– goofcode
Nov 23 '18 at 17:22
add a comment |
1 Answer
1
active
oldest
votes
You need to use sprintf
to convert your uint8_t
data to a string:
char string_data[LENGTH]; // LENGTH = Whatever length is sufficient to hold all your data
int i=0;
int index = 0;
//NUMBER_OF_ITEMS_OF_DATA could be constant or another variable
for (i=0; i<NUMBER_OF_ITEMS_OF_DATA; i++)
{
index += sprintf(&string_data[index], "%d,", data[i]);
}
p.addParameter(string_data);
This will convert an array like {1,2,3,4,5}
into the string "1,2,3,4,5,".
You can change the "%d,"
in the sprintf
call to get another format. You may also want to remove the trailing ,
depending on your requirements.
Thank you for answering. Well, this is good enough. What i was trying to do was sending raw image data which uses a byte for a pixel. I was wondering if there is any way to send byte array itself, because it is lot easier to handle on server side and doesn't require any parsing process.
– goofcode
Nov 23 '18 at 17:28
Yeah, if you have zeros in your data you'll need to encode them somehow because HTTP is text-based and will interpret actual zero-bytes (0x00) as NULL. I'm not qualified to say what happens next, but it likely won't be what you intend.
– jfowkes
Nov 25 '18 at 22:09
Great, I decided to use hex because Arduino has String data type that gets byte and convert it to hex string. Thank you by the way.
– goofcode
Nov 26 '18 at 2:38
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53440625%2fcalling-curl-command-using-byte-buffer-in-arduino%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You need to use sprintf
to convert your uint8_t
data to a string:
char string_data[LENGTH]; // LENGTH = Whatever length is sufficient to hold all your data
int i=0;
int index = 0;
//NUMBER_OF_ITEMS_OF_DATA could be constant or another variable
for (i=0; i<NUMBER_OF_ITEMS_OF_DATA; i++)
{
index += sprintf(&string_data[index], "%d,", data[i]);
}
p.addParameter(string_data);
This will convert an array like {1,2,3,4,5}
into the string "1,2,3,4,5,".
You can change the "%d,"
in the sprintf
call to get another format. You may also want to remove the trailing ,
depending on your requirements.
Thank you for answering. Well, this is good enough. What i was trying to do was sending raw image data which uses a byte for a pixel. I was wondering if there is any way to send byte array itself, because it is lot easier to handle on server side and doesn't require any parsing process.
– goofcode
Nov 23 '18 at 17:28
Yeah, if you have zeros in your data you'll need to encode them somehow because HTTP is text-based and will interpret actual zero-bytes (0x00) as NULL. I'm not qualified to say what happens next, but it likely won't be what you intend.
– jfowkes
Nov 25 '18 at 22:09
Great, I decided to use hex because Arduino has String data type that gets byte and convert it to hex string. Thank you by the way.
– goofcode
Nov 26 '18 at 2:38
add a comment |
You need to use sprintf
to convert your uint8_t
data to a string:
char string_data[LENGTH]; // LENGTH = Whatever length is sufficient to hold all your data
int i=0;
int index = 0;
//NUMBER_OF_ITEMS_OF_DATA could be constant or another variable
for (i=0; i<NUMBER_OF_ITEMS_OF_DATA; i++)
{
index += sprintf(&string_data[index], "%d,", data[i]);
}
p.addParameter(string_data);
This will convert an array like {1,2,3,4,5}
into the string "1,2,3,4,5,".
You can change the "%d,"
in the sprintf
call to get another format. You may also want to remove the trailing ,
depending on your requirements.
Thank you for answering. Well, this is good enough. What i was trying to do was sending raw image data which uses a byte for a pixel. I was wondering if there is any way to send byte array itself, because it is lot easier to handle on server side and doesn't require any parsing process.
– goofcode
Nov 23 '18 at 17:28
Yeah, if you have zeros in your data you'll need to encode them somehow because HTTP is text-based and will interpret actual zero-bytes (0x00) as NULL. I'm not qualified to say what happens next, but it likely won't be what you intend.
– jfowkes
Nov 25 '18 at 22:09
Great, I decided to use hex because Arduino has String data type that gets byte and convert it to hex string. Thank you by the way.
– goofcode
Nov 26 '18 at 2:38
add a comment |
You need to use sprintf
to convert your uint8_t
data to a string:
char string_data[LENGTH]; // LENGTH = Whatever length is sufficient to hold all your data
int i=0;
int index = 0;
//NUMBER_OF_ITEMS_OF_DATA could be constant or another variable
for (i=0; i<NUMBER_OF_ITEMS_OF_DATA; i++)
{
index += sprintf(&string_data[index], "%d,", data[i]);
}
p.addParameter(string_data);
This will convert an array like {1,2,3,4,5}
into the string "1,2,3,4,5,".
You can change the "%d,"
in the sprintf
call to get another format. You may also want to remove the trailing ,
depending on your requirements.
You need to use sprintf
to convert your uint8_t
data to a string:
char string_data[LENGTH]; // LENGTH = Whatever length is sufficient to hold all your data
int i=0;
int index = 0;
//NUMBER_OF_ITEMS_OF_DATA could be constant or another variable
for (i=0; i<NUMBER_OF_ITEMS_OF_DATA; i++)
{
index += sprintf(&string_data[index], "%d,", data[i]);
}
p.addParameter(string_data);
This will convert an array like {1,2,3,4,5}
into the string "1,2,3,4,5,".
You can change the "%d,"
in the sprintf
call to get another format. You may also want to remove the trailing ,
depending on your requirements.
answered Nov 23 '18 at 12:04
jfowkes
754312
754312
Thank you for answering. Well, this is good enough. What i was trying to do was sending raw image data which uses a byte for a pixel. I was wondering if there is any way to send byte array itself, because it is lot easier to handle on server side and doesn't require any parsing process.
– goofcode
Nov 23 '18 at 17:28
Yeah, if you have zeros in your data you'll need to encode them somehow because HTTP is text-based and will interpret actual zero-bytes (0x00) as NULL. I'm not qualified to say what happens next, but it likely won't be what you intend.
– jfowkes
Nov 25 '18 at 22:09
Great, I decided to use hex because Arduino has String data type that gets byte and convert it to hex string. Thank you by the way.
– goofcode
Nov 26 '18 at 2:38
add a comment |
Thank you for answering. Well, this is good enough. What i was trying to do was sending raw image data which uses a byte for a pixel. I was wondering if there is any way to send byte array itself, because it is lot easier to handle on server side and doesn't require any parsing process.
– goofcode
Nov 23 '18 at 17:28
Yeah, if you have zeros in your data you'll need to encode them somehow because HTTP is text-based and will interpret actual zero-bytes (0x00) as NULL. I'm not qualified to say what happens next, but it likely won't be what you intend.
– jfowkes
Nov 25 '18 at 22:09
Great, I decided to use hex because Arduino has String data type that gets byte and convert it to hex string. Thank you by the way.
– goofcode
Nov 26 '18 at 2:38
Thank you for answering. Well, this is good enough. What i was trying to do was sending raw image data which uses a byte for a pixel. I was wondering if there is any way to send byte array itself, because it is lot easier to handle on server side and doesn't require any parsing process.
– goofcode
Nov 23 '18 at 17:28
Thank you for answering. Well, this is good enough. What i was trying to do was sending raw image data which uses a byte for a pixel. I was wondering if there is any way to send byte array itself, because it is lot easier to handle on server side and doesn't require any parsing process.
– goofcode
Nov 23 '18 at 17:28
Yeah, if you have zeros in your data you'll need to encode them somehow because HTTP is text-based and will interpret actual zero-bytes (0x00) as NULL. I'm not qualified to say what happens next, but it likely won't be what you intend.
– jfowkes
Nov 25 '18 at 22:09
Yeah, if you have zeros in your data you'll need to encode them somehow because HTTP is text-based and will interpret actual zero-bytes (0x00) as NULL. I'm not qualified to say what happens next, but it likely won't be what you intend.
– jfowkes
Nov 25 '18 at 22:09
Great, I decided to use hex because Arduino has String data type that gets byte and convert it to hex string. Thank you by the way.
– goofcode
Nov 26 '18 at 2:38
Great, I decided to use hex because Arduino has String data type that gets byte and convert it to hex string. Thank you by the way.
– goofcode
Nov 26 '18 at 2:38
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53440625%2fcalling-curl-command-using-byte-buffer-in-arduino%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
do you have a Yun board? this is not the way to do network communication in Atmega of Arduino Yun. use the Bridge library.
– Juraj
Nov 23 '18 at 9:01
You can improve your question by specifying the format of the string you need. Should the numbers be separated by spaces, commas, tabs, or something else?
– jfowkes
Nov 23 '18 at 12:08
@Juraj I'm using dragino LG01, and I thought it is ok to use process library because there are some example codes using that library.
– goofcode
Nov 23 '18 at 17:22