Aosong AM2315 temp/rh

Has anyone tried to collect Temp/RH data from a AM2315 sensor?

I've tried the i2C in/out nodes with little success (I get a return from the sensor but it doesn't make sense).

I can get data through python scripts so I know the sensor is wired correctly.

Which hardware? Show us your flow please!

[{"id":"1477d41f.ef3274","type":"inject","z":"414b12bb.d470bc","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":200,"y":360,"wires":[["9809ef2.46f0c1","4374245d.98630c"]]},{"id":"ea35a8fa.c6eb","type":"debug","z":"414b12bb.d470bc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":750,"y":420,"wires":[]},{"id":"9809ef2.46f0c1","type":"delay","z":"414b12bb.d470bc","name":"","pauseType":"delay","timeout":"250","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":430,"y":360,"wires":[["cb6377b9.a717a8","df8343ed.6fba58"]]},{"id":"cb6377b9.a717a8","type":"i2c out","z":"414b12bb.d470bc","name":"","address":"92","command":"3","payload":"[0x00,0x04]","payloadType":"str","count":"3","x":620,"y":360,"wires":[]},{"id":"df8343ed.6fba58","type":"i2c in","z":"414b12bb.d470bc","name":"","address":"92","command":"3","count":"5","x":610,"y":420,"wires":[["ea35a8fa.c6eb"]]},{"id":"4374245d.98630c","type":"i2c out","z":"414b12bb.d470bc","name":"","address":"92","command":"0","payload":"0","payloadType":"str","count":"2","x":440,"y":300,"wires":[]}]

Please redo pasting the flow between back-ticks or triple back-ticks.

You may need to decode the Python library you are using in order to work out how to read the raw sensor data. Personally, I always put sensors on an Arduino (direct connect) or ESP (output to MQTT) microprocessor so I don't have to think about sensor complexity - there is nearly always a suitable Arduino IDE library available.

1 Like

Re-pasted a simpler flow inside backticks.....

I am using a Raspberry Pi 3b with a Aosong AM2315.

The sensor needs to be sent a couple of bytes to wake it up then the commands to read (0x03), from register 0 (0x00), and the number of bytes (4). So all together is: [0x03,0x00,0x04]

The I2C input node seems to only allow a single byte in its command.

The backticks should be on separate lines, before and after the code:
```
code
```

sorry - new to this whole forum thing

Still wrong way.
Please read this to get flow sharing done in proper way
https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506

thank you - fixed (really this time)

I am currently working on am2315 temperature sensor on raspberry pi, it will be kind if you can share the flow and how do you connect the sensor, get everything works together, I tried about an hour now but no luck thanks in advance, Elvin.

Elvincth - my flow is pasted further up on the thread - as I stated, I get numbers from the sensor but they don't seem to coincide with my expected HEX Temp/RH.

The sensor needs to be wired to the PI: Red wire to 3.3V, Black wire to Ground, Yellow to SDA, White to SCL. Both Yellow and white wires require a pull-up resistor (I used 10K) from 3.3V.

1 Like

Thanks mate!

no problem - let me know how it turns out or if you figure out what I've done wrong.

In case anyone is interested I managed to get the AM2315 Temp/RH to work using the NPM i2c-sensor-am2315 driver:

[{"id":"b969dd56.ca08c","type":"debug","z":"414b12bb.d470bc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1070,"y":100,"wires":[]},{"id":"d5647717.af045","type":"debug","z":"414b12bb.d470bc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1070,"y":220,"wires":[]},{"id":"6a8e5018.4d76d","type":"function","z":"414b12bb.d470bc","name":"AM2315","func":"var Driver = global.get('am2315');\n\n// create device\nvar device = new Driver();\n\n// read the sensor\ndevice.read(function(err, data) {\n\tif (err) {\n\t\tconsole.error(err);\n\t} else {\n\t\tconsole.log('Original in K');\n\t\tconsole.log(data);\n\t\tnode.send([{payload: data}]);\n\t    \n\t}\n});\n\n\n\n","outputs":1,"noerr":0,"x":360,"y":160,"wires":[["54fd5c06.5177fc","ca3e1500.27111"]]},{"id":"9a2fe3db.285a3","type":"inject","z":"414b12bb.d470bc","name":"","topic":"","payload":"","payloadType":"date","repeat":"5","crontab":"","once":true,"onceDelay":0.1,"x":130,"y":160,"wires":[["6a8e5018.4d76d"]]},{"id":"54fd5c06.5177fc","type":"debug","z":"414b12bb.d470bc","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":530,"y":100,"wires":[]},{"id":"ca3e1500.27111","type":"split","z":"414b12bb.d470bc","name":"Split Environment","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"topic","x":590,"y":160,"wires":[["76fd5ab5.7c7c04","8d65cce5.b8e4b"]]},{"id":"76fd5ab5.7c7c04","type":"function","z":"414b12bb.d470bc","name":"Environment Type","func":"var topic = msg.topic;\n\nif(topic == 'temperature') {\n    var T = parseFloat(msg.payload - 273.15).toFixed(1);\n    global.set(\"TEMP\",T);\n    msg.payload = T\n    return [msg, null];}\nelse if (topic == 'humidity'){\n    var R = parseFloat(msg.payload).toFixed(1);\n    global.set(\"RH\",R);\n    msg.payload = R;\n    return [null, msg];}\n\n","outputs":2,"noerr":0,"x":790,"y":160,"wires":[["b969dd56.ca08c","d8251f9d.8fa6f"],["d5647717.af045","a69c2bd0.c15b08"]]},{"id":"d8251f9d.8fa6f","type":"ui_gauge","z":"414b12bb.d470bc","name":"Temp","group":"7c438e24.69789","order":0,"width":0,"height":0,"gtype":"gage","title":"Temp","label":"Deg C","format":"{{value}}","min":"-50","max":"50","colors":["#00b500","#e6e600","#ca3838"],"seg1":"0","seg2":"25","x":1050,"y":140,"wires":[]},{"id":"a69c2bd0.c15b08","type":"ui_gauge","z":"414b12bb.d470bc","name":"RH","group":"7c438e24.69789","order":0,"width":0,"height":0,"gtype":"gage","title":"RH","label":"%","format":"{{value}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"40","seg2":"60","x":1050,"y":180,"wires":[]},{"id":"8d65cce5.b8e4b","type":"debug","z":"414b12bb.d470bc","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":770,"y":100,"wires":[]},{"id":"7c438e24.69789","type":"ui_group","z":"","name":"TEMPERATURE","tab":"6fde6a42.ec3284","order":1,"disp":true,"width":"6","collapse":true},{"id":"6fde6a42.ec3284","type":"ui_tab","z":"","name":"Home","icon":"dashboard"}]
1 Like

I don't fully understand how you got this to work. I can get the sensor to work outside of Node Red but i cannot get your flow to work. I'm most likely over looking something simple but could use some guidance. The error I am getting is [function:am2315] TypeError: Driver is not a constructor. I don't know what that means.