DHT temp sensor

Github Repo C Header C source JS source
mongoose-os-libs/dht mgos_dht.h   api_dht.js

Overview

This is a library for the DHT series of low cost temperature/humidity sensors.


DHT sensor API.

See https://learn.adafruit.com/dht/overview for more information.


mgos_dht_create

struct mgos_dht *mgos_dht_create(int pin, enum dht_type type);

Initialise DHT sensor. Return an opaque DHT handle, or NULL on error.

mgos_dht_close

void mgos_dht_close(struct mgos_dht *dht);

Close DHT handle.

mgos_dht_get_temp

float mgos_dht_get_temp(struct mgos_dht *dht);

Return temperature in DegC or 'NAN' on failure.

mgos_dht_get_humidity

float mgos_dht_get_humidity(struct mgos_dht *dht);

Return humidity in % or 'NAN' on failure.

JS API


DHT.create

DHT.create(pin, type)

Create a DHT object. type could be DHT.DHT11, DHT.DHT21, DHT.DHT22. Return value: an object with the methods described below, or 'null' in case of a failure. Example:

let mydht = DHT.create(5, DHT.DHT11);
print('Temperature:', mydht.getTemp());

mydht.close

mydht.close()

Close DHT handle. Return value: none.

mydht.getTemp

mydht.getTemp()

Return temperature in degrees C or 'NaN' in case of a failure.

mydht.getHumidity

mydht.getHumidity()

Return humidity in RH% or 'NaN' in case of a failure.

edit this doc