MMM-LocalTemperature icon indicating copy to clipboard operation
MMM-LocalTemperature copied to clipboard

DHT 12 Sensor

Open tonizombie opened this issue 3 years ago • 6 comments

Would it be possible to use DHT 12 sensor with this module? (The board im using https://wiki.52pi.com/index.php?title=EP-0106)

tonizombie avatar Dec 24 '21 10:12 tonizombie

Hi, I don't have a DHT12 to test with. Have you tried it? It may just work.

glitch452 avatar Dec 24 '21 15:12 glitch452

I tried but just says "Loading..." under the module header when i start the mirror. No errors in log either, i think the issue might be with the DHT script that reads the temps. This is the script that came with the board and it works fine, so might be the script (https://wiki.52pi.com/index.php?title=EP-0106#Program_in_Language_C.28Raspberry_Pi.29)

tonizombie avatar Dec 24 '21 19:12 tonizombie

ah ok, quickly looking over that script, it looks like it asks the board to get the data from the sensor, rather than querying it directly. My recommendation would be to modify that script to output the data in the JSON format the this module expects ({ "humidity": 18.9, "celcius": 20.6, "fahrenheit": 69.1, "kelvin": 293.8, "attempts": 1 }) then set this module to use that script for the query.

glitch452 avatar Dec 24 '21 22:12 glitch452

As i know very little about C how would i go about with this? Would "printf(0x05, 0x06)" work? Those numbers being what the original script defines the temp and humidity as.

tonizombie avatar Dec 25 '21 18:12 tonizombie

Check out the source of my DHT script to see the output format. https://github.com/glitch452/MMM-LocalTemperature/blob/d17850d11a81d6e4d7b71463e214d631b96fa099/DHT.c#L297

glitch452 avatar Dec 26 '21 20:12 glitch452

I removed the farenheit, kelvin and attempts because they do not exist in the original code, also changed the original defines to temp_c and humidity. With this code (https://pastebin.com/d4Baysug) i can get it to output the humidity and celcius, however they are both 0.0 because the print is missing their (int)aReceiveBuf[EITHER temp_c OR humidity respectively]

Would you have any idea how to incorporate that intareceivebuff to the print?

In the original code it adds it just after the value (temperature = %d Celsius\n", (int)aReceiveBuf[temp_c]), if doing like this in the fprintf(stdout it also prints the aReceiveBuff after the 0.0 value and dosent actually get the sensor data

tonizombie avatar Dec 27 '21 08:12 tonizombie