Socket.io 在循环arduino中接收套接字(用套接字中断while循环)

Socket.io 在循环arduino中接收套接字(用套接字中断while循环),socket.io,interrupt,nodemcu,neopixel,Socket.io,Interrupt,Nodemcu,Neopixel,我目前正在做一个arduino项目。arduino正在通过web套接字与NodeJS服务器通信 插座连接工作正常,没有问题。但我目前的问题是,我希望能够使用NodeJS服务器发出的套接字中断无限while循环 我找到了一个解决这个问题的页面,但只在arduino上附加了一个按钮 这是我希望能够用套接字中断的循环: bool loopRunning = true; void rainbow(int wait) { while(loopRunning == true) { for(

我目前正在做一个arduino项目。arduino正在通过web套接字与NodeJS服务器通信

插座连接工作正常,没有问题。但我目前的问题是,我希望能够使用NodeJS服务器发出的套接字中断无限while循环

我找到了一个解决这个问题的页面,但只在arduino上附加了一个按钮

这是我希望能够用套接字中断的循环:

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);  
      }
    }
}
bool loopRunning=true;
虚空彩虹(整数等待){
while(loopRunning==true){
用于(长firstPixelHue=0;firstPixelHue<3*65536;firstPixelHue+=256){

对于(int i=0;i而言,您似乎需要使用两个主要函数:

  • SocketIoClient::on(事件,回调)
    -将事件绑定到函数
  • SocketIoClient::loop()
    -处理websocket并获取任何传入事件
我无法轻松地测试这一点,但根据文档,类似这样的东西似乎应该可以工作:

bool loopRunning = true;
SocketIoClient webSocket;

void handleEvent(const char* payload, size_t length) {
  loopRunning = false;
}

void setup() {
  // ...
  // general setup code
  // ...

  webSocket.on("event", handleEvent); // call handleEvent when an event named "event" occurs
  webSocket.begin(/* ... whatever ... */);
}

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();
      webSocket.loop(); // process any incoming websocket events
      delay(wait);
    }
  }
}
bool loopRunning=true;
SocketIoClient-webSocket;
无效handleEvent(常量字符*有效负载,大小和长度){
loopRunning=false;
}
无效设置(){
// ...
//一般设置代码
// ...
on(“event”,handleEvent);//在发生名为“event”的事件时调用handleEvent
webSocket.begin(/*…随便…*/);
}
虚空彩虹(整数等待){
while(loopRunning==true){
用于(长firstPixelHue=0;firstPixelHue<3*65536;firstPixelHue+=256){

for(int i=0;iI)已经使用了您提到的两个主要函数。问题是,当调用while循环时,我无法再接收来自服务器的传入套接字。@RobinFors,代码的主要添加内容是while中的
webSocket.loop();
loop@RobinFors如果您的代码已经包含了这些函数的使用(您共享的代码中没有
webSocket.loop()
)并且仍然不起作用,请共享整个相关的代码段。我试着按照您说的做了,但仍然没有成功,当循环get被调用时,我无法再接收套接字。@Michelleletilley我们仍然无法从服务器获得任何套接字发射。