Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: SoftSerial MAX14690 Buffer
Fork of rtos_threading_with_callback by
acquireDHT/getDHT.cpp
- Committer:
- lwehmeier
- Date:
- 2018-03-30
- Revision:
- 3:d7ec6dc025b0
- Parent:
- 2:bf699e054b34
File content as of revision 3:d7ec6dc025b0:
#include "mbed.h" #include "DHT.h" #include "rtos.h" #include "global.h" #include "logger.h" class DHTData { public: static void run() { while(1) { int error = dht.readData(); if (0 == error) { float c = dht.ReadTemperature(CELCIUS); float h = dht.ReadHumidity(); humidity = h; float dpf = dht.CalcdewPointFast(c, h); char *buffer = new char[50]; sprintf(buffer, "Temperature: %3.2f, Humidity: %3.2f\r\n", c,h); Logger::log(buffer); printf("DHT: Temperature in Celcius: %4.2f\r\n", c); printf("DHT: Humidity is %4.2f, Dewpoint: %4.2f\r\n", h, dpf); { linkPacket *p = new linkPacket(); uint8_t *data = new uint8_t[4]; data[0]=((uint8_t*)&h)[0]; data[1]=((uint8_t*)&h)[1]; data[2]=((uint8_t*)&h)[2]; data[3]=((uint8_t*)&h)[3]; p->payload=data; p->payloadSz=4; p->priority =3; p->frameType = FRAMETYPE_HUMIDITY; txQueue.addPacket(p); } { linkPacket *p = new linkPacket(); uint8_t *data = new uint8_t[4]; data[0]=((uint8_t*)&dpf)[0]; data[1]=((uint8_t*)&dpf)[1]; data[2]=((uint8_t*)&dpf)[2]; data[3]=((uint8_t*)&dpf)[3]; p->payload=data; p->payloadSz=4; p->priority =3; p->frameType = FRAMETYPE_DEWPOINT; txQueue.addPacket(p); } } else { printf("DHT: Error: %d\r\n", error); } rtos::Thread::wait(20000);//ms } } DHTData() { registerThread(DHTData::run); } static DHT dht; }; DHT DHTData::dht(P3_2, DHT11);; // some witchcraft to register run function without touching anything outside our library static DHTData _dummy;