Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON Parsing error causes homebridge to restart #18

Open
irdeto-hackwestern opened this issue Mar 22, 2020 · 1 comment
Open

JSON Parsing error causes homebridge to restart #18

irdeto-hackwestern opened this issue Mar 22, 2020 · 1 comment

Comments

@irdeto-hackwestern
Copy link

I am getting the following error:

SyntaxError: Unexpected token N in JSON at position 0
at JSON.parse ()
at Request._callback (/homebridge/node_modules/homebridge-sonoff-tasmota-http/index.js:34:29)
at Request.self.callback (/homebridge/node_modules/homebridge-sonoff-tasmota-http/node_modules/request/request.js:185:22)
at Request.emit (events.js:210:5)
at Request. (/homebridge/node_modules/homebridge-sonoff-tasmota-http/node_modules/request/request.js:1161:10)
at Request.emit (events.js:210:5)
at IncomingMessage. (/homebridge/node_modules/homebridge-sonoff-tasmota-http/node_modules/request/request.js:1083:12)
at Object.onceWrapper (events.js:299:28)
at IncomingMessage.emit (events.js:215:7)
at endReadableNT (_stream_readable.js:1183:12)
at processTicksAndRejections (internal/process/task_queues.js:80:21)

I added a fix to wrap the JSON parse which fixes the issue:

SonoffTasmotaHTTPAccessory.prototype.getState = function(callback) {
var that = this
request("http://" + that.hostname + "/cm?user=admin&password=" + that.password + "&cmnd=Power" + that.relay, function(error, res
if (error) return callback(error);
that.log("Sonoff HTTP: " + that.hostname + "body: " + body);
try{
var sonoff_reply = JSON.parse(body); // {"POWER":"ON"}
that.log("Sonoff HTTP: " + that.hostname + ", Relay " + that.relay + ", Get State: " + JSON.stringify(sonoff_reply));
switch (sonoff_reply["POWER" + that.relay]) {
case "ON":
callback(null, 1);
break;
case "OFF":
callback(null, 0);
break;
}
}catch(e){
return callback(error);
}
})
}

@juliangorge
Copy link

same issue, what's your firmware version?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants