I'm using Energia to program one of TI's MCU. Since Energia is based off the Arduino IDE, I'm hoping someone can help me here.
I'm building a simple UDP packet sender and receiver app. The MCU starts up and connects to the local Wifi network and waits for a packet from another device on the same network.
This packet is collected in a char array char packetBuffer[16];
I want to split this array into two separate arrays each of 8 elements. These are char lampCmdRead[8];
and char pwdReadBuffer[8];
Now the network bit works great. I can send the packet through my desktop and receive it on the MCU. However when I split this array I see that the pwdReadBuffer
shows the same contents as packetBuffer
even though they are of different sizes. How is this possible?
Here is the code:
char packetBuffer[16];
char lampCmdRead[8];
char pwdReadBuffer[8];
// This is code from the 'void loop()' section
int packetSize = Udp.parsePacket();
if(packetSize) {
int len = Udp.read(packetBuffer, 16);
if (len > 0) packetBuffer[len] = 0;
Serial.println();
Serial.println("packetBuffer:");
Serial.println(packetBuffer);
Serial.println();
for(ctr = 0; ctr < 8; ctr++) {
pwdReadBuffer[ctr] = packetBuffer[ctr];
}
if (len > 8) pwdReadBuffer[len] = 0;
for(ctr = 0; ctr < 8; ctr++) {
lampCmdRead[ctr] = packetBuffer[ctr+8];
}
if (len > 8) lampCmdRead[len] = 0;
Serial.println("pwdReadBuffer:");
Serial.println(pwdReadBuffer);
Serial.println();
Serial.println("lampCmdRead:");
Serial.println(lampCmdRead);
Serial.println();
}
And here is the output:
Received packet of size 16
From 192.168.1.101, port 55056
packetBuffer:
2qZ@X51Rredledon
pwdReadBuffer:
2qZ@X51Rredledon
lampCmdRead:
redledon