From 964d8c90cf59e26d84514474549d9138870b16cf Mon Sep 17 00:00:00 2001 From: KubMakCZ Date: Thu, 6 Feb 2025 12:08:52 +0100 Subject: [PATCH] add 02 variant A --- 02a_serialBT_DTH11/02a_serialBT_DTH11.ino | 47 +++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 02a_serialBT_DTH11/02a_serialBT_DTH11.ino diff --git a/02a_serialBT_DTH11/02a_serialBT_DTH11.ino b/02a_serialBT_DTH11/02a_serialBT_DTH11.ino new file mode 100644 index 0000000..6131625 --- /dev/null +++ b/02a_serialBT_DTH11/02a_serialBT_DTH11.ino @@ -0,0 +1,47 @@ +#include "BluetoothSerial.h" +#include + +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); +} \ No newline at end of file