-
Notifications
You must be signed in to change notification settings - Fork 64
Support Generic Sensor APIs for common sensors #96
Comments
I had just noticed the DHT22 on adafruit yesterday and wondered how we would support something like that. So this sounds great, I'd like to look at it myself if I can finish up the stuff I'm doing right now. |
Be aware that there are two versions (one external, and one which requires external pullup resistor or the communication channel won't work at all). The Generic Sensor API will have to be adjusted for Node.js (We had planned to do that, but the funding to the guy contracted to do it was cut - so I don't know the status). The big issue is that there are no DOMString (just String which is basically the same), no DOMHighResTimers (can be emulated with double) and no EventTarget (but an EventEmitter which works quite differently) in node.js. Here is how the temperature API would look with EventEmitter (my adjustments). Changes are market by ** ... **
Example:
|
This here is the one with internal pullup: https://www.adafruit.com/products/393 As the Arduino 101 has a six-axis accelerometer and gyroscope we can also implement: https://rawgit.com/w3c/gyroscope/gh-pages/index.html in a similar fashion, without needing a special option to select controller. |
Going to split this out into other bugs and just let this be about the actual Sensor objects |
Closing because the basic API is there and the A101 built-in sensors are supported. Other issues have been opened for the DHT22 specifically. |
Some sensors are quite impossible to implement using I2C, GPIO etc on top of JS and that might also not be very efficient if it was possible.
For this Zephyr has the sensor subsystem: https://www.zephyrproject.org/doc/subsystems/sensor.html
This works with the very common DTH22 sensor for instance: https://www.adafruit.com/product/385
Sensors are relative easy to use in Zephyr (Might require to run on ARC, that is the only thing that I tested):
Unfortunately, a few changes might be required to Zephyr in order to set the pin from JS, as it is currently set by a build config
CONFIG_DHT_GPIO_PIN_NUM
Here are a few of our W3C proposals for temperature and humidity sensors.
https://github.com/otcshare/thermometer/blob/gh-pages/index.html
https://github.com/otcshare/hygrometer/blob/gh-pages/index.html
These build upon: https://www.w3.org/TR/generic-sensor/#idl-index
(It is planned that the spec will align so that it will work on node.js, so I would say that it is fine replacing the EventTarget - ie
onchange
,onerror
with anon("change")
andon("error")
event, at least until that gets settled)Example code:
We could add the pin and sensor name as arguments to
TemperatureSensor
, ieThe text was updated successfully, but these errors were encountered: