#include "DHTesp.h"
#include <BluetoothSerial.h>
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif
BluetoothSerial SerialBT;
const int DHT_PIN = 15;
DHTesp dhtSensor;
void setup() {
Serial.begin(115200);
SerialBT.begin("ESP32");
Serial.println("The device started, now you can pair it with bluetooth!");
dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
}
void loop() {
delay(2000);
TempAndHumidity data = dhtSensor.getTempAndHumidity();
if (SerialBT.available()) {
String request = SerialBT.readString();
if (request == "get_data") {
String data = "Temperature: " + String(data.temperature, 2) + "°C, Humidity: " + String(data.humidity, 1) + "%";
SerialBT.println(data);
}
}
}