Getting Error: "Parse Error: Expected HTTP" - "HPE_INVALID_CONSTANT"

Hi,

I have a ethernet webrelay (WebRelay | Ethernet Relay | Remote Relay Control) that opens my front door.
To open the door I simply have to open a browser and type in:
http://192.168.10.224:10359/state.xml?relayState=2&pulseTime=5
After filling-in the credentials the door opens.

I try to do the same from node-red.
I have 4 nodes:

  • 1 injector
  • 1 change node
  • 1 http request node
  • 1 HA node to check the status of my door.

Here is the code:

[{"id":"994311c7.7445d8","type":"inject","z":"2e0bd4f.934d72c","name":"Unlock door","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":"1","topic":"","payload":"","payloadType":"date","x":210,"y":240,"wires":[["49d1e033.fff5f8"]]},{"id":"430d6a4c.b6affc","type":"http request","z":"2e0bd4f.934d72c","name":"Query","method":"GET","ret":"txt","paytoqs":"body","url":"","tls":"","persist":false,"proxy":"","authType":"","x":730,"y":240,"wires":[["702c1d7b.69dbd4"]]},{"id":"49d1e033.fff5f8","type":"change","z":"2e0bd4f.934d72c","name":"Prep login","rules":[{"t":"set","p":"headers.content-type","pt":"msg","to":"text/html; charset=UTF-8","tot":"str"},{"t":"set","p":"queryDate","pt":"msg","to":"$now()","tot":"jsonata"},{"t":"set","p":"headers.authorization","pt":"msg","to":"Basic ThisIsMyBase64String","tot":"str"},{"t":"set","p":"url","pt":"msg","to":"http://192.168.10.224:10359/state.xml?relayState=2&pulseTime=5","tot":"str"},{"t":"set","p":"headers.content-length","pt":"msg","to":"3495","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":490,"y":240,"wires":[["430d6a4c.b6affc"]]},{"id":"702c1d7b.69dbd4","type":"api-current-state","z":"2e0bd4f.934d72c","name":"Door Open?","server":"52cfa5eb.37210c","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"binary_sensor.alarm_contact_entree","state_type":"str","state_location":"doorOpen","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":950,"y":220,"wires":[[],[]]},{"id":"52cfa5eb.37210c","type":"server","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

As such, the flow opens the door but I get an error and the flow stops just after the http request.

I tried unsuccessfully all sort of combinations in order to remove this error message.

Now I am stuck and would appreciate some help.

Thanks.

Sined

Hello Sined,

Welcome to the forum! Can you please specify the error message you are receiving?

Cheers
Ranki

Hi Ranki,

Thank you for this rapid reaction.
Here is the error message:

{
   "_msgid":"29ee57ca.d347c8",
   "payload":"Error: Parse Error: Expected HTTP/ : http://192.168.10.224:10359/state.xml?relayState=2&pulseTime=5",
   "topic":"",
   "headers":{
      "content-type":"text/html; charset=UTF-8",
      "authorization":"Basic MyBase64",
      "content-length":"3495"
   },
   "queryDate":"2021-05-18T16:17:32.176Z",
   "url":"http://192.168.10.224:10359/state.xml?relayState=2&pulseTime=5",
   "statusCode":"HPE_INVALID_CONSTANT"
}

Cheers.

Sined

Hi Signed,

Which node is generating the error message?

Cheers
Ranki

The HTTP Request node

This is the change node that prepares the values for the HTTP Request Node

This is the HTTP Request node

Have you tried entering the credentials on the http request node settings?

If that doesn't work then maybe providing the credentials in the URL will work e.g. http://user: password@192.168.10.224:10359/state.xml?relayState=2&pulseTime=5

You do not need to send payload as request body, try just ignoring the payload.

Hi Steve,

Thank you for your reply. Yes I already tried that. No success.

Sined

Hi E1cid,

Thank for proposing but as explained I tried almost all the combinations.

Thanks for proposing.

Sined

Hello @NoeudRouge,

sorry, I was not at the computer anymore yesterday ... do you need all the parameters for the header etc, which you are preparing in the «prep login»-node?

Can you maybe try this one (you have to enter your credentials in the http-node and add your last node again to it; or check first the debug output):

[
    {
        "id": "994311c7.7445d8",
        "type": "inject",
        "z": "b4fa726a.49a62",
        "name": "Unlock door",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": "1",
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 630,
        "y": 780,
        "wires": [
            [
                "430d6a4c.b6affc"
            ]
        ]
    },
    {
        "id": "430d6a4c.b6affc",
        "type": "http request",
        "z": "b4fa726a.49a62",
        "name": "Query",
        "method": "GET",
        "ret": "txt",
        "paytoqs": "ignore",
        "url": "http://192.168.10.224:10359/state.xml?relayState=2&pulseTime=5",
        "tls": "",
        "persist": false,
        "proxy": "",
        "authType": "basic",
        "x": 790,
        "y": 780,
        "wires": [
            [
                "d7105393.07ac7"
            ]
        ]
    },
    {
        "id": "d7105393.07ac7",
        "type": "debug",
        "z": "b4fa726a.49a62",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 930,
        "y": 780,
        "wires": []
    }
]

Cheers
Ranki

I assume when you tried the built in authentication and the URL style authentication you removed the authorization header from the change node?

Hi Steve,

Yes I removed it.

Sined

Hello,

I tried your proposal. Door still opens but get the error message:

image

image

Thanks again for your support.

Sined

If you search the forum and internet for the HPE error you will see it usually means there is something wrong with the response from the server (in your case this relay)

What do you see if you curl the URL?

Also, have you looked to see if this relay has an updated firmware or if it has a forum, raise an issue?

Lastly, does this relay have any other protocols that http API?

Try to „play“ with the return setting; so change it from UTF-8 to the other options …

Cheers
Ranki

… and this would be really interesting. Do you know how to use curl?

Dear,
Thank you for your combine effort.
I tried with curl. The door still opens and get back the following error:

curl: (1) Received HTTP/0.9 when not allowed

Apparently, and I don't know if this normal, the job is sent back in the shell and the only way to recover a prompt is by doing a CTRL+C which kills the job.

Sined

Hi,

I ran the same command with --verbose option and here is the output:

*   Trying 192.168.10.224:10359...
* Connected to 192.168.10.224 (192.168.10.224) port 10359 (#0)
* Server auth using Basic with user 'admin'
> GET /state.xml?relayState=2 HTTP/1.1
> Host: 192.168.10.224:10359
> Authorization: Basic Base64Username:Password
> User-Agent: curl/7.74.0
> Accept: */*
>
* Received HTTP/0.9 when not allowed

* Closing connection 0
curl: (1) Received HTTP/0.9 when not allowed

Hi,

Me again. I investigated the HTTP/0.9 protocol and apparently it could be the problem.
By reading the following article, it appears that:

Blockquote

HTTP/0.9 — The One-line Protocol

  • Initial version of HTTP — a simple client-server, request-response, telenet-friendly protocol
  • Request nature: single-line (method + path for requested document)
  • Methods supported: GET only
  • Response type: hypertext only
  • Connection nature: terminated immediately after the response
  • No HTTP headers (cannot transfer other content type files), No status/error codes, No URLs, No versioning
$> telnet ashenlive.com 80(Connection 1 Establishment - TCP Three-Way Handshake)
Connected to xxx.xxx.xxx.xxx(Request)
GET /my-page.html(Response in hypertext)
<HTML>
A very simple HTML page
</HTML>(Connection 1 Closed - TCP Teardown)

Popular web servers (Apache, Nginx) still supports HTTP/0/9. Try opening up a Telnet session and accessing google.com

Maybe the server behind the relay is configured with this protocol and maybe do I need to specify it in the "HTTP Request" node.

Sined

did you explore other options?

If all else fails, you could do this using the TCP nodes.

adapt this solution from Nick to do it raw.