dhtserver/src/dht/linux/libdht.c

18 lines
382 B
C
Raw Normal View History

2021-04-23 12:41:16 +02:00
#include "libdht.h"
#include <stdio.h>
#include <unistd.h>
#include <pi_2_dht_read.h>
int getdhtstring(int PIN, char* string)
{
float humid;
float temp;
while (1) {
2021-04-23 13:19:34 +02:00
if (pi_2_dht_read(DHT22, PIN, &humid, &temp) == DHT_SUCCESS) {
2021-04-23 12:41:16 +02:00
sprintf(string, "{\"humidity\": %.1f, \"temp\": %.1f}", humid, temp);
break;
}
}
return 0;
}