Go Down

Topic: Socket.io v1.x Library for W5100 & ENC28J60 + ESP8266 (Read 11920 times) previous topic - next topic


May 02, 2015, 10:11 pm Last Edit: Nov 05, 2015, 11:34 pm by washo4evr
Hi guys,
I've just finished a working lib for Arduino using W5100.
My work is based on Bill Roy's library : https://github.com/billroy/socket.io-arduino-client

Right now, my lib supports Socket.io v1.x and node.js v0.12.2 and arduino 1.6.3
it uses websocket, masking frames as requested with the new version of socket.io

I will set up an account on github and post it soon (just need to clean up a little bit and try to make it work for ENC28j60)

Hope it helps the community

Edit: Added an example to show basic communication with node.js server

Edit 2 : Added GitHub : https://github.com/washo4evr/Socket.io-v1.x-Library

Edit 3 : Successfully tested with Node.JS version 4.1.1 & Socket.IO version 1.3.7

Edit 4 : Initial support for ESP8266 has been added
(something like http://www.banggood.com/NodeMcu-Lua-ESP-12E-WIFI-Development-Board-p-985891.html)


May 04, 2015, 09:59 pm Last Edit: Nov 05, 2015, 10:35 pm by washo4evr

- Merged both libraries into 1 :
You need to edit socketio.h to select the correct chipset (W5100 or ENC28J60)

- Several improvements

- client.send behavior changed : client.send(String RID, String Rname, String Rcontent);
("[RID , {Rname : Rcontent}]")

- Ping & Pong handled


OMG THANK YOU!!!!!!! Seriously, I have been trying on and off for months to get a working arduino socket.io setup going. I have most of the MEAN stack finished for my security system server but couldn't get away from REST for the arduino itself.

I can't believe nobody has commented on this. This has saved my life man. Your code is so simple and easy to understand which is important to me as a beginner/intermediate programmer. When I couldn't get it to work I just skimmed your .cpp and .h and it all made so much sense.

Now my arduino can connect to my server via socket.io and I can arm/disarm my alarm remotely (in a better way than I was before).

This made my day. Nay, my month. Keep working on this and get that git-hub working. People should flock to this, it's so extremely useful.


I did edit your .cpp code a bit though.

So, as you know, the send() function accepts three strings; one for the socket.io ".on" identifier (not sure what its called), one for the key and one for the value. Then it makes an object out of it and sends it off.

I modified it to accept a string that is in JSON format. This way instead of a single key:value pair I can now send an entire object with multiple key:value pairs.

Then in my arduino code I made a quick little function "jsonBuilder". I run it whenever I want to send data over the socket and it constructs a string out of my data and sends it off with the modified send() function.

Works great! I am able to send my entire security system status in a single object in one single send() call.


OMG, someone actually replied.
I'm so happy my lib was actually usefull

I will get the github working since you have shown interest in my work

Thanks a lot, you also just made my day!

(I will add the JSON, if you are OK with it, as a 2nd function, so users can decide which one they prefer)


Sorry my reply is so late now haha! I was out of town for military stuff since November and have had ZERO "fun time" (programming, electronics, etc.) since then!

Now the hard part is pulling all my code back up and remembering what is what! God I hate when I have to take a long break from these things.

Anyways, definitely an awesome library man. I can't say enough how much you saved me here. I searched for months and months and months before finding your library. I think part of why you haven't gotten many replies is that this is still new stuff. I mean, sockets like this have been around forever, but you just don't see that many people who are working on socket.io with arduino, and when they do it's all hard wired USB and just other things that I don't want.

I am an amateur with all this (experienced amateur I suppose at this point) and the only reason I took the dive to start learning socket.io, node.js, angular.js, mongo etc was because my buddy highly recommended it. And he is a 'cutting edge' type software developer. He spends most of his time working with beta tech stuff like the virtual reality stuff right now for example. He turned me onto all these javascript based socket connections and said they will be more popular later when more is done with them. They definitely improved my security server dramatically.


Hi! First, thanks for sharing!! ^-^ Is this library working properly with ESP8266? May I upload this to my  ESP instead of Arduino?


it does work for the 8266 using Arduino IDE and additional boards :

you just need to edit the .h file depending on your needs
//Uncomment the correct line
//#include <Ethernet.h>               //For W5100
//#include <UIPEthernet.h>            //For ENC28J60
#include <ESP8266WiFi.h>            //For ESP8266

let me know if you have any issues


Really nice, man. I'll test it today.
I don't know if it helps, but this WebSocket library https://github.com/Links2004/arduinoWebSockets seems to support secure websocket and be more up to date than Bill Roy's.


thanks for the link
I will check it out and see if I can update my lib using the newer version.
Did you find any bugs / issues with ESP8266?


I have a SparkFunESP8266 shield. I connected to the wifi network and I want to use socket.io on this one.

I`am trying to use your library but I`am stuck .... I do not know C++ ... it`s my first time ...

I use on setup

   if (!client.connect(server, port)){
        Serial.println(F("Not connected."));

.... on SocketIOClient::connect sendHandshake(hostname) works and I can see in node console that a new connection was make ... problem comes on ::readhandshake on

if (atoi(&databuffer[9]) != 200) {
      while (client.available()) readLine();
      return false;
... it returns always false ... it seems data databuffer is empty

If i uncomment in the ::readLine  (Serial.print(c);         //Can be used for debugging)

I reaceive that:

+IPD,0,357:HTTP/1.1 200 OK
Content-Type: text/plain; charset=UTF-8
Content-Length: 100
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: Arduino
Set-Cookie: io=1bO6tm54TbT7t-QtAAAC
Date: Mon, 07 Mar 2016 04:01:45 GMT
Connection: keep-alive

97:0{"sid":"1bO6tm54TbT7t-QtAAAC","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":60000}Not connected.




Can you help me ?


did you get the latest version from Github? (not the beta, I still need to finish it)
what version of node.js and socket.io are you using?
did you modify the provide app.js?

you can also open a ticket on github if you want.


Dear washo4evr, I'm new in Arduino, so may be my question will looks strange, so could You please explain to which pins on ESP8266 should ENC28J60 connectrd to. In Enc28J60Network.h I found lines
#define ENC28J60_CONTROL_CS     SS
#define SPI_MOSI        MOSI
#define SPI_MISO        MISO
#define SPI_SCK         SCK
#define SPI_SS          SS

but I can't understod which pins on ESP8266 board corresponds to MOSI, MISO,SCK asd SS names.


You can use the WiFi directly from the ESP
I have not tried to connect a ENC28J60 to the ESP
I usually use https://learn.adafruit.com/adafruit-feather-huzzah-esp8266/pinouts to check which pins I need


Hey washo4evr..  :) Thanks...Thankyou very much for the library.

I tried with esp8266 and it's working  _/\_ :D .. The only problem is .. if the is any documentation of functions. It would be really helpful.

SomeHow I made it work, but unable to figured out what's happening in WebSockets to edit the code.

Go Up