I'm trying to update my emoncms inputs from a C program using libcurl. I was just wondering if there was a way to get the post.json to accept POST requests instead of GET requests. I wanted to avoid the problem of having to encode the JSON data before a GET request when using CURL.
I've already done the hardware interfacing stuff in C. So, I want to do the curl part in C as well, because to do it in php would mean to pass the input from the C code via pipes or something. I wasn't able to find a simple equivalent to json_encode/decode() in C.
POST JSON bulk data to input using CURL and C
Submitted by zaxter on Sun, 13/04/2014 - 10:25I'm trying to update my emoncms inputs from a C program using libcurl. I was just wondering if there was a way to get the post.json to accept POST requests instead of GET requests. I wanted to avoid the problem of having to encode the JSON data before a GET request when using CURL.
I've already done the hardware interfacing stuff in C. So, I want to do the curl part in C as well, because to do it in php would mean to pass the input from the C code via pipes or something. I wasn't able to find a simple equivalent to json_encode/decode() in C.
This is what i'm trying to acheive:
http://192.168.7.2/emoncms/input/bulk.json?data=[[0,16,107,1557,110,1445]]
And this is my C code:
int main(void)
{
CURL *easyhandle;
curl_global_init(CURL_GLOBAL_ALL);
easyhandle = curl_easy_init();
if(easyhandle) {
char *data="data=[[0,16,107,1557,110,1445]]";
curl_easy_setopt(easyhandle, CURLOPT_POSTFIELDS, data);
curl_easy_setopt(easyhandle, CURLOPT_URL, "http://192.168.7.2/emoncms/input/bulk.json");
curl_easy_perform(easyhandle);
curl_easy_cleanup (easyhandle);
}
curl_global_cleanup();
return 0;
}
Is there a simple way to implement this? I'm quite a novice to php. Please help.
Also wanted to know if the present emoncms code for bulk data handles POST requests as well.
A basic working C example would be highly appreciated.
Thanks again!