because of this lockdown situation I can't buy a Arduino that has WIFI inbuild. So I had to use the things that I have at home to complete my project. So I decided to connect my Nodemcu esp8266 to arduino via serial communication and send that data to the firebase. The data comes all good to the Nodemcu and can see that on the serial monitor until I start to send that data to the firebase. when I put the code line that needs to send data to firebase, incoming data from the arduino uno goes crazy. And on firebase realtime database it shows some random numbers. Im a noob at this. I searched every where for a solution but there was non. I think way im saving the serialread data to the variable is also wrong. Can someone please help me? down here is the code I used.
arduino code
#include <dht.h>
#include <SoftwareSerial.h>
dht DHT;
#define DHT11_PIN 4
SoftwareSerial espSerial(5, 6);
String str;
float h, t;
void setup(){
Serial.begin(115200);
espSerial.begin(115200);
delay(2000);
}
void loop(){
int chk = DHT.read11(DHT11_PIN);
Serial.print("Temperature = ");
Serial.println(DHT.temperature);
Serial.print("Humidity = ");
Serial.println(DHT.humidity);
h = DHT.humidity;
t = DHT.temperature;
str =String("coming from arduino: ")+String("H= ")+String(h)+String("T= ")+String(t);
espSerial.println(str);
delay(2000);
}
nodemcu esp8266 code
#include <ESP8266WiFi.h> // esp8266 library
#include <FirebaseArduino.h> // firebase librar // dht11 temperature and humidity sensor library
#define FIREBASE_HOST "######################################"
#define FIREBASE_AUTH "#####################################"
#define WIFI_SSID "###########"
#define WIFI_PASSWORD "##########"
String alldata;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
delay(1000);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
}
void loop() { // run over and over
if (Serial.available()) {
Serial.write(Serial.read());
alldata = Serial.read();
}
Firebase.pushString("/smart pot/data", alldata);
delay(500);
}