Hi,
Sorry for my English, i will try my best.
I'm trying to activate/deactivate a set of relays using UDP commands, I saw some examples here in the forums, but my project didn't work, this is my code:
void loop() // Start Running System
{
int packetSize = Udp.parsePacket(); // if there's data available, read a packet
if(packetSize)
{
int read = Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE); // read the packet into packetBufffer
packetBuffer[read] = 0;
char ch1 = packetBuffer[0];
char ch2 = packetBuffer[1];
char ch[] = { packetBuffer[0], packetBuffer[1], '\0'};
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
Udp.write(ch);
// Udp.write(ch1);
// Udp.write(ch2);
Udp.endPacket();
if (ch == "10")
{
digitalWrite(PinA, HIGH);
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
Udp.write("hello");
Udp.endPacket();
}
else if (ch == "11") {
digitalWrite(PinA, LOW);
}
else if (ch == "20") {
digitalWrite(PinB, HIGH);
}
else if (ch == "21") {
digitalWrite(PinB, LOW);
}
else if (ch == "30") {
digitalWrite(PinC, HIGH);
}
else if (ch == "31") {
digitalWrite(PinC, LOW);
}
else if (ch == "40") {
digitalWrite(PinD, HIGH);
}
else if (ch == "41") {
digitalWrite(PinD, LOW);
}
else if (ch == "50") {
digitalWrite(PinE, HIGH);
}
else if (ch == "51") {
digitalWrite(PinE, LOW);
}
else if (ch == "60") {
digitalWrite(PinF, HIGH);
}
else if (ch == "61") {
digitalWrite(PinF, LOW);
}
else
Serial.print("No Case Found for: ");
Serial.print(ch);
for (int x = 0; x < 8; x++){
digitalWrite(x, HIGH);
}
}
delay(15); // waits 15ms for udp input wait ...
} // end system run, but now loop and start system run again
Is only the loop, as you can see.
My ability programming is low.
The UDP response is only to see what is stored in the variables, the response shows the correct values. With a little trial and error I get the correct values in the UDP and nothing else, but it never do the if actions.
My board is an ARDUINO compatible and HIGH-LOW works inverse in this case.
Thanks for you help.