You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.0 KiB
47 lines
1.0 KiB
#include "BluetoothSerial.h"
|
|
#include <DHT11.h>
|
|
|
|
String device_name = "ESP32-DHT-VasePrijmeni";
|
|
|
|
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);
|
|
}
|