Hi, i was working on a program for a while then i stopeed for a few weeks. now i forget what im suppose to do, i have 2 pieces of code and everything work except when i use the memcpy command. I'm going to assume the delimiters in the received bytes is causing my issue. i have 7 bytes to the beginning and end of the message i send with the esp8266.
this code sends the message
struct packet {
int local;
float temp;
};
packet localData;
if (millis() - now >= 300) {
now = millis();
const char delimiter[] = "NODE01";
const char delimiter2[] = "01NODE";
Serial.println("sent");
Udp.beginPacket(Server, ServerPort);
Udp.write((const uint8_t *)delimiter, sizeof(delimiter) - 1);
Udp.write((const uint8_t *)&localData, sizeof(localData));
Udp.write((const uint8_t *)delimiter2, sizeof(delimiter2) - 1);
//Udp.write((char*)&buffer, sizeof(buffer));
Udp.endPacket();
digitalWrite(5, HIGH);
}
the code is sending the message properly i think. im receiving the message im sending but i need to seperate the delimiters from the bytes i want to keep.
this is the receiving code,
struct packet {
int local;
float temp;
};
packet localData;
int packetSize = Udp.parsePacket();
if (packetSize)
{
Serial.println("Message");
int len = Udp.read(incomingPacket, 800);
char verifyStart[7];
char verifyEnd[7];
Serial.println((char*)incomingPacket);
strncpy (verifyStart, (char*)incomingPacket, 7 );
strncpy (verifyEnd, (char *)incomingPacket + len - 6 , 7 );
if (strcmp(verifyStart, "NODE01") == 0) {
if (strcmp(verifyEnd, "01NODE") == 0) {
Serial.println("Node01");
memcpy(&localData, incomingPacket, sizeof(localData));
Serial.print("Tempature is ");
Serial.println(localData.temp);
now = millis();
}
}
i'm getting to the memcpy part but i think im not copying exactly what i want. can someone help me please i need to remove the delimiters from the struct data so i can memcpy it
heres the serial print,
Now listening at IP 192.168.4.1, UDP port 4210
Message
NODE01
Node01
Tempature is 0.00
hello
as you can see its sort of working. im just not copying the right bytes to the structure?