Supereg / homebridge-http-switch

Powerful http switch for Homebridge: https://github.com/homebridge/homebridge
ISC License
219 stars 36 forks source link

Log error/error on Home tile #40

Closed markob100 closed 4 years ago

markob100 commented 4 years ago

This is a really useful module!

I'm having a couple of minor errors.

1/ A stateless switch rebooting 3 Raspberry Pis, each running lighttpd and PHP 7.3-FPM. This seems to work but generates the following error:

[2019-11-12 10:12:44] [Reboot Blinds] setStatus() doing http request...
[2019-11-12 10:12:50] [Reboot Blinds] 2 requests successfully set switch to ON; 1 encountered and error:
[2019-11-12 10:12:50] [Reboot Blinds] [ { index: 0,
    error: { Error: socket hang up
    at createHangUpError (_http_client.js:331:15)
    at Socket.socketOnEnd (_http_client.js:423:23)
    at emitNone (events.js:111:20)
    at Socket.emit (events.js:208:7)
    at endReadableNT (_stream_readable.js:1056:12)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9) code: 'ECONNRESET' } } ]

Here is the relevant config excerpt:

{
"accessory": "HTTP-SWITCH",
"name": "Reboot Blinds",
"switchType": "stateless",
"timeout": 20000,
"multipleUrlExecutionStrategy": "series",
"onUrl":
[
"http://[internal IP]/reboot.php",
"delay(1000)",
"http://[internal IP]/reboot.php",
"delay(1000)",
"http://[internal IP]/reboot.php"
]
}

It also leaves an exclamation mark on the Home tile.

Using UrlObjects and/or specifying httpmethod doesn't seem to make a difference. I have a more complex switch in which I've set those options and I get the same error.

2/ A stateless switch pinging 8 URLs in order. This is to issue an http command stopping 8 blinds moving. The blind controls are not particularly reliable. Although the switch works well sometimes the response from the server is a 500 error with a webpage which contains 'Error - cannot read property'. (This can be seen in the 'value' line below.) This doesn't actually mean it hasn't worked, usually.

Here is the log extract:

[2019-11-12 10:20:33] [Stop Blinds] 4 requests successfully set switch to ON; 4 encountered and error:
[2019-11-12 10:20:34] [Stop Blinds] [ { index: 2,
    error: Error: HTTP request returned with error code 500
    at results.forEach (/usr/local/lib/node_modules/homebridge-http-switch/index.js:448:32)
    at Array.forEach (<anonymous>)
    at http.multipleHttpRequests.results (/usr/local/lib/node_modules/homebridge-http-switch/index.js:438:21)
    at multipleUrlExecutionStrategy (/usr/local/lib/node_modules/homebridge-http-switch/node_modules/homebridge-http-base/http.js:143:13)
    at err (/usr/local/lib/node_modules/homebridge-http-switch/node_modules/async/dist/async.js:2959:19)
    at wrapper (/usr/local/lib/node_modules/homebridge-http-switch/node_modules/async/dist/async.js:272:20)
    at replenish (/usr/local/lib/node_modules/homebridge-http-switch/node_modules/async/dist/async.js:439:29)
    at iterateeCallback (/usr/local/lib/node_modules/homebridge-http-switch/node_modules/async/dist/async.js:428:21)
    at /usr/local/lib/node_modules/homebridge-http-switch/node_modules/async/dist/async.js:325:20
    at result (/usr/local/lib/node_modules/homebridge-http-switch/node_modules/async/dist/async.js:2957:17),
    value: '<!DOCTYPE html>\n<html lang="en">\n<head>\n<meta charset="utf-8">\n<title>Error</title>\n</head>\n<body>\n<pre>TypeError: Cannot read property &#39;00001530b87f490c92cb11ba5ea5167c&#39; of undefined<br> &nbsp; &nbsp;at Gatt.write (/usr/local/lib/node_modules/soma-ctrl/node_modules/noble/lib/hci-socket/gatt.js:526:58)<br> &nbsp; &nbsp;at NobleBindings.write (/usr/local/lib/node_modules/soma-ctrl/node_modules/noble/lib/hci-socket/bindings.js:364:10)<br> &nbsp; &nbsp;at Noble.write (/usr/local/lib/node_modules/soma-ctrl/node_modules/noble/lib/noble.js:325:19)<br> &nbsp; &nbsp;at Characteristic.write (/usr/local/lib/node_modules/soma-ctrl/node_modules/noble/lib/characteristic.js:74:15)<br> &nbsp; &nbsp;at SomaShade.stop (/usr/local/lib/node_modules/soma-ctrl/src/SomaShade.js:104:34)<br> &nbsp; &nbsp;at express.post (/usr/local/lib/node_modules/soma-ctrl/src/WebConnector.js:56:20)<br> &nbsp; &nbsp;at Layer.handle [as handle_request] (/usr/local/lib/node_modules/soma-ctrl/node_modules/express/lib/router/layer.js:95:5)<br> &nbsp; &nbsp;at next (/usr/local/lib/node_modules/soma-ctrl/node_modules/express/lib/router/route.js:137:13)<br> &nbsp; &nbsp;at Route.dispatch (/usr/local/lib/node_modules/soma-ctrl/node_modules/express/lib/router/route.js:112:3)<br> &nbsp; &nbsp;at Layer.handle [as handle_request] (/usr/local/lib/node_modules/soma-ctrl/node_modules/express/lib/router/layer.js:95:5)</pre>\n</body>\n</html>\n' },

I am wondering if there is a way to suppress/remap the response returned by the server above so that http-switch will accept it as success so the Home tile won't show an exclamation mark. Which I realise is appropriate behaviour for a 500 error, but since it ACTUALLY works in my case, I want it to show in the UI as successful.

Thanks Mark

Supereg commented 4 years ago

1) The problem here is the fact that you shutdown your raspberry while the http request is still in progress. This results in the plugin being unable to get the http response and not knowing what to do, which results in displaying an error.

2) I'm not quite sure what your problem is here? You have an API endpoint which returns an 500 - internal server error but somehow executes the action nonetheless? Im unsure if I should add an option to suppress http error codes. 500 should be used in cases for severe errors only. The appropriate way to fix this would be to fix that on your API end since there is something severely failing (though the action is executed, which is weird).

Supereg commented 4 years ago

Feel free to reopen the issue if you have any further question or rather want to answer my followup questions.