Hi people,
I have some program on Arduino NANO with sensors and buttons, display etc.
I need to send some data from that sensors to ESP8266 over serial. There I want to send them to NodeRED.
I tried that code on my test breadboard and I have some difficulties with data transmission.
Arduino and ESP are connected according to this scheme.
For test purposes, I am using one dht11. To generate some test data to serial output.
#include <dht.h>
dht Sensor;
String Str_Payload ;
#define DHT11_PIN 7
void setup(){
Serial.begin(9600);
}
void loop()
{
int chk = Sensor.read11(DHT11_PIN);
String Temp = (String)Sensor.temperature ;
String Hum = (String)Sensor.humidity ;
int DataCounter = 2;
Str_Payload = "";
Str_Payload += DataCounter;
Str_Payload += " " + Temp;
Str_Payload += " " + Hum;
Str_Payload += " ";
Str_Payload += "\n";
Serial.print(Str_Payload);
delay(1000);
}
This is my test code from ESP.
#include<SoftwareSerial.h>
#include <PubSubClient.h>
#include <stdio.h>
//Included SoftwareSerial Library
//Started SoftwareSerial at RX and TX pin of ESP8266
SoftwareSerial s(3, 1);
String InputString;
char Input [20];
int DataCount = 0;
float Temp = 0 ;
float Hum = 0 ;
void setup() {
//Serial S Begin at 9600 Baud
s.begin(9600);
}
void loop() {
while (s.available()) {
InputString = s.readString();
InputString.toCharArray(Input, InputString.length());
s.print(" Received by ESP:");
s.print(InputString);
s.println();
int n = sscanf(Input, "%d:f:f", &DataCount, &Temp, &Hum);
s.print("Count = " );
s.print(DataCount);
s.print(" Temperature =" );
s.print(Temp);
s.print("Humidity = " );
s.print(Hum);
s.println();
}
}
There I want to parse incoming String to individual float values. (Will be maybe 10)
And send separate value via publish(const char* topic, const char* payload);
from <PubSubClient.h> library
But if i put serial monitor also to ESP TX pin.. (TTDI232) I receiving some wrong chars.
Please who know why it happening and how to solve this task better.
Especially to make it work.