Fork me on GitHub

A DHT Mongoose OS library

Overview

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

C API Reference mgos_dht.h

#include "mgos_dht.h"

View this file on GitHub: mgos_dht.h


enum dht_type {
  DHT11 = 11,
  DHT21 = 21,
  AM2301 = 21,
  DHT22 = 22,

  AM2302 = 22
};

Supported sensor types

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

Initializes DHT. Returns the DHT handle opaque pointer or 'NULL' if operation failed.

void mgos_dht_close(struct mgos_dht *dht);

Closes the DHT handle.

float mgos_dht_get_temp(struct mgos_dht *dht);

Returns temperature in DegC or 'NAN' if operation failed.

float mgos_dht_get_humidity(struct mgos_dht *dht);

Returns humidity in % or 'NAN' if operation failed.

bool mgos_dht_init(void);

JAVASCRIPT API Reference api_dht.js

load("api_dht.js");

Mongoose OS DHT library API. Source C API is defined at: mgos_dht.h


dht.close()

Close DHT handle. Return value: none.

dht.getTemp()

Returns temperature in DegC or 'NaN' if operation failed

dht.getHumidity()

Returns temperature in RH% or 'NaN' if operation failed.

DHT.create(pin, type)

Create a DHT object. type could be DHT.DHT11, DHT.DHT21, DHT.DHT22. Return value: DHT handle opaque pointer or 'null' if operation failed. Example:

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