Git Product home page Git Product logo

socket.io-arduino-client's Introduction

SocketIO Arduino Client, an Arduino client for connecting and messaging with Socket.io servers

Based on Kevin Rohling's arduino websocket client modified to work with socket.io servers. Along the way, all uses of the String class were replaced with fixed char buffers so as to use less memory.

The bitlashsocketio.ino example provides an integration with Bitlash on the Arduino and a node.js example server that can be used to send Bitlash commands over the Websocket fabric to the Arduino, and see its output in reply.

Example setup

You'll need node.js and npm installed first.

cd examples/bitlashsocketio
npm install             // only need this once, the first time
node index.js           // start web server.  optionally add --port=8080 to change port

========================================================

======================================================== Kevin's documentation is reproduced hereinafter, with changes as needed.

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

Clone this repo 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 SocketIOClient.

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, char *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.

socket.io-arduino-client's People

Contributors

billroy 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

socket.io-arduino-client's Issues

Weird encoding issue on Serial Monitor

Hi,

When I open the serial monitor to see the commands send to the Arduino it looks like this:

ú�à­ì�ÕؼÀþûóÆððáñðñûûûðüðûñððûññðñðñüüñðüñððñððñððñûððñüüññññáñüñððáøððððüûñññðñññðáûñûðüûðñðûûñûøññðûñáðÿðððûñûðá

What could this be caused? Wrong encoding on either side perhaps?

How do I relay what the arduino sent to SocketIO back to other connected browsers

Bill,

Thank you so much for making this Arduino/SockIO code.

I can see the Arduino is sending data to my socketIO server in my mac osx
terminal window (see attached screen shot) but I'm having trouble figuring out how to then get my server to relay it back out to the other connected browsers?

I'm guessing the syntax or something is incorrect on my server code:

//Server

io.sockets.on('connection', function (socket) {
socket.send("Hi from Server");
socket.on('message', function (data) {
socket.send(data);
});
});

//And here's my Client code

var socket = io.connect('http://10.0.1.3:80');

socket.on('message', function (data) {
$('#measurementlabel').html(data);
});

I appreciate any help you can offer in figuring it out. Hopefully it's something simple that I've missed.

Thanks,

Drew

variable emit

How can ı emit variable data in json format.
I cant do it.

Not able to connect

Even though I could fix the couple bugs on the compilation, it seems there is an error ocurring on the connection.
I have sniffed my connection using wireshark, sending a message to a server in my computer, and there really is some sort of problem in the handshake. The package is sent by the client and received by the host, by the connection with the server is never established.
Was anyone able to make it work?

Subject: Arduino Yun and node.js, a good read

Subject: Arduino Yun and node.js, a good read

After spending 2 weeks working through lots of challanges with Arduino Yun and Node.js, I put together a massive article with lots of source code to cover in depth Arduino Yun and Node.js.

I also provide a pre-built binary image that you can bun onto your own Micro SD (instruction included) for the perfect Yun / Node.js setup.

I developed a serial Watchdog (for when serial bridge doesn't connect), socket.io client using binary ws for the Yun, figured our node.js live remote debug and more...

I just had too many good things to not share it with everyone, so here it is, ENJOY and please comment:

https://github.com/born2net/mediaArduino

(PS sorry that has to open an issue, but no other way to post on GitHub).

I can't reconnect to my server after my server crushed.

I have saw the code in monitor function.

if (!client.connected()) {

            // I print the connect result here
    Serial.print(client.connect(hostname,port));

    if (!client.connect(hostname, port)) return;
}

When my server crushed, it start to connect again. After i restart my server, it always return 0. It can't reconnected to server.

Then delete the monitor ,and test by this codes

if(!client.connected()){
    Serial.print("Reconnecting```");
    if(client.connect(hostname,port))
      Serial.print("Connected");

      Serial.print("\n");
  }else{
    Serial.print("Available \n");
  }
  delay(1000);

I still can't reconnect to my server.

Please help me ! Thanks a lot .

My server code:

var io  = require('socket.io').listen(8686);
io.sockets.on("connection",function(socket){
    socket.send("Socket Connected...");

    socket.on("message",function(message,callback){
        socket.broadcast.emit(message);
        console.log(message);
    });

});

Best way to keep connection alive?

Thanks for making this awesome library available. I've successfully used it in a socket.io-powered Window Air Conditioner Remote, but am curious if anyone knows a good way to deal with interrupted connections.

Basically, what's the best way to have an arduino check it's connection periodically and reconnect if it is not connected?

GSM Connectivity

Bill
I have used Socket.io with the Ethernet shield connected to a GSM Router for outdoors connectivity. I had a issue with not detecting a re-connection because of the LAN network of the GSM Router. I solved using a ICMPPing library every 15 seconds. If that gave me 5 timeouts on a row, I disconnect the client and wait for an alive ping from the server.

Because of the lack of space of my proyect, I need to attach directly, instead of the Ethernet shield, a GSM Shield (I have got one with a SIM 900 modulo on it.

The problem resides, that the methods and properties of the Ethernet Shield are not the same than the GSM Shield. Have you tried before with an GSM Shield your library? or are there any approaches that I need to now in order to configure the socket against a GSM Shield?

THe GSM Shield is the GSM/GPRS/GPS Shield of Futura/Open-electronics
The GSM Shield library is at: https://code.google.com/p/gsm-shield-arduino/

Thanks in advance
Felipe Brito

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.