1 changed files with 47 additions and 0 deletions
@ -0,0 +1,47 @@ |
|||
#include "BluetoothSerial.h" |
|||
#include <DHT11.h> |
|||
|
|||
String device_name = "ESP32-DHT-Skrabanek"; |
|||
|
|||
BluetoothSerial SerialBT; |
|||
DHT11 dht11(5); |
|||
|
|||
void setup() { |
|||
Serial.begin(115200); |
|||
|
|||
SerialBT.begin(device_name); |
|||
//SerialBT.deleteAllBondedDevices();
|
|||
Serial.printf("Zarizeni \"%s\" je zapnuto. \n Bluetooth se brzy zobrazí",device_name.c_str()); |
|||
|
|||
} |
|||
|
|||
void loop() { |
|||
|
|||
if (SerialBT.available()) { |
|||
String command = SerialBT.readStringUntil('\n'); |
|||
command.trim(); |
|||
|
|||
if(command.equalsIgnoreCase("ok")) { |
|||
|
|||
int teplota = 0; |
|||
int vlhkost = 0; |
|||
|
|||
int result = dht11.readTemperatureHumidity(teplota, vlhkost); |
|||
|
|||
String senzorData; |
|||
if (result == 0) { |
|||
senzorData = "Teplota: " + String(teplota) + "°C, Vlhkost: " + String(vlhkost) + "%"; |
|||
} else { |
|||
senzorData = "Chyba pri cteni DHT11: " + String(DHT11::getErrorString(result)); |
|||
} |
|||
|
|||
Serial.println(senzorData); |
|||
SerialBT.println(senzorData); |
|||
}else { |
|||
SerialBT.println("Neznamy prikaz. napis ok pro ziskani dat"); |
|||
} |
|||
|
|||
} |
|||
|
|||
delay(2000); |
|||
} |
Loading…
Reference in new issue