GithubHelp home page GithubHelp logo

arduinowebsocketclient's Introduction

ArduinoWebsocketClient, an Arduino client for connecting and messaging with Websockets

Blog: World Domination Using Arduinos And Websockets

Websockets currently provide a simple and lightweight way to send and receive messages from web browsers. This project was developed to extend this capability to embedded devices (Arduinos). It is my hope that allowing devices to easily send information about themselves as well as respond to messages received from hosted services will result in some interesting applications.

Caveats

This library doesn't support every inch of the Websocket spec, most notably the use of a Sec-Websocket-Key. Also, because Arduino doesn't support SSL, this library also doesn't support the use of Websockets over https. If you're interested in learning more about the Websocket spec I recommend checking out the Wikipedia Page. Now that I've got that out of the way, I've been able to successfully use this to connect to several hosted Websocket services, including: echo.websocket.org and pusherapp.com.

Installation instructions

Once you've cloned this repo locally, copy the ArduinoWebsocketClient directory into your Arduino Sketchbook directory under Libraries then restart the Arduino IDE so that it notices the new library. Now, under File\Examples you should see ArduinoWebsocketClient. To use the library in your app, select Sketch\Import Library\ArduinoWebsocketClient.

How To Use This Library

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
char server[] = "echo.websocket.org";
WebSocketClient client;

void setup() {
  Serial.begin(9600);
  Ethernet.begin(mac);
  client.connect(server);
  client.setDataArrivedDelegate(dataArrived);
  client.send("Hello World!");
}

void loop() {
  client.monitor();
}

void dataArrived(WebSocketClient client, String data) {
  Serial.println("Data Arrived: " + data);
}

Examples

There example included with this library, EchoExample, will connect to echo.websocket.org, which hosts a service that simply echos any messages that you send it via Websocket. This example sends the message "Hello World!". If the example runs correctly, the Arduino will receive this same message back over the Websocket and print it via Serial.println.

arduinowebsocketclient's People

Contributors

krohling avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

arduinowebsocketclient's Issues

Arduino websocket client and personal websocket server

Hello Krohling,

Thanks for sharing your code, it's very helpfull !!

However I've a issue when I tried to connect the Arduino to my own websocket echo server: nothing append.

I have change the line:

client.connect(server); => client.connect(server,"/",9000);

But It didn't works.

I have test my echo Server with the websocket.org client and it works....

Any ideas ? Should I modify the request Header into the ccp file ?

Thanks again.

vlp

RFC 6455

