Closed bwired-nl closed 8 years ago
What's in response and responsebody at the time of the error - I expect that's what it can't parse - probably malformed json or xml or the decimal in the response is upsetting httprequest
If I do this.log(resonse) or reponse body its undefined. And only when I use the decimal? If I click on the link from within the config it gives me the right value with decimal in chrome
If you wrote the called function try wrapping the result in double quotes to see if that will parse okay
You mean like this res.sendStatus("15.1"); instead of res.sendStatus('15.1');
see same result below, the undefined is the value
[Kamertemperatuur] Getting temp level [Kamertemperatuur] http://10.0.0.47:3031/temp [Kamertemperatuur] HTTP get temp function failed: Parse Error Accessory [HomebridgeBwired] Got Characteristic "Current Temperature" value: undefined +96ms Accessory [HomebridgeBwired] Error getting value for Characteristic "Current Temperature": Parse Error +1ms [Kamertemperatuur] undefined
I'm confused you're using a sendStatus to pass data back? can you share more code please?
my http server is on nodejs and is using Node express this is what i send back Works great on all other devices like switches etc and like i told if i put in '15' below it works...its making me crazy :)
app.get('/temp', function (req, res) { console.log('temp info') res.sendStatus("15.1"); });
sendStatus is for the response status (refer http://expressjs.com/en/api.html) - it only expects a few http defended values - a decimal would freak it out. Don't know express personally. But their hello world example returns data via res,send. http://expressjs.com/en/starter/hello-world.html
wtf:
i always use res.send before but got a message with other devices i need to use res.sendStatus() and it worked. but not with this temp values. with res,send its working :) many thanks!
res.send() Send a response of various types. res.sendStatus() Set the response status code and send its string representation as the response body.
Note the last line - it does set the vale as the return value, but also attempts to set the value as the "http status" - which a decimal value would break i expect.
res.sendStatus(statusCode)
Set the response HTTP status code to statusCode and send its string representation as the response body.
res.sendStatus(200); // equivalent to res.status(200).send('OK')
res.sendStatus(403); // equivalent to res.status(403).send('Forbidden')
res.sendStatus(404); // equivalent to res.status(404).send('Not Found')
res.sendStatus(500); // equivalent to res.status(500).send('Internal Server Error')
If an unsupported status code is specified, the HTTP status is still set to statusCode and the string version of the code is sent as the response body.
res.sendStatus(2000); // equivalent to res.status(2000).send('2000')
Hi Mr Rudders
Adding more sensors to your http plugin :-) getting a parse error with the temp status? if i send back '15' all is OK and the temp displays 15, no errors. if i send back '15.1' or '15,1' I get a parse error?
Hope you can help
part of the index.js
And this is the error i get, when i send back '15.1'