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?
You need to use
sprintf
to convert youruint8_t
data to a string: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 thesprintf
call to get another format. You may also want to remove the trailing,
depending on your requirements.