Data from IoTaWatt - getting HPE_INVALID_CONSTANT error

I've recently got an IoTaWatt and have set up initially and can access it correctly (outside of Node Red)

When I try to retrieve data from the 'query' structure defined by IoTaWatt, I get HPE_INVALID_CONSTANT errors, regardless of the modifications I've tried so far. Some of that history is over in IoTaWatt forums here https://community.iotawatt.com/t/data-retrieval-getting-hpe-invalid-constant/2415

Based on those troubleshooting steps, was nudged here. Has anyone else had this problem with calling the IoTaWatt query interface using http request node?

Does it / should it work?

(for those without IoTaWatt / some docs background here: https://docs.iotawatt.com/en/master/query.html#query-show)

Can you try going to that URL manually with curl. Eg curl -i http... With the -i to print the header of the response and show us what that contains please.

Yes, here it is from the pi on which node red is running on (latest raspberry os on rpi2b, as of last week). What is interesting is that both the rpi, and my Mac, both imply a problem with the same part of the http: request:

On the Pi:

On the Mac:

As the error says, that is not a valid url. I think you need to escape the square brackets, assuming they are really supposed to be there.

yes I think you need to use %5B for [ and %5D for ] when using the command line

hmmm, that didn't seem to make a difference on the Mac (using bash)...(same error)

Can you show us the error now ?
Also please try just curl -v http....

dceejay, this is with the -v option on Mac:

ok - get a query yo know works and paste it into your browser - if that then works copy the address from the browser address bar and do curl -v {pasted url from browser}
(Note not what you type into the browser - -often the browser will re-encode it and add the %5B etc etc - so what it ends up being)

I'm the person who maintains the API that is in question. I've been trying to figure this out and have discovered that this is actually a continuation of this:

That thread starts out looking like something else, but morphs into the real issue. I think the analysis and resolution is flawed, but have the nagging feeling I'm missing something obvious.

Just want to bring in @unixneo, @knolleary, and a couple of others but I hit the new user limit (at Andrei, at Waynedejager if they are still interested.

This thread on the IoTaWatt forum shows how (at)samos has tried using some other APIs on IoTaWatt and they worked fine. He also used a much simpler (no non-URL characters) query API and it failed. The only perceived difference is that the failing requests elicit CHUNKED) responses.

To sum up the previous thread from March on this forum, the Chunk headers and delimiter were interpreted as a malformed response. A "solution" was proposed that essentially used a php script to remove a chunked header and trailer and send the response as if it wasn't chunked. That seemed to work on the 086x length response in question, but the query API can and does regularly send up to 100Kb and is capable of sending megabytes. When it starts, the ultimate length is unknown and so the HTTP/1.1 chunked encoding (sorry, at my newbie link limit so google chunked transfer encoding wiki)

What I can't understand is why node red doesn't seem to recognize chunked responses, and seems to have no hits when I google it. It's been around quite awhile.

I have recreated the node-red issue reported here and tested these various URLs myself. I've changed the chunked response in several ways with no luck. In all cases the responses still work with browsers and the HTTPrequest in various javascript apps.

What I'd like to find out is if there is support for chunked that I'm just missing. It looks as if I could drop down to the tcp in/out level and decode and aggregate the chunks into a string, but that seems foolish when it's such a ubiquitous function.

1 Like

@overeasy and @knolleary, please see here where a 'very' simple get request response is successfully returned by the IoTaWatt using the http request node, and its node config. does this help?

this is what results from one type of query pasted into

Safari/big Sur and after the result is returned:
http://192.168.1.96/query?select=[time.local.iso,Input_0.volts]&begin=d-1d&end=d&group=auto&format=csv&header=yes

only the [ and ] were changed to %5B and %5D after being pasted as [ and ]

On Mozilla Firefox / Big Sur, the same address is left unchanged with the square brackets (whilst also correctly returning the csv requested within Firefox)
http://192.168.1.96/query?select=[time.local.iso,Input_0.volts]&begin=d-1d&end=d&group=auto&format=csv&header=yes

Chromium on the RPi does exactly the same as FireFox on the Mac (does not re-write the address, and keeps them as [ and ], and correctly returns the csv from the IoTaWatt too

Something odd going on then.. if I go to https://www.bbc.co.uk/news/
using one of our http-request nodes I get a complete page back no problem.
If I do curl -I https://www.bbc.co.uk/news/ I can see the headers are set to chunked.
And that not Content-Length is specified
So the node can handle chunks just fine... that is why I am trying to get you to see the headers returned from that server and in particular both the Transfer-Encoding and the Content-Length (which should not be set if transfer-encoding is set to chunked)

image

Hello @dceejay,

Here are the response headers using a browser to access:

image

Yes - I also tried getting the IoTaWatt's built in homepage, via a simple http request node and got back the whole page too:

So no content length... good... so ok - admit I'm confused.

Though it does say connection close - which seems odd when you would be expecting another chunk.

PS try the full query again with curl -ig http://.... thanks

I just tried adding keep-alive. That didn't help. But I have tried something else and have got it to work.

The older post from March had a clue with the curl response that said there was

This is a problem with newer ESP8266WebServer's chunking interacting with IoTaWatt's older implementation. Never bothered browsers but I'll get it fixed in a day or so. After reading through the various releases of ESP8266WebServer, it looks like they have changed it yet again but that version is not yet published to PlatformIO, so I will need to understand the implications of that.

Thanks for your efforts. I'll post back when I have resolved on my end.

It's been interesting to explore Node-Red and I think you'll be seeing more of me in the future. Nice project.

1 Like

Thanks for helping out. Much appreciated. See you again.

1 Like

Problem was in IoTaWatt chunking. Fixed and will be released in a few weeks.

2 Likes

Brilliant! And im happy to beta test :slight_smile: :grin: