morrissinger / esp8266-websocket Goto Github PK
View Code? Open in Web Editor NEWThis project forked from brandenhall/arduino-websocket
A websocket library for the ESP-8266.
This project forked from brandenhall/arduino-websocket
A websocket library for the ESP-8266.
Hi @morrissinger . what changes should make customer code example WebSocketClient_Demo.ino to enable or disable a GPIO in Websocketserver module with a given order from other websocketclient module?
Hi,
With DEBUGGING on, I get as far
"Sending websocket upgrade headers"
The following Headers take ~30 seconds each
Then goes into an extremely long loop "Waiting...".
Then:
Invalid handshake
Terminating socket
Handshake failed.
Soft WDT reset
Have I overlooked anything?
Thanks,
Nic
I am try this library with Arduino IDE for ESP8266 and compile WebSocketServer_DEMO.ino programme and i got a
WebSocketServer_Demo:72: error: no matching function for call to 'WiFlyDevice::sendCommand(const __FlashStringHelper*)'
WiFly.sendCommand(F("set wlan auth 1"));
can you suggest the solution's.
Hi.
Thank you for implementing this websocket library.
After running the Demo project I noticed my handshake was failing.
I noticed when comparing the serverKey with b64Result it returns false.
I printed the strings to the console and got:
serverKey: T+3dNVZmHv6jbhlNJr0Qgko9WDQ=
b64Result: MxsNxX0E23KLqFNKO79uD0Gjotg=
this is the part of the code that is returning false WebSocketClient::analyzeRequest()
Serial.println("serverKey: " + serverKey);
Serial.println("b64Result: " + String(b64Result));
// if the keys match, good to go
return serverKey.equals(String(b64Result));
I appreciate any help.
Thank you
My understanding is that I upload the sketch onto my ESP8266 board, keeping in mind that the SSID and PWD has to be changed. After that procedure I upload only the .htlm file containing the JS script, and as I understand - it it possible to control my ESP pins via my website ?
Second thing is that I already have some sketch, but the whole procedure is based on reading the JSON file in specified time intervals (dictated i presume by so to speak the overall refresh rate of ESP board). But after clicking a button on my website, the ESP module has to parse data and change the state of pins accordingly -- but that alone takes at least 2 seconds and the whole website has to reload because the PHP has to open-write-save JSON file.
Is your way faster ?
I had some experience with socket.io and NODE.js, and I can tell that the communication between client and server was almost instant - is this the case if I were to use your method ?
Thank You.
I was able to get this working as a server with some small changes to sendEncodedData(). I was getting SLOWWW speeds (like 2 seconds/msg for small sizes and 20 seconds/msg for 100-bytes). Changing the write() loop to a single print() fixed this (now getting about 1.6 messages/sec).
//for (int i=0; i<size; ++i) {
// socket_client->write(str[i]);
//}
socket_client->print(str);
I tried doing longer ones but got protocol errors for length > 125. There's another small change in sendEncodedData().
socket_client->write((uint8_t) (size & 0xFF)); // was &&
Now getting about 1/sec at 1000 bytes and .8/sec at 2500 bytes. At 4000 bytes the poor little bugger choked.
Sometimes , due to I think unreliable connection socket seems to hang on this loop:
I got firstly an error in parsing object , then everything hangs on :
while ((socket_client->connected() && !socket_client->available())) {
delay(100);
Serial.println("Waiting..." );
}
got an infinite Waiting loop. This happens randomly but when it hangs it's sketch end as it never go out from loop. it would not be better to have a timeout on this?
Hi. I'm using ESP8266 07 and run WebSocketClient_Demo.ino but after socket connects got handshake failed error.
my server which i try to connect is http://198.143.180.203:3000/
I would appreciate any help
Hi, I program the nodeMCU as my websocketclient, and send humidity and temperature data to the websocket server, for the first 5 times, the program update the data to the server successfully, but for the 6th time to send data, seemly the program is dead, this is no other information printed on the serial terminal. I have no idea what had happened. I am sure the server is OK, and the following is the information of the sketch.
Sketch uses 235,746 bytes (22%) of program storage space. Maximum is 1,044,464 bytes.
Global variables use 32,624 bytes (39%) of dynamic memory, leaving 49,296 bytes for local variables. Maximum is 81,920 bytes.
void loop() {
h = h + 1 ; //just for test
t = t + 0.5; //just for test
if (client.connected())
{
String postStr ="{";
postStr +="\"action\":\"update\",";
postStr +="\"apikey\":\"";
postStr += apikey;
postStr +="\",";
postStr +="\"deviceid\":\"";
postStr += deviceID;
postStr +="\",";
postStr += "\"params\":";
postStr += "{";
postStr += "\"humidity\":\"";
postStr += String(h);
postStr +="\",";
postStr += "\"temperature\":\"";
postStr += String(t);
postStr +="\"";
postStr +="}";
postStr +="}";
webSocketClient.sendData(postStr);
Serial.println("Update data");
Serial.print("humidity: ");
Serial.println(h);
} else {
Serial.println("Client disconnected.");
while (1) {
// Hang on disconnected
}
}
// wait to fully let the client disconnect
delay(20000);
}
Hi I am facing this error. Can someone tell me where to get the ESP8266WiFi.h file from. I don't see it in my libraries folder.
Where can I find the libraries of SC16IS750.h and WiFly.h ?
Dear morrissinger,
I have some issue with yout websocket client part. I try with example as you defined and i have the following message on the serial port:
Connecting to NUMERICABLE-A8B3
.........
WiFi connected
IP address:
192.168.0.22
Connection failed.
ctx: cont
sp: 3ffea780 end: 3ffea960 offset: 01b0
stack>>>
3ffea930: 3ffe8f88 1600a8c0 00000000 00000000
3ffea940: 3fffdc20 00000000 3ffea984 40201863
3ffea950: 00000000 00000000 3ffe9940 40100db4
▒▒▒▒L▒<1▒▒▒
I modify the different information and try to connect to my own websocket server and i have the following message:
Connecting to NUMERICABLE-A8B3
...........
WiFi connected
IP address:
192.168.0.22
Connected
Client connected
Sending websocket upgrade headers
Analyzing response headers
Invalid ANALYSE REQUEST
Terminating socket
Handshake failed.
I also test my server with the websocket echo online client and it worked. But with your client it does not work It seems that the client nerver received data from the handshake.
Did you have a client example that works?
Any reason why connection would fail when connecting to echo.websocket.org (just like the demo file)?
Hello,
Thanks for making this. I'm very new to the arduino world, have been reading on several websites about using using esp8266 and websockets. I'm hoping someone can help me, After uploading my sketch to the esp8266, I was wondering how do you set up the esp8266 to the serial monitor in the arduino IDE so I can hopefully see what's coming through. Presently I just show a blue light coming off of the esp8266, but I need sometype of monitor to see how what text is spitting out. Thanks in advance...
Hey,
I'm using this library to listen to a websocket in client mode. I'm trying to control a led stip with the esp8266 module. Everything works fine, but after some time the socket doesn't get the data from the server. Is there a way to reset the controller if socket connection is lost?
Thanks in advance :)
My code:
#include <ESP8266WiFi.h>
#include <WebSocketClient.h>
#include <DNSServer.h> //Local DNS Server used for redirecting all requests to the configuration portal
#include <ESP8266WebServer.h> //Local WebServer used to serve the configuration portal
#include <WiFiManager.h> //https://github.com/tzapu/WiFiManager WiFi Configuration Magic
char path[] = "/";
char host[] = "foo.bar";
int port = 9000;
WebSocketClient webSocketClient;
WiFiClient client;
void setup() {
Serial.begin(115200);
WiFiManager wifiManager;
//wifiManager.resetSettings();
//Initial LED settings
delay(10);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
digitalWrite(12,HIGH);
digitalWrite(13,LOW);
delay(400);
digitalWrite(12,LOW);
//try to connect to Wifi Access Point or create a hotspot if no suitable network found
//first parameter is name of access point, second is the password
wifiManager.autoConnect("MyWiFi", "myPassphrase");
delay(1000);
// Connect to the websocket server
if (client.connect(host, port)) {
Serial.println("Connected");
} else {
Serial.println("Connection failed.");
while(1) {
// Hang on failure
}
}
// Handshake with the server
webSocketClient.path = path;
webSocketClient.host = host;
if (webSocketClient.handshake(client)) {
Serial.println("Handshake successful");
digitalWrite(12,HIGH);
} else {
Serial.println("Handshake failed.");
while(1) {
// Hang on failure
}
}
}
void loop() {
String data;
if (client.connected()) {
Serial.println("Try to get data...");
webSocketClient.getData(data);
if (data.length() > 0) {
Serial.print("Received data: ");
Serial.println(data);
if(data=="open") //keyword to switch on the LED strip
digitalWrite(13,HIGH);
else //keyword to switch off the LED strip
digitalWrite(13,LOW);
}
} else {
Serial.println("Client disconnected.");
while (1) {
// Hang on disconnect.
}
}
// wait to fully let the client disconnect
delay(2000);
}
Trying to make it work on ESP32 by following this tutorial but unable to make it compile its showing this error 'WebSocketClient' does not name a type
I have written a websocket code on Nodemcu 1.0 /0.9 veraion using aurdino ide and made an app ( websocket client )which connects to the websocket server on the nodemcu .It used to work, but now I am experiencing some problem.
Logs : Connection opened to ws://192.168.4.1
ECHO: successful connection
and then it auto disconnects after less than a sec
Error : saying this Close : CONNECTION_LOST, websocket connection lost
then the same thing repeats when I try to connect again
can u suggest me what the issue behind this even i tried on serial monitor / htm;l webpage same issue i am facing please suggest me how to debug this issue ??
whats wrong why its showing connection lost after a sec only when connected to client . Below u can see the attachment of code this code i flashed on Nodemcu esp8266 12-E dev board and facing this issue .
I hope u got my point . If any query ask me but try to give me suggestion how to resolve it ??
As per I know issue in code only but I am not able to debug suggest me Please !!!!!!!!!!!!!!
Is it possible to run this on a cactus rec 2 with an atmega32u4?
This error shows up and I'm not sure how to fix it:
/libraries/ESP8266-Websocket-master/MD5.h:25:3: error: 'UINT4' does not name a type
UINT4 state[4]; /* state (ABCD) */
^
Hey there,
Thanks so much for your work on this. I'm getting the following message in my serial console when trying to run the demo, seems like it's connecting but then crashing shortly after? Log is as follows:
Connecting to ****
...
WiFi connected
IP address:
10.10.10.106
Connected
Waiting...
H�
anyone can run client demo?
i tested with arduino 1.8.1 and esp8266, but not run.
I have create a Android App(WS Client) which I use Autobahn Library. In ESP8266(NodeMCU) I have the WebSocket Server with library arduinoWebSockets. My problem is when I am connected to the AP and then close the Wifi and disconnect from access point in Android the ESP don't recognize the disconnect.
Why this can happen ?
Thanks!
Hi, this is very interesting websocket client. It is working when connecting to echo.websocket.org but if change host url to my url and copy the same echo.websocket into index.html it does not work. Any help would be appreciated.
I couldn't compile even the library example
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.