Go Down

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

washo4evr

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)

washo4evr

#1
May 04, 2015, 09:59 pm Last Edit: Nov 05, 2015, 10:35 pm by washo4evr
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

salomonsk8r2003

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.

salomonsk8r2003

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.

washo4evr

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)

salomonsk8r2003

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.

Vitorbnc

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

washo4evr

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

Vitorbnc

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.

washo4evr

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?

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy