Replace the trigger of sending logs to server from serial port data_received event to timer.
This commit is contained in:
@@ -1,35 +1,35 @@
|
||||
#include <DHT22.h>
|
||||
#include <DHT11.h>
|
||||
|
||||
#define DHTPIN 2
|
||||
#define DHTTYPE DHT22
|
||||
|
||||
DHT22 dht(DHTPIN);
|
||||
DHT11 dht(DHTPIN);
|
||||
|
||||
void setup() {
|
||||
// put your setup code here, to run once:
|
||||
Serial.begin(115200);
|
||||
Serial.println("Hello, ESP32!");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// put your main code here, to run repeatedly:
|
||||
|
||||
float h = dht.getHumidity();
|
||||
float t = dht.getTemperature();
|
||||
float f = dht.getTemperature(true);
|
||||
int h = 0;
|
||||
int t = 0;
|
||||
//int h = dht.getHumidity();
|
||||
//int t = dht.readTemperature();
|
||||
//float f = dht.getTemperature(true);
|
||||
|
||||
if (isnan(h) || isnan(t) || isnan(f)) {
|
||||
Serial.println(F("Failed to read from DHT sensor!"));
|
||||
return;
|
||||
}
|
||||
int res = dht.readTemperatureHumidity(t, h);
|
||||
|
||||
Serial.print("{ \"tempC\" : ");
|
||||
Serial.print(t);
|
||||
Serial.print(", \"tempF\" : ");
|
||||
Serial.print(f);
|
||||
Serial.print(", \"tempH\" : ");
|
||||
Serial.print(h);
|
||||
Serial.println(" }");
|
||||
|
||||
if (res == 0) {
|
||||
Serial.print("{ \"tempC\" : ");
|
||||
Serial.print(t);
|
||||
Serial.print(", \"tempF\" : ");
|
||||
Serial.print("0.00");
|
||||
Serial.print(", \"tempH\" : ");
|
||||
Serial.print(h);
|
||||
Serial.println(" }");
|
||||
} else {
|
||||
Serial.println(DHT11::getErrorString(res));
|
||||
}
|
||||
delay(1000); // this speeds up the simulation
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user