Data retrieval - getting HPE_INVALID_CONSTANT

Hello Support,

New IoTaWatt owner here, and first time poster…

It looks like I’m having some trouble retrieving data from the unit, if I use a http request from node red, rather than a browser (eg. safari works)

when I use this request for example:
http://192.168.1.96/query?select=[time.local.iso,Input_0.volts]&begin=d-1d&end=d&group=auto&format=csv&header=yes

In the browser correctly returns a CSV version of the data.

However, if I copy-paste that exact command into a node-red http request node, I get the HPE_INVALID_CONSTANT error reported as per this screen shot, which then says that ‘HTTP /’ was expected. any hints as to what I may be doing wrong?

Not a node-red user, but from what you posted, the error detail appears to be from the payload node that has received the 150 byte payload listed. That is not an error that would come from IoTaWatt. It looks like something that node-red is telling you about the HTTP request.

So I think you need to back-up to the http request node and get some details about the HPE_INVALID_CONSTANT. Can you show the node settings and any diagnostic information that it associates with the http request node?

Yes, this is the node settings for the http request:

I’ve also searched around, and maybe to do with http versions v0.9 vs v1.0, and that apparently node.js (which node red is based on), doesn’t support v0.9 or earlier… what version info / header info does iotaawatt return? (this is a theory I got from here: https://stackoverflow.com/questions/34769824/what-does-this-error-mean-hpe-invalid-constant)

IoTaWatt uses HTTP 1.1 which supports chunked response. Chunked response is used when you don’t know at the outset how much data will be transferred (which we don’t). So IoTaWatt sends “chunks” with a length header. That should be supported in Node Red. Do you have the latest version installed?

EDIT: Also, does Node Red have any further information for the HPE-INVALID-CONSTANT message being reported in the HTTP request node?

I was running node-red 1.2.3 and now updated to 1.2.5, still the same unfortunately.

I will try and dig out any other error info reported by the node, but at the surface, it appears that the parsing of the response failed in node red… let me see if I can find something additional on there…

The way I read it, the http request node does the request and then passes the response string to the msg.payload node. So what happens when something goes wrong with the http request? I’m thinking it passes an error string to the next node, and that’s what we see in:
image
IoTaWatt has no error message that anything remotely like that. So my take is tat there is something about the URL that the http request node doesn’t like.

This is half-baked research, but a quick look at some forum posts suggests that node-red parses the query (part after the ?) of the URL. The IoTaWatt query is a litlle complicated and I wouldn’t be surprised that node-red would have trouble with it.

So looking at this


It appears you can pass the URL as a quoted string using a “function node”. That might eliminate parsing the query, and thus the error. I’m not sure how all this goes together, but it seems clear to me that node-red is trying to parse the URL and having difficulty, so an alternate means of specifying the URL that bypasses the query substitutions might be the fix.

Like I said, I know very little about node-red, but that’s the path I would explore.

You might try asking on the node red forum. Looks like a lively bunch.

1 Like

Ok will do - looks more like a node red issue, since, after doing the above, as well as even simplifying the query even further to just the “HTTP://iotawatt.local/query?show=series” query, still fails with the same error. Thanks for the guidance so far - I will ask over at node-red (same username there :slight_smile: )

Also, in terms of the link you pointed me to, unfortunately that is no longer possible due to deprecation in the underlying node software…

Just for grins, try “http://IoTaWatt.local/status?inputs=yes”. That response will not be chunked.

Okay, that’s different :smiley: appears to output the following…but “now what?” :laughing:

Hmmmm… What’s different about that transaction is that the response is not chunked. I’m wondering if node-red supports chunked response and if there’s a different approach to using it.

But before I take that leap, I need to see this with my own eyes.

So can you show the screenshot of the http request node and the response as above so I can verify there is nothing else different?

Yes of course - here it is overeasy, thanks for persisting!

As best I can tell, the only functional difference between these two requests is that the status request is not chunked. So it looks like that’s the root of the problem.

Have you tried specifying a json response, which is what it is?

I don’t see the Payload option in screenshots on their tutorials. What are the other options there?

I did try JSON response [edit] and it too resulted in the same error as the utf8 string. I also tried empty [] brackets (which yielded an error about an array). I tried many other items too such as no parameters at all, escaping or double-quoting ampersands too.

Specifically for the combo you’ve asked for, here’s the options. Do I need to use digest authentication by any chance?

Also, the green ones are just ‘debug’ nodes, and can be named anything (as seen here :slight_smile: ) But there is an option for a J: expression in terms of its output - see here:

the ‘http request’ node is actually the request and parsing the response., before passing the response in the msg.payload to the next in line, which in this case, is a debug node.

If you have a password set in your IoTaWatt you would need to authenticate. Rather than try to use Digest Authentication (which woul dbethe correct choice), I’d try to get it working with no authentication first by removing the password (set it to blank in the IoTaWatt).

ok done set to blank (but it didn’t change anything to do with the error - i.e. I still have the error)

TBH I had not explored the Node-Red capabilities before, but it looks as if it could easily satisfy the MQTT output needs that folks have been asking for. So I’m running this issue to ground.

I’m pretty sure it’s about the chunked response, so I have joined your thread on the Node-Red forum to follow up with a few apparent regulars who appear to have looked at this issue back in March. I think they got it wrong, but maybe between us this can be resolved.

2 Likes

Yes! it sure would, and even more too! Glad to be helping, troubleshooting, and making IoTaWatt a little better along the way, thanks for assisting :slight_smile:

Have got this working


and with a select query using the [ brackets] works fine

This will go into a new release within a few weeks along with a couple of other maintenance items.

2 Likes