//Created by Barbu Vulc!
//BluetoothSerial & DHT libraries:
#include "BluetoothSerial.h"
#include <DHT.h>
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif
//Define the sensor:
#define DHTPIN 18
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
//Create BT object:
BluetoothSerial SerialBT;
int received; //Received value will be stored in this variable.
char receivedChar; //Received value will be stored as CHAR in this variable.
void setup() {
Serial.begin(115200);
SerialBT.begin("NodeMCU-32S"); //Bluetooth device name
Serial.println("The device started, now you can pair it with bluetooth!");
pinMode(DHTPIN, OUTPUT);
}
void loop() {
receivedChar = (char)SerialBT.read();
float temp = dht.readTemperature();
float hum = dht.readHumidity();
//Normally show in BT terminal temperature & humidity:
SerialBT.write(Serial.read());
SerialBT.print(temp); SerialBT.println(" °C \n");
SerialBT.print(hum); SerialBT.println(" % \n\n");
delay(500);
/*
* Serial.println(" BT stopping ");
* SerialBT.flush(); SerialBT.disconnect();
* SerialBT.end(); Serial.println(" BT stopped "); digitalWrite(LED, LOW);
*/
}