Hello everyone ,
I have a problem in my UDP packet sender i will describe it. first this is the code
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
// Set WiFi credentials
#define WIFI_SSID "DIGI_676df8"
#define WIFI_PASS "aa219892"
#define UDP_PORT 9180
// UDP
WiFiUDP UDP;
char packet[255];
char reply[] = "Packet received!";
char packet_ret[36] = {01,0x24,00,0x1E,06,00,00,00,0x0B,00,00,00,0x10,00,00,00,0x15,00,00,00,0x1A,00,00,00,0x1F,00,00,00,0x24,00,00,00,0x29,00,00,00} ;
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);
while (WiFi.status() != WL_CONNECTED)
{
delay(100);
Serial.print(".");
}
Serial.println();
Serial.print("Connected! IP address: ");
Serial.println(WiFi.localIP());
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';
}
UDP.beginPacket(UDP.remoteIP(), UDP.remotePort());
UDP.write(reply);
UDP.endPacket();
UDP.beginPacket(UDP.remoteIP(), UDP.remotePort());
UDP.write(packet_ret);
UDP.endPacket();
}
}
I'm using Wireshark to monitor the packets , for the 1st reply array it worked perfectly and i can see it in the program
280211 22240.862216 192.168.1.6 192.168.1.2 UDP 58 9180 → 9180 Len=16
the sent data : Packet received!
while for the 2nd reply packet_ret it should be a36 bytes message, but in wireshark i could see that the arduino only sent 2 bytes as following
280212 22240.862610 192.168.1.6 192.168.1.2 UDP 44 9180 → 9180 Len=2
the sent data: only 0124
both arrays type is char, so i couldn't really know why this happen.