Dear All,
I'm trying to communicate between two systems using UDP server, the 1st system send a message in this form as example 0024008c0a00000050000000000000000000000000000000000000006400000090010000
the total length is 36 bytes, where byte 0 is 0 always, byte 1 is 36 always, byte 2 is 0 always, byte 4-7 is variable0 the type is INT32, byte 8-11 is variable1 the type is INT32,...., until 32-35 which is the last variable7.
in the message above the value for var1 is 10 , var2 = 80, var6 = 100 and var7 is 400.
but when i use this code to read the UDP packet i got different message .
The code
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#define WIFI_SSID "****"
#define WIFI_PASS ""
#define UDP_PORT 9180
WiFiUDP UDP;
char packet[255];
char reply[] = "Packet received!";
signed long INT0;
signed long INT1;
signed long INT7;
signed long INT6;
void setup() {
Serial.begin(115200);
Serial.println();
WiFi.begin(WIFI_SSID , WIFI_PASS);
Serial.print("Connecting to ");
Serial.print(WIFI_SSID );
Serial.print(WIFI_PASS);
// Loop continuously while WiFi is not connected
while (WiFi.status() != WL_CONNECTED)
{
delay(100);
Serial.print(".");
}
Serial.println();
Serial.print("Connected! IP address: ");
Serial.println(WiFi.localIP());
// Begin listening to UDP port
UDP.begin(UDP_PORT);
Serial.print("Listening on UDP port ");
Serial.println(UDP_PORT);
}
void loop() {
int packetSize = UDP.parsePacket();
if (packetSize) {
Serial.print("Received packet! Size: ");
Serial.println(packetSize);
int len = UDP.read(packet, 255);
if (len > 0)
{
packet[len] = '\0';
}
for (int i = 0; i < packetSize ; i = i + 1) {
// Serial.print(i);
Serial.print(packet[i],HEX);
Serial.println();
// Send return packet
UDP.beginPacket(UDP.remoteIP(), UDP.remotePort());
UDP.write(reply);
UDP.endPacket();
}
I'm getting this message
Received packet! Size: 36
02408CA0005000000000000000000006400090100
I really need some help since i tried so many times to know what causing the issue.