Skip to content

fr33r4ng3r/ArduinoWebsocketClient

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ArduinoWebsocketClient, an Arduino client for connecting and messaging with Websockets

Blog: World Domination Using Arduinos And Websockets Blog: Smart Phone Powered Home Automation using Websockets and Amazon EC2

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.

UPDATE: RFC 6544 support is improving. Sec-Websocket-Key + Sec-Websocket-Protocol are now supported. Also, the client will re-establish lost connections.

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.onMessage(onMessage);
  client.send("Hello World!");
}

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

void onMessage(WebSocketClient client, char* message) {
  Serial.print("Received: ");
  Serial.println(message);
}

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.

About

Websocket client for Arduino

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C++ 58.0%
  • Objective-C 23.8%
  • C 14.6%
  • Other 3.6%