Open dror3go opened 4 years ago
HTU21D is not yet supported by https://github.com/rzr/generic-sensors-lite
But it looks there are other drivers available: https://www.npmjs.com/search?q=HTU21D
Tell me you manage to use any of those ?
Then it should be easy to add it as a new "controller" in https://github.com/rzr/generic-sensors-lite/tree/master/lib/temperature
Just add an else statement in: https://github.com/rzr/generic-sensors-lite/blob/master/lib/temperature/index.js#L98
Then adapter can be updated
Does this help ?
I'm trying to use sensor-htu21d but I'm not sure what are the steps. So I did:
cd /home/pi/.mozilla-iot/addons/generic-sensors-adapter/
npm i sensor-htu21d
Then I edited node_modules/generic-sensors-lite/lib/temperature/index.js
:
var Htu21d = null;
...
try {
Htu21d = require('htu21d.js');
} catch (err){
// console.log(err);
}
...
} else if (this.options.controller === 'htu21d' || this.options.controller === 'htu21d-sensor') {
this.sensor = new Htu21d(this.options.sensor);
}
But I'm pretty sure I'm not doing it right :-) Any help would be appreciated.
well it's a good start
This module could be preferable to use: https://github.com/bbx10/node-htu21d/blob/master/index.js#L95
Then it will be easier to also support iotjs: https://github.com/rzr/webthing-iotjs/wiki/IotJs
To make it easier may I suggest that we use focus only on humidity value first then once merged some refactoring should be done...
Let me suggest this plan
1/ duplicate: https://github.com/rzr/generic-sensors-lite/blob/master/lib/battery to "lib/humidity"
2/ Then replace occurrences of "battery" to "humidity" :)
3/ replace "read" by "readHumidity" (update simulator too)
https://github.com/bbx10/node-htu21d/blob/master/index.js#L95
4/ then you can try by running once it work you can open a PR
node ./lib/humidity
5/ Add Humidity to: https://github.com/rzr/generic-sensors-lite/blob/master/lib/index.js
6/ import driver and add controller like you did in init part, test it update PR Set default Humidity driver in: https://github.com/rzr/generic-sensors-lite/blob/master/lib/controllers.js
7/ I will suggest a plan for refactoring this into temperature sensor too
8/ Multiple type sensors should be also specified, eventually as non w3c API, relate to: https://github.com/bbx10/node-htu21d/issues/1
I have prepared you the last for step 6 and later
On trouble feel free to reach me here or on irc
May I ask @dror3go what distro are you using ?
If debian please can you try Iot.js:
https://github.com/rzr/webthing-iotjs/wiki/IotJs
with
I made the changes manually, but the humidity is not available in the UI. Is there a command I need to run 1st in order to be able to use it?
I noticed that when viewing ~/.mozilla-iot/addons/generic-sensors-adapter/package.json
then it contains moziot
object with generic-sensors
config array, which includes ambientLightSensor
, colorSensor
, temperatureSensor
, but lacks the new humiditySensor
.
Also, note that I still have version 0.0.9, just with these humidity manual additions. Should I update to 0.0.14 and if so - how?
As for the distro - well I'm using Mozilla gateway 0.10.0 and when I SSH to the Pi I see that it's indeed Debian. What's the motivation to use IotJs and what is its current replacement in the default setup?
yes I am about to update the mozilla adapter without the humidity sensor... I wanted you to test the driver in this module, if it is working please show me your code in a PR, if it's good I will integrate it in next version.
Originally i made this module for iotjs and since it's backward compatible with node, then i reused this module in mozilla addon.
Oh sorry, I totally forgot about the readings.
So after I've added lib/humidity/index.js
, lib/humidity/simulator.js
and running:
$ node ./lib/humidity
log: level=0.559389175818104
That's fine. But I wasn't able to use the driver, it's still using the simulator. Where should I initiate the driver?
yes the simulator is used by default So you need to add the controller in
https://github.com/rzr/generic-sensors-lite/blob/master/lib/humidity/index.js
like I made for
https://github.com/rzr/generic-sensors-lite/blob/master/lib/temperature/index.js#L94
Then you can test it using:
node lib/humidity "{ \"controller\": \"node-htu21\"}"
I can prepare this in a branch if you can try find me in chat room.
@dror3go If you also added htu21d to temperature, please confirm if both can be added to mozilla gateway and used at the same time maybe not in that case other API will be needed any idea ?
Thx @dror3go to confirm your change https://github.com/dror3go/generic-sensors-lite/commit/6727023aa6420b645451780039b326f6d17b8521
Is fixing this bug, I will release a new version once my patches are merged, starting with:
Back to the original temperature use:
Please @dror3go forward this change with a PR:
https://github.com/dror3go/generic-sensors-lite/commit/6727023aa6420b645451780039b326f6d17b8521
Make sure to update requiere path like I did for humidity:
Current release should fix this bug, please @dror3go test to confirm this issue should be closed.
See you at:
https://github.com/rzr/mozilla-iot-generic-sensors-adapter/issues/5
I purchased ANAVI Infrared pHAT together with a temperature & humidity sensor (HTU21D), and attached it to a Pi 3 with a newly installed gateway version 0.10.0. I was able to add the device in the gateway, however I can't seem to get a reading of it: when I try to turn it on (browsing to /things/generic-sensors-2) I see in the browser's network log that when I press the "on" button there's a request to PUT /things/generic-sensors-2/properties/on which doesn't get an answer. Another click on the button, to turn it off, results in an immediate response in the network tab (
{"on":false}
).When I SSH to the Pi I get this:
How can I make the sensor up and running? Thanks a lot