Hey all I am trying to upload the data I get from DHT11 on a server. I know I can upload it immediately if I connect the DHT to the ESP8266, I still want to try to connect both of them though. So basically I want the arduino to measure the temperature, send it to the ESP which will then store it on a variable and upload it to the server. I can't manage to store it on a variable though. I connected it like this picture from this guy's guide :
if the RX & TX pins are connected I get the message which was given from the arduino : . If I try to write something on the monitor myself it is not getting printed. If I am disconnecting the TX & RX pins nothing comes (surprising) but I can print to the serial monitor myself and it stores the information I print on the variable. In the picture I uploaded the output at the top (<26>) is when TX & RX are connected, on the bottom they are not. I suppose I block the serial communication somehow by letting the arduino sending message there. Do you guys know how I can enjoy both world ? getting a message and storing it on a variable ? Thank you all in advance Hier are the sketches :
Arduino :
#include <SoftwareSerial.h>
#include <EduIntro.h>
DHT11 dht11(D2); //adjusting the Sensor DATA pin to pin 7 of the Arduino
SoftwareSerial espSerial(5, 6);
void setup() {
Serial.begin(9600);
espSerial.begin(9600);
delay(2000);
}
void loop()
{
dht11.update();
float temperature = dht11.readCelsius();
Serial.print( "\t Temperature: ");
Serial.print(temperature);
Serial.println("°C");
delay (1000);
espSerial.print (temperature) ;
espSerial.println (" >") ;
delay(1000);
}
ESP (which sketch I took from the serial input guide) :
const byte numChars = 32;
char receivedChars[numChars]; // an array to store the received data
boolean newData = false;
float dataNumber = 0; // new for this version
void setup() {
Serial.begin(9600);
}
void loop() {
recvWithEndMarker();
showNewNumber();
}
void recvWithEndMarker() {
static byte ndx = 0;
char endMarker = '>';
char rc;
if (Serial.available() > 0) {
rc = Serial.read();
if (rc != endMarker) {
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
}
else {
receivedChars[ndx] = '\0'; // terminate the string
ndx = 0;
newData = true;
}
}
}
void showNewNumber() {
if (newData == true) {
// dataNumber = 0; // new for this version
dataNumber = atof (receivedChars); // new for this version
Serial.print("This just in ... ");
Serial.println(receivedChars);
Serial.print("Data as Number ... "); // new for this version
Serial.println(dataNumber); // new for this version
newData = false;
}
}
Thank you so much !
![u[pload.png|1013x518](upload://4gkdTaogfQ2vnm83fFMg62lNLtU.png)