I am writing the program on ESP32. I want the DHT11's data that sent to Android via Bluetooth. However, I have a error about the invalid conversion.
#include <SimpleDHT.h>
#include <BluetoothSerial.h>
#define DHT11_PIN 7
SimpleDHT11 chk(DHT11_PIN);
BluetoothSerial SerialBT;
void setup()
{
Serial.begin(9600);
Serial.println("Enter AT commands:");
// HC-06 default serial speed is 9600
BTserial.begin("BLETEST");
}
void loop()
{
String output = "";
String tokenizer = "@";
byte temperature = 0;
byte humidity = 0;
int err = SimpleDHTErrSuccess;
if ((err = chk.read(&temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
Serial.print("Read DHT11 failed, err=");
Serial.println(err);
delay(1000);
return;
}
// Keep reading from HC-06 and send to Arduino Serial Monitor
if (SerialBT.available())
{
Serial.write(SerialBT.read());
}
Serial.print((int)temperature); Serial.print(" *C, ");
Serial.print((int)humidity); Serial.println(" H");
// Keep reading from Arduino Serial Monitor and send to HC-06
//dummy data
SerialBT.write("@");
output.concat(tokenizer);
if ((int)temperature != -999.00 || (int)humidity != -999.00){
if((int)temperature != -999.00){
output.concat((int)temperature);
output.concat(";");
}
if((int)humidity != -999.00){
output.concat((int)humidity);
output.concat(";");
}
output.concat("0.00@");
Serial.println(output);
SerialBT.write(output.c_str());
SerialBT.write("@100.25;100.00;100.00@");
}
delay(10);
delay(500);
}
The error message:
C:\Users\yiu_c\OneDrive\桌面\arduino\bt-weather-arduino\bt-weather-arduino.ino: In function 'void loop()':
bt-weather-arduino:57:26: error: invalid conversion from 'const char*' to 'uint8_t {aka unsigned char}' [-fpermissive]
In file included from C:\Users\yiu_c\OneDrive\桌面\arduino\bt-weather-arduino\bt-weather-arduino.ino:5:0:
C:\Users\yiu_c\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.2\libraries\BluetoothSerial\src/BluetoothSerial.h:38:16: note: initializing argument 1 of 'virtual size_t BluetoothSerial::write(uint8_t)'
size_t write(uint8_t c);
How can put the variable of string in SerialBT.write? In this situation, the variable of string cannot put in function of SerialBT.write.
Have anyone can solve this problem?