hey guys!
i got a Mega2560 Uart connected towards a NodeMCU-ESP8266
The NodeMCU is connected to my WiFi and UDP.broadcasts the Data which he got serial the Mega2560
Somehow i cant use the Nodemcu hardware serial so i tried softserial.
This works. but sometimes the softserial reciever ist doing strange things for some seconds (arround 200-400 UDP packages).
Left: the Mega2560 serial output
Middle: SoftSerial from my Node which will be broadcasted over WiFi
Right: another Node also connected to Wifi which recieves the Data from the UDP.Broadcast
Here everything is fine for a long time:
Here its broken:
#define LED0 2 // WIFI Module LED
#define analogPin A0
#include <ESP8266WiFi.h>
#include <WiFiUDP.h>
#include <Wire.h>
#include <SoftwareSerial.h>
char inData[65]; // USART DATA BUFFER...
boolean started = false;
boolean ended = false;
boolean USART_completed = false;
SoftwareSerial SoftSerial(13, 12); // (RX,TX) // (D7, D6)
int index2;
int status = WL_IDLE_STATUS;
const char* ssid = "BBT"; // your network SSID (name)
const char* pass = "pennyisafreeloader"; // your network password
byte packetBuffer[512]; //buffer to hold incoming and outgoing packets
unsigned int localPort = 2390; // local port to listen for UDP packets
IPAddress ipMulti (192,168,178,255); // ipMulti (192.168.178.255);
WiFiUDP Udp; // A UDP instance to let us send and receive packets over UDP
void setup()
{
// pinMode(D7, INPUT); // RX0
pinMode(LED0, OUTPUT); // WIFI OnBoard LED Light
pinMode(analogPin, INPUT); // ADC PIN
Serial.begin(115200);
SoftSerial.begin(115200); // softwareserial
WiFi_setup();
I2C_Begin();
delay(1000);
}
void loop()
{
Read_SoftSerial_Data();
Serial_to_WiFi(); // Here we send the USART Data over WiFiUDP
// Recieve_WiFi_response(); // If a WIFI device sends us UDP data we can react in this function on
WiFi_setup(); // Here we check if we are still connected to the WiFi server
}
void Read_SoftSerial_Data(){
while (SoftSerial.available()>0) {
char inChar = SoftSerial.read();
if(inChar == '<'){
started = true;
index2 = 0;
inData[index2] = inChar;
index2++;
inData[index2] = '\0';
}
else if(inChar == '>'){
ended = true;
inData[index2] = inChar;
index2++;
inData[index2] = '\0';
}
else if(started){
inData[index2] = inChar;
index2++;
inData[index2] = '\0';
}
if(started && ended) {
started = false;
ended = false;
USART_completed = true;
Serial.println("inData:");
Serial.println(inData);
}
}
}
anybody got a clue why it suddnly gets broken ? is it maybe because its Softserial and it crashes into other timing or interrupt stuff ?
I would like to use the hardware UART but it does not work
transmissionrate: every 7ms i send out the string <0A255_233_132>
Another point to mention is that when I choose another UART frequency the data gets more and more broken.
Regards
Stefan