That’s my experience as well. I have 2 of the Eagle’s and they appear to be happier pushing data. Polling is a little problematic with them. If you are going to poll, you have to be ready for timeouts and other error conditions. I found them to be far more reliable when they push data. No errors, no issues.
Thank you for this - I’d been battling with a Python->MQTT solution (which was working until I updated mosquitto), and then last night I tried setting this up and within a matter of minutes had it working better and more smoothly than either the binding or the Python version ever did. Set it up as a LaunchAgent this morning.
I seem to have a new problem with what had been a very robust solution for a long time - possibly since updating to openHAB 5.0.0.M1? For some reason, post2put.js no longer seems happy to talk to my openHAB installation… which is weird, because if I send the same request using curl it seems to work. Here’s the error output from post2put being run at the command line:
PUT Instantaneous Demand: 0.774
{ Error: Parse Error
at TLSSocket.socketOnData (_http_client.js:440:20)
at emitOne (events.js:116:13)
at TLSSocket.emit (events.js:211:7)
at addChunk (_stream_readable.js:263:12)
at readableAddChunk (_stream_readable.js:250:11)
at TLSSocket.Readable.push (_stream_readable.js:208:10)
at TLSWrap.onread (net.js:597:20) bytesParsed: 0, code: 'HPE_INVALID_CONSTANT' }
But if I send the same data with a curl, it works fine:
curl -k -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "0.774" "https://192.168.11.5:8443/rest/items/elecDemand/state"
Any ideas why post2put would be failing now?
I haven’t tried this with 5.0M1 yet. Google search says this:
The HPE_INVALID_CONSTANT error in Node.js typically arises when the HTTP parser encounters an issue interpreting the response from a server. This often indicates that the response is malformed or doesn’t conform to expected HTTP standards.
You could add some console.log statements for debugging and see if that gives any additional info.
By the way, if I were to start over on this, I think I would look at the webhook binding as then there is no need for the external script. I haven’t done that yet, but it seems like a good solution. However, node.js should work, there’s probably a simple problem.
Thanks for the reply - still no idea why node.js’s https wasn’t working, but I’ve rewritten it to send the request to openHAB using curl (since that worked fine from the command line), and that seems to have done the job nicely. Here’s the code chunk I inserted, with everything else that post2put did with https commented out.
const curlStart = 'curl -k -s -S -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "';
const curlEnd = '" "https://192.168.11.5:8443/rest/items/elecDemand/state"';
var curlString;
// this one handles the Eagle 200 packets
app.post('/eagle200', (req, res) => {
if (req.body.body[0].dataType == 'InstantaneousDemand') {
if (parseInt(req.body.body[0].timestamp) > (LastInstantaneousDemandTimestamp + InstaneousDemandTimeLimit)) {
LastInstantaneousDemandTimestamp = parseInt(req.body.body[0].timestamp);
console.log('PUT Instantaneous Demand: ' + req.body.body[0].data.demand);
// for some reason sending it using node.js https was not working... but curl works!
curlString = curlStart;
curlString += req.body.body[0].data.demand.toString();
curlString += curlEnd;
exec(curlString, (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
return;
}
if (stderr) {
console.log(`stderr: ${stderr}`);
return;
}
});
}
}
Thanks for the workaround.
I’m curious if you tried using node.js to put to the http (not https) port? Possibly there is an issue using https now?