Post Temperature to API via NodeRed Node Error?


#1

Today I have a nodered server which collects weather data (via SDR 433mhz) from my home sensors and I’m attempting to create a POST message via an HTTP REQUEST node to the PVOutput.org API containing my current temp value in degrees C every five minutes. I’m a donor to the site, and can copy and paste the POST string from NoedRed via a browser and I get the “OK Value Added” massage and I can see data in my live stream.

If I take the same exact output generated in NodeRed (SSL and I have certs working), I get an error “401: Incorrect Station ID”. If I look at the debug info, I can see the correct URL a ? and the message appears below the ? which I assumed was just because of scrolling. I have copied and pasted this to Word, Text Wrangler and other text editors to see if there are any special characters, etc., but I see nothing.

From the copy and paste (removing SID and APIKEY) you can see the end of the URL with the ? and then there is something like a return being sent. If I just send the first part of the URL query up to the ?, I get the same error in my browser. I know I’m missing something in the construction here. Any thoughts or pointers?

A piece of my flow below contain the message function to build the HTTP context and also convert my F to C temp.

The below shot shows the message body after the temp conversion and setting the context details.

POST MESSGE:
My post looks like this: “https://pvoutput.org/service/r2/addstatus.jsp?sid=SIDHERE&key=APIKEYHERE&d={{{payload.date}}}&t={{{payload.time}}}&v5={{{payload.temperature_F}}}”

Responder URL back from API (key removed):
https://pvoutput.org/service/r2/addstatus.jsp?sid=64031&key=***&d=20190109&t=15:27:15&v5=4.9

Response:
Status Code: “401”
Payload: “Unauthorized 401: Invalid System ID”


#2

Just a guess here, but a couple of things I’ve noticed is that addstatus requires at least one of v1, v2, v3 or v4. Your only sending v5. Also, the format of the time parameter is hh:mm, you’ve passed hh:mm:ss. The 401 error doesn’t appear to match these issues but who knows.


#3

Thanks for the pointers bd thoughts

I have used both time formats in a browser and both seem to work with the API, I could modify it to the HH:MM, but I get the same error from the API response. I also am a donner system which the API claims does not require that I upload the other feed items along with the temp. Today I have the energy data coming from my IoTaWatt device.

What is interesting is that to get a few of the screen shots for the post, it appears that the temp was being sent even with the 401 error response. That was a surprise. I will continue to play, and thanks again for the thoughts.


#4

I had forgot that Donators could send temperature only. Everything else in the responder URL looks right. Maybe BB will have an idea when he check here.


#5

Thanks again for the thoughts as it often is something simple I have overlooked and the community is a great way to find a solution. I will play with the time feed and try again, but as you said, it is an odd message if that is the underlying problem.


#6

Check your API key for errors


#7

Confirmed API key is correct and if I post the same data in a browser, all is good. It seems to be something around the construction of the post that I’m missing. Thanks for the input.


#8

Change the HTTP request to use GET instead of POST.

When using POST the HTTP headers X-Pvoutput-Apikey and X-Pvoutput-SystemId are expected.

When using GET the URL parameters sid and key are used.

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

Entering a URL into the browser uses GET so will always work with sid and key in the URL.


#9

Thanks I’ll try the “GET” option instead of “POST”. I assume GET will be HTTP and not SSL? Also, if I can populate the HTTP headers with the necessary data fields, would that be the preferred option?


#10

I changed to a “GET” as you recommended and we are good to go! Thank you!


#11

Doh!! - I should have thought of that. I use HTTP Headers in my own applications as well rather than the sid and key parameters.