Socket.io v1.x Library for W5100 & ENC28J60 + ESP8266

Hi guys,
I've just finished a working lib for Arduino using W5100.
My work is based on Bill Roy's library : GitHub - billroy/socket.io-arduino-client: A socket.io client for the Arduino Ethernet shield

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 : GitHub - washo4evr/Socket.io-v1.x-Library: Socket.io Library for Arduino

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 Geekcreit® NodeMcu Lua ESP8266 ESP-12F WIFI Development Board Sale - Banggood USA)

UPDATED :

  • 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

socketio.zip (9.08 KB)

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?

Hey,
it does work for the 8266 using Arduino IDE and additional boards :
http://arduino.esp8266.com/stable/package_esp8266com_index.json

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 GitHub - Links2004/arduinoWebSockets: 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.

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

I use on setup

client.setDataArrivedDelegate(ondata);
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();
client.stop();
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.
"185.84.64.111",4540,0

OK
"185.84.64.111",4540,0

OK
"185.84.64.111",4540,0

OK
"185.84.64.111",4540,0

Can you help me ?

Hey,
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 Pinouts | Adafruit Feather HUZZAH ESP8266 | Adafruit Learning System to check which pins I need

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

I tried with esp8266 and it's working _/_ :smiley: .. 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.

Hey,
thank you for your kind message.
a wiki has been started and should be available on github soon as well as the new version which will include HTTP REST functions

stay tuned

Thanks for your ...quick response :slight_smile:

Mean while can you help me with some source where can I start learning ? ....at least to get some overview, please.

Thanks,
Teja

Hi!
I'm starting to use this great library!
But I can not receive from the Node long strings,
these are truncated !!
I Uncomment line 145 SocketIOClient.cpp to show (databuffer), which
instead it contains the whole string.
How can I do to valorize (Rcontent) with long strings (600 characters)?
Thank you

Hi,
this is a know issue with a fix on github
the fix will be added to the next version

Hello,

First of all thank you for the library. It works perfect with W5100.

I am now the owner of a new Ethernet Shield 2 - W5500 chip. I work with arduino ide 1.7.9 and Ethernet2 library.

I tried to combine the ethernet2 with socket.IO and i had partly success. My setup is a Mega and Ethernet shield 2. I connected to a Socket.IO server, but it disconnects from it and never sends any message.

I don't know if it is a chip error or the libraries are not completely compatible.

Do you have any suggestions i might try?