Hello. I'm new here and in arduino. Hope you can help me. I'm developing an alarm program in arduino UNO, and an app for iphone to send the password by wifi (socket_datagram, UDP) and compare it with an array called: char password[4]={1,2,3,4} in the arduino. The problem is that when the arduino receives the udpSocket is properly showed in the screen, but when i compare it with the password it does anything, like it was wrong, or if change a bit the comparing method trying an other way, it works allways although the password received is wrong. I don't know how to solve the comparing method. Can someone help me? The code used in the receiving function is:
char password[4]={1,2,3,4}; //password going to be compared
char activ[2]={9,9}; // code to activate alarm
void loop()
{
...
udpReceive(); // call the function to receive udp sockets
...
}
void udpReceive()
{
// if there's data available, read a packet
int packetSize = Udp.parsePacket();
if(packetSize)
{
Serial.print("Received packet of size ");
Serial.println(packetSize);
Serial.print("From ");
IPAddress remote = Udp.remoteIP();
for (int i =0; i < 4; i++)
{
Serial.print(remote*, DEC);*
-
if (i < 3)*
-
{*
-
Serial.print(".");*
-
}*
-
}*
-
Serial.print(", port ");*
-
Serial.println(Udp.remotePort());*
-
// read the packet into packetBufffer*
-
Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE);*
-
Serial.println("Contents:");*
-
Serial.println(packetBuffer);*
-
for(int i=0;i<UDP_TX_PACKET_MAX_SIZE;i++) //comparing*
-
{*
if(packetBuffer_==password*)
{
x=0;
code=1; //password correct to switch off the alarm in loop() functio*
* break;
}
if(packetBuffer==activ)
{
code=0;
x=1; // just to activate the alarm in loop() function*
* break;
}
}
delay(10);
}
}*_