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

Temperature sensor not showing any data #13

Open
dror3go opened this issue Jan 11, 2020 · 12 comments
Open

Temperature sensor not showing any data #13

dror3go opened this issue Jan 11, 2020 · 12 comments

Comments

@dror3go
Copy link
Contributor

dror3go commented Jan 11, 2020

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:

$ /usr/sbin/i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: 40 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --

How can I make the sensor up and running?
Thanks a lot

@rzr
Copy link
Owner

rzr commented Jan 11, 2020

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 ?

@dror3go
Copy link
Contributor Author

dror3go commented Jan 11, 2020

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.

@rzr
Copy link
Owner

rzr commented Jan 12, 2020

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:
bbx10/node-htu21d#1

rzr added a commit that referenced this issue Jan 13, 2020
API could be renamed to readHumidity to align some drivers

Relate-to: #13
Change-Id: I0b26199d4384e8aab9fd0894ded26664fe50663a
Signed-off-by: Philippe Coval <rzr@users.sf.net>
rzr added a commit that referenced this issue Jan 13, 2020
API could be renamed to readHumidity to align some drivers

Relate-to: #13
Change-Id: I0b26199d4384e8aab9fd0894ded26664fe50663a
Signed-off-by: Philippe Coval <rzr@users.sf.net>
@rzr
Copy link
Owner

rzr commented Jan 13, 2020

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

bbx10/node-htu21d#2

@dror3go
Copy link
Contributor Author

dror3go commented Jan 14, 2020

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?

@rzr
Copy link
Owner

rzr commented Jan 14, 2020

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.

@dror3go
Copy link
Contributor Author

dror3go commented Jan 15, 2020

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?

@rzr
Copy link
Owner

rzr commented Jan 15, 2020

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.

rzr added a commit that referenced this issue Jan 17, 2020
Test using:

   node lib/humidity '{ "controller": "htu21d" }'

Relate-to: #13
Change-Id: I8f4dfa53b478a42019f445e46da9f9de93768c4a
Signed-off-by: Philippe Coval <rzr@users.sf.net>
rzr added a commit that referenced this issue Jan 17, 2020
Relate-to: #13
Change-Id: I9872317ed9cae7c8a6966da962a71e2eb252ff95
Signed-off-by: Philippe Coval <rzr@users.sf.net>
rzr added a commit that referenced this issue Jan 17, 2020
Test using:

   node lib/humidity '{ "controller": "htu21d" }'

Relate-to: #13
Change-Id: I8f4dfa53b478a42019f445e46da9f9de93768c4a
Signed-off-by: Philippe Coval <rzr@users.sf.net>
rzr added a commit that referenced this issue Jan 17, 2020
Relate-to: #13
Change-Id: I9872317ed9cae7c8a6966da962a71e2eb252ff95
Signed-off-by: Philippe Coval <rzr@users.sf.net>
rzr added a commit to rzr/generic-sensors-webthings that referenced this issue Jan 18, 2020
Note only humidity is used with this sensor also
measuring temperature,
maybe an other API will be needed to support both type.

Relate-to: rzr/generic-sensors-lite#13
Change-Id: I19a57898209ed6421cc760ae5a2ab3f4d8034379
Signed-off-by: Philippe Coval <rzr@users.sf.net>
@rzr
Copy link
Owner

rzr commented Jan 19, 2020

@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 ?

@rzr
Copy link
Owner

rzr commented Jan 21, 2020

Thx @dror3go to confirm your change
dror3go@6727023

Is fixing this bug, I will release a new version once my patches are merged, starting with:

bbx10/node-htu21d#4

rzr added a commit that referenced this issue Feb 7, 2020
Test using:

   node lib/humidity '{ "controller": "htu21d" }'

Relate-to: #13
Change-Id: I8f4dfa53b478a42019f445e46da9f9de93768c4a
Signed-off-by: Philippe Coval <rzr@users.sf.net>
rzr added a commit that referenced this issue Feb 7, 2020
Relate-to: #13
Change-Id: I9872317ed9cae7c8a6966da962a71e2eb252ff95
Signed-off-by: Philippe Coval <rzr@users.sf.net>
@rzr
Copy link
Owner

rzr commented Feb 7, 2020

Back to the original temperature use:

Please @dror3go forward this change with a PR:

dror3go@6727023

Make sure to update requiere path like I did for humidity:

#14

rzr added a commit to rzr/generic-sensors-webthings that referenced this issue Mar 3, 2020
Note only humidity is used with this sensor also
measuring temperature,
maybe an other API will be needed to support both type.

Relate-to: rzr/generic-sensors-lite#13
Change-Id: I19a57898209ed6421cc760ae5a2ab3f4d8034379
Signed-off-by: Philippe Coval <rzr@users.sf.net>
@rzr
Copy link
Owner

rzr commented Mar 3, 2020

Current release should fix this bug, please @dror3go test to confirm this issue should be closed.

See you at:

rzr/generic-sensors-webthings#5

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