Any chance of updating the web socket protocol to the latest version? (http://tools.ietf.org/html/rfc6455)

I've been able to fix most of the issues besides message encoding when sending messages.

Thanks for the great work!

Please add support for ESP8266

I'm using this add-on for the Arduino IDE: https://github.com/esp8266/Arduino since the ESP8266 is an absolute jewel for IoT devices. But I'm getting a ton of warnings and the app crashes when I replace EthernetClient with WiFiClient in your code and robot example although it will compile.

Thanx!

jeroen

Hi, just requesting bit of help

HI, i think so far this is great, butn unfortunatly im having a bit of trouble getting it to work on my own server.

I have a simple echo server setup using node and this websocket :
https://github.com/Worlize/WebSocket-Node

A html client works great and the same client connects and works to echo.websocket.org fine.

But the arduino wont connect to my server, but does to echo.websocket.org.

So i can only assume this is down to protocol version or the headers. I blive the protocol i require is 8 or 13, which i belive all html browsers use at the moment.

Can this be change to support these protocols? Or could you let me into any information where i might be able to impliment them, even though my C++ skills arent to good.

Would be much appriciated if it was update.

Note: Also how did you get it working with pusher, as you pusher clients you have to include thier js framework?

Many thanks
Andy

Help please! can't connect to my java websocket server

Hi, I have a java websocket server with multiple websocket endpoints, each one with a specific location in LAN. example:

http://[my local ip]:[port]/myJavaApp/webSocket1
http://[my local ip]:[port]/myJavaApp/webSocket2
http://[my local ip]:[port]/myJavaApp/webSocket3 etc..

The example sketch is working fine with "echo.websocket.org", but I just cant connect to my websocket server endpoints.

That's what I'm trying...

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
char server[] = "[my local ip]:[port]/myJavaApp/webSocket1";
WebSocketClient client;

void setup() {
Serial.begin(9600);
Ethernet.begin(mac);
client.connect(server);
client.setDataArrivedDelegate(dataArrived);
client.send("Hello World!");
}

void loop() {
client.monitor();
}

void dataArrived(WebSocketClient client, String data) {
Serial.println("Data Arrived: " + data);
}

Also I have tried with client.connect(server,port); but I don't know how to indicate the /myJavaApp/webSocket1 location.

I know my java server is ok because I can use Javascript clients and all is working fine.
I hope you can help me, I think is just about setup.

draft 10 handshake for node.js or tornado socket server?

I am trying to use this library with an ethernet shield to connect to WebSocket Server on my computer. It works with the most recent version of Chrome v16. Any chance of updating this library to support that? I ran the example and it did connect to echo.websockets.org, but I am guessing they are supporting really old prototcols.

When I try and connect to "10.1.2.10:8888/chatsocket" it hangs for a while then says not connected

Can't compile example

Using Arduino 1.6.0 and it won't compile. Error log below:
Arduino: 1.6.0 (Windows 7), Board: "Arduino Uno"

Build options changed, rebuilding all

C:\Users\Matt\Documents\Arduino\libraries\ArduinoWebsocketClient-master\WebSocketClient.cpp:30:1: error: 'prog_char' does not name a type
prog_char stringVar[] PROGMEM = "{0}";
^
C:\Users\Matt\Documents\Arduino\libraries\ArduinoWebsocketClient-master\WebSocketClient.cpp:31:1: error: 'prog_char' does not name a type
prog_char clientHandshakeLine1[] PROGMEM = "GET {0} HTTP/1.1";
^
C:\Users\Matt\Documents\Arduino\libraries\ArduinoWebsocketClient-master\WebSocketClient.cpp:32:1: error: 'prog_char' does not name a type
prog_char clientHandshakeLine2[] PROGMEM = "Upgrade: WebSocket";
^
C:\Users\Matt\Documents\Arduino\libraries\ArduinoWebsocketClient-master\WebSocketClient.cpp:33:1: error: 'prog_char' does not name a type
prog_char clientHandshakeLine3[] PROGMEM = "Connection: Upgrade";
^
C:\Users\Matt\Documents\Arduino\libraries\ArduinoWebsocketClient-master\WebSocketClient.cpp:34:1: error: 'prog_char' does not name a type
prog_char clientHandshakeLine4[] PROGMEM = "Host: {0}";
^
C:\Users\Matt\Documents\Arduino\libraries\ArduinoWebsocketClient-master\WebSocketClient.cpp:35:1: error: 'prog_char' does not name a type
prog_char clientHandshakeLine5[] PROGMEM = "Origin: ArduinoWebSocketClient";
^
C:\Users\Matt\Documents\Arduino\libraries\ArduinoWebsocketClient-master\WebSocketClient.cpp:36:1: error: 'prog_char' does not name a type
prog_char serverHandshake[] PROGMEM = "HTTP/1.1 101";
^
C:\Users\Matt\Documents\Arduino\libraries\ArduinoWebsocketClient-master\WebSocketClient.cpp:38:48: error: variable 'WebSocketClientStringTable' must be const in order to be put into read-only section by means of 'attribute((progmem))'
PROGMEM const char *WebSocketClientStringTable[] =
^
C:\Users\Matt\Documents\Arduino\libraries\ArduinoWebsocketClient-master\WebSocketClient.cpp:40:5: error: 'stringVar' was not declared in this scope
stringVar,
^
C:\Users\Matt\Documents\Arduino\libraries\ArduinoWebsocketClient-master\WebSocketClient.cpp:41:5: error: 'clientHandshakeLine1' was not declared in this scope
clientHandshakeLine1,
^
C:\Users\Matt\Documents\Arduino\libraries\ArduinoWebsocketClient-master\WebSocketClient.cpp:42:5: error: 'clientHandshakeLine2' was not declared in this scope
clientHandshakeLine2,
^
C:\Users\Matt\Documents\Arduino\libraries\ArduinoWebsocketClient-master\WebSocketClient.cpp:43:5: error: 'clientHandshakeLine3' was not declared in this scope
clientHandshakeLine3,
^
C:\Users\Matt\Documents\Arduino\libraries\ArduinoWebsocketClient-master\WebSocketClient.cpp:44:5: error: 'clientHandshakeLine4' was not declared in this scope
clientHandshakeLine4,
^
C:\Users\Matt\Documents\Arduino\libraries\ArduinoWebsocketClient-master\WebSocketClient.cpp:45:5: error: 'clientHandshakeLine5' was not declared in this scope
clientHandshakeLine5,
^
C:\Users\Matt\Documents\Arduino\libraries\ArduinoWebsocketClient-master\WebSocketClient.cpp:46:5: error: 'serverHandshake' was not declared in this scope
serverHandshake
^
Error compiling.

This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.

Sec-WebSocket-Key Error

While using your library I've never been able to get a successful response from the echo.websocket.org server. So, I added a Serial.print on the handshake section to debug the error and I got the following:

HTTP/1.1 400 Bad Request
Server: Kaazing Gateway
Date: Tue, 07 May 2013 05:11:21 GMT
Access-Control-Allow-Origin: ArduinoWebSocketClient
Access-Control-Allow-Credentials: true
Access-Control-Allow-Headers: content-type
Access-Control-Allow-Headers: authorization
Access-Control-Allow-Headers: x-websocket-extensions
Access-Control-Allow-Headers: x-websocket-version
Access-Control-Allow-Headers: x-websocket-protocol
Content-Type: text/html
Content-Length: 63
Connection: Keep-Alive

Then, I tested it with a Node websocket server I created and got the following:

HTTP/1.1 400 Bad Request
Connection: close
X-WebSocket-Reject-Reason: Client must provide a value for Sec-WebSocket-Key.

Am I doing something wrong or does the library need to be updated?

Regards and Thanks a lot!!

Node JS socket client support?

I've attempted to use this library to connect to a local node js socket io server with no luck. Do you have any recommendations for a compatible local server?

NOT CONNECTING

client.connect() function in echo example was not functioning properly earlier. but did suddenly. still sometimes it connects, sometimes it doesn't cant figure out why.
PS: i am using the ide 1.6.5 . Does it make a difference?

Connect to a specific port

Nice project indeed!

I have been trying to figure out how to connect to a specific port in a websocket server.
Currently I do have a WS server with the echo sketch running on my LAN, the WS is open on port :1234

With Arduino ethernet shields in client mode there is this line:

client.connect(server, 80)

I have tried the same with your WS client but does not work

Ethernet.begin(mac, ip);
client.connect(server, 1234);
client.setDataArrivedDelegate(dataArrived);
client.send("Hello World!");

Thanks in advanced for the help or hints you can provide me in order to solve it.

yOPERO

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.