I am write you because I am running out of ideas to fix it..
I have a java server controling a car robot by UDP. Basicly the robot send its sensor values and server is then sending movement direction and speed.
- Using a ESP8266-ESP01 with firmware 1.5.4 at 115200 baud.
- Using arduino mega at 115200 on Serial and 115200 on Serial1 connected to the ESP.
100% working :
Robot --> to Server
Half working :
Server -->to Robot
For testing purpose, the complet packet should look like the following :
ROORD|{"motor":{"direction":"neutral","speed":0,"time":0},"ip":"192.168.0.100"}
Wireshark prove that the server packets are full and correct. Ex:
0000 84 0d 8e 84 18 c5 00 22 4d 49 3b 7b 08 00 45 00 .....Å."MI;{..E.
0010 00 6b 3e 5b 00 00 80 11 00 00 c0 a8 00 64 c0 a8 .k>[......ˬ.dˬ
0020 00 77 11 5d 11 5f 00 57 82 94 52 4f 4f 52 44 7c .w.]._.W..ROORD|
0030 7b 22 6d 6f 74 6f 72 22 3a 7b 22 64 69 72 65 63 {"motor":{"direc
0040 74 69 6f 6e 22 3a 22 6e 65 75 74 72 61 6c 22 2c tion":"neutral",
0050 22 73 70 65 65 64 22 3a 30 2c 22 74 69 6d 65 22 "speed":0,"time"
0060 3a 30 7d 2c 22 69 70 22 3a 22 31 39 32 2e 31 36 :0},"ip":"192.16
0070 38 2e 30 2e 31 30 30 22 7d 8.0.100"}
I am reading packets at approximatly 10 packets / seconds. (but from test, the number of packets do not modify the accuracy)
Here is the code that read the packets :
bool haveUdpData() {
// if there's data available, read a packet
int packetSize = Udp.parsePacket(); //take 4 milliseconds maximum
if (packetSize) {
// read the packet into packetBufffer
int len = Udp.read(packetBuffer, 512);
if (len > 0) {
packetBuffer[len] = 0;
}
String dataReceived = String(packetBuffer);
Serial.println(dataReceived);
if (dataReceived.length() != packetSize) {
////Serial.print("Incorrect data received :");
}
else {
lastServerCommand = dataReceived;
////Serial.print("Last correct server command :");
}
return true;
}
return false;
}
If you check the image attached you will see that what is printed in the console is random. I am going from almost 100% accuracy to bad accuracy (like the attached image) where only one read is complet.
I think the first 32 chars are always accurate (ROORD|{"motor":{"direction":"neu) then it get random..
Any suggestion?
Also why am I geting sometimes:
1 - blank line
2 - +IPD,3,79,192.168.0.100,4445
3 - +IPD,3,79,192.168.0.100,4445:ROORD|{"motor":{
Rather than just the data?
Other specs :
- Running a 1000 capacitor close to the esp.
- Running a 700 milli_amp power supply for the arduino/esp8266/servo/distance sensor/proximity sensor; powered by a 12 volts lipo battery
- Dropping the voltage from the Arduino serial pin to 3.3v with resistor.
- Car motors are running from another battery.
For my test, the Arduino is connected directly to the computer, not the powersupply.
Libraries used :
#include <Servo.h>
#include <WiFiEsp.h>
#include <WiFiEspUdp.h>
#include <Metro.h>
#include <ArduinoJson.h>
Thank you very much!