You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am testing WebSocketClient.ino on Adafruit HUZZAH ESP8266 breakout using node webSocketServer. I modified WebSocketClient.ino to add input interrupt from push button which sends a text message. First message works and then it disconnects.
Here is the code:
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <WebSocketsClient.h>
#include <Hash.h>
ESP8266WiFiMulti WiFiMulti;
WebSocketsClient webSocket;
void webSocketEvent(WStype_t type, uint8_t * payload, size_t lenght) {
switch(type) {
case WStype_DISCONNECTED:
Serial.printf("[WSc] Disconnected!\n");
break;
case WStype_CONNECTED:
{
Serial.printf("[WSc] Connected to url: %s\n", payload);
// send message to server when Connected
webSocket.sendTXT("Connected");
}
break;
case WStype_TEXT:
Serial.printf("[WSc] get text: %s\n", payload);
// send message to server
// webSocket.sendTXT("message here");
break;
case WStype_BIN:
Serial.printf("[WSc] get binary lenght: %u\n", lenght);
hexdump(payload, lenght);
// send data to server
// webSocket.sendBIN(payload, lenght);
break;
}
}
void inputChanged() {
Serial.printf("inputChanged\n");
webSocket.sendTXT("inputChanged");
}
void setup() {
Serial.begin(115200);
Serial.setDebugOutput(true);
for(uint8_t t = 4; t > 0; t--) {
Serial.printf("[SETUP] BOOT WAIT %d...\n", t);
Serial.flush();
delay(1000);
}
WiFiMulti.addAP("KWN", "xxxxxxxx");
//WiFi.disconnect();
while(WiFiMulti.run() != WL_CONNECTED) {
delay(100);
}
webSocket.begin("192.168.0.10", 81);
webSocket.onEvent(webSocketEvent);
pinMode(0, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(0), inputChanged, RISING);
}
void loop() {
webSocket.loop();
}
Thu Dec 17 2015 03:35:57 GMT-0600 (Central Standard Time) Connection accepted.
Received Message: Connected
Received Message: inputChanged
Thu Dec 17 2015 03:37:25 GMT-0600 (Central Standard Time) Peer ::ffff:192.168.0.16 disconnected.
sendTXT works fine if i placed it in loop as shown below and it doesn't get disconnected.
void loop() {
webSocket.loop();
static unsigned long last = 0;
if(abs(millis() - last) > 1000) {
webSocket.sendTXT(String(millis()));
last = millis();
}
But if i press the button it disconnects. If i remove the sendTXT from button interrupt handler , connection stays alive.
Any idea what could be causing this issue?
The text was updated successfully, but these errors were encountered:
I am testing WebSocketClient.ino on Adafruit HUZZAH ESP8266 breakout using node webSocketServer. I modified WebSocketClient.ino to add input interrupt from push button which sends a text message. First message works and then it disconnects.
Here is the code:
Here is what i get from serial monitor:
Here is what i see on the server side:
sendTXT works fine if i placed it in loop as shown below and it doesn't get disconnected.
But if i press the button it disconnects. If i remove the sendTXT from button interrupt handler , connection stays alive.
Any idea what could be causing this issue?
The text was updated successfully, but these errors were encountered: