Problem with libcurl on Raspberry Pi


#1

Hello,
I want to upload my S0-pulse data to Pvoutput.org.
It works with a testscript in a shell-file, using “curl” from the command line.
But the goal is to put it in a c-program linked with libcurl.
In this case, with the same kind of request, a get as reply:
“Unauthorized 401: Invalid System ID”
The working shell command:
curl -d “d=20180130” -d “t=10:15” -d “v1=1000” -d “v2=150” -H “X-Pvoutput-Apikey:MyApi” -H “X-Pvoutput-SystemId:MyId” https://pvoutput.org/service/r2/addstatus.jsp

The c-program posts this string:
static const char *postthis = “-d “d=20180130” -d “t=10:05” -d “v1=1000” -d “v2=150” -H “X-Pvoutput-Apikey:MyApi” -H “X-Pvoutput-SystemId:MyId””;

A printf of this string gives:
-d “d=20180130” -d “t=10:05” -d “v1=1000” -d “v2=150” -H “X-Pvoutput-Apikey:MyApi” -H “X-Pvoutput-SystemId:MyApi”

(I deleted the Id’s in this forumpost)
libcurl returns with success. But the message from Pvoutput.org is not good.
“Unauthorized 401: Invalid System ID”

What can be wrong ?


#2

The system id is a number i.e. 56582

See https://pvoutput.org/help.html#api-getting-started


#3

You could use webhooks instead of curl.
In fact you could construct the urls for testing in Notepad or something like this:
Method: GET
Headers:

{
"X-Pvoutput-Apikey": "myKey",
"X-Pvoutput-SystemId": "01010"
}

Query Parameters: (the 4 required are here)

{
"d": "{{Date}}",
"t": "{{Time}}",
"v2": "{{Watts}}",
"v1": "{{WattHrs}}"
}

After some debugging on Requestb.in it was determined that this should work and it did.
The GET request is then formed like this:

https://someurl.jsp?d={{Date}}&t={{Time}}&v2={{Watts}}&v1={{WattHrs}}&key=lsfdskfldjfie&sid=00100

Note that you can send SID and KEY not as headers but included in the parameters of a get request like in the string above. You can paste it into a browser to see what happens.


#4

I got it working. The syntax and argument passing is different in libcurl.
I studied the liburl tutorial.
This works:
static const char *postthis = “d=20180206&t=10:05&v1=1000&v2=150”;
struct curl_slist *headers=NULL;
headers = curl_slist_append(headers, “X-Pvoutput-Apikey:MyApi”);
headers = curl_slist_append(headers, “X-Pvoutput-SystemId:MyId”);