DHT

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.


_read

uint32_t read;                 // calls to _read()
  uint32_t read_success;         // successful _read()
  uint32_t read_success_cached;  // calls to _read() which were cached
  // Note: read_errors := read - read_success - read_success_cached
  double read_success_usecs;     // time spent in successful uncached _read()
};

value of mg_time() upon last call to _read()

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.

mgos_dht_getStats

bool mgos_dht_getStats(struct mgos_dht *dht, struct mgos_dht_stats *stats);

Returns the running statistics on the sensor interaction, the user provides a pointer to a struct mgos_dht_stats object, which is filled in by this call.

Upon success, true is returned. Otherwise, false is returned, in which case the contents of stats is undetermined.

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