I have produced a simple project that has buttons on all the digital inputs and output a UDP command depending on which button was pressed. I have this working but the command Stop coming out after I have sent 8 command until I either reconnect to the cloud or leave it for about 5 mins and it does an auto sync with the cloud.
I have tried it not connected to the cloud and i can only get it to send out once. I would like it not to be connected to the cloud as some of the projects i am going to use this on do not have internet access.
Code i am using
//UDP Setup
byte ipAddress[] = { 192, 168, 0, 61};
UDP Udp;
// Button setup
int W1A = 0; //white 1
int W1B = 0; //white 1 CONTROL
void setup() {
//Pin Setup.
pinMode(D0, INPUT_PULLUP);
pinMode(D1, INPUT_PULLUP);
//UDP Setup
Udp.begin(1024);
Udp.beginPacket(ipAddress, 1024);
Udp.write("Connected\r\n");
Udp.endPacket();
Spark.disconnect();
}
void loop() {
// Button setup
W1A = digitalRead(D0); //white 1
if (W1A == LOW){
if (W1B == 0){
W1B = 1;
Udp.begin(1024);
Udp.beginPacket(ipAddress, 1024);
Udp.write("WHITE1\r\n");
Udp.endPacket();
}
}
else if (SLO == LOW){
if (Spark.connected() == false){
Spark.connect();
}
else {Spark.disconnect();
}
}
else {
W1B = 0;}
}
Hope someone can help me solve this problem.