I'm currently working on an arduino project. Were the arduino is communicating with a NodeJS server via web sockets.
The socket connection is working fine and has no problems. But the problem I currently have is that I want to be able interupt an infinite while loop with a socket emit from the NodeJS server.
I found a page that had a solution for this problem but only with a button attached to the arduino.
Link to page (Interrupt with button)
This is the loop I want to be able to interrupt with a socket:
bool loopRunning = true;
void rainbow(int wait) {
while(loopRunning == true) {
for(long firstPixelHue = 0; firstPixelHue < 3*65536; firstPixelHue += 256) {
for(int i=0; i<strip.numPixels(); i++) {
int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));
}
strip.show();
delay(wait);
}
}
}
I want to set loopRunning to false when I recieve a socket emit.
Anyone have any ides how I can implement this?
It seems there are two main functions you need to use:
SocketIoClient::on(event, callback)
- bind an event to a functionSocketIoClient::loop()
- process the websocket and get any incoming eventsI can't test this easily, but based on the documentation it seems like something like this should work: