Arduino Forum

Development => Other Software Development => Topic started by: washo4evr on May 02, 2015, 10:11 pm

Title: Socket.io v1.x Library for W5100 & ENC28J60 + ESP8266
Post by: washo4evr on May 02, 2015, 10:11 pm
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 (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)
Title: Re: Socket.io v1.x Library for W5100 & ENC28J60
Post by: washo4evr on May 04, 2015, 09:59 pm
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
Title: Re: Socket.io v1.x Library for W5100 & ENC28J60
Post by: salomonsk8r2003 on Sep 22, 2015, 04:31 am
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.
Title: Re: Socket.io v1.x Library for W5100 & ENC28J60
Post by: salomonsk8r2003 on Sep 22, 2015, 06:10 am
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.
Title: Re: Socket.io v1.x Library for W5100 & ENC28J60
Post by: washo4evr on Oct 02, 2015, 06:53 pm
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)
Title: Re: Socket.io v1.x Library for W5100 & ENC28J60 + ESP8266
Post by: salomonsk8r2003 on Jan 25, 2016, 11:15 pm
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.
Title: Re: Socket.io v1.x Library for W5100 & ENC28J60 + ESP8266
Post by: Vitorbnc on Jan 27, 2016, 03:59 am
Hi! First, thanks for sharing!! ^-^ Is this library working properly with ESP8266? May I upload this to my  ESP instead of Arduino?
Title: Re: Socket.io v1.x Library for W5100 & ENC28J60 + ESP8266
Post by: washo4evr on Jan 27, 2016, 12:06 pm
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
Title: Re: Socket.io v1.x Library for W5100 & ENC28J60 + ESP8266
Post by: Vitorbnc on Jan 27, 2016, 01:08 pm
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.
Title: Re: Socket.io v1.x Library for W5100 & ENC28J60 + ESP8266
Post by: washo4evr on Feb 01, 2016, 02:51 pm
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?
Title: Re: Socket.io v1.x Library for W5100 & ENC28J60 + ESP8266
Post by: braicauc on Mar 07, 2016, 05:28 am
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

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 ?
Title: Re: Socket.io v1.x Library for W5100 & ENC28J60 + ESP8266
Post by: washo4evr on Mar 08, 2016, 08:12 am
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.
Title: Re: Socket.io v1.x Library for W5100 & ENC28J60 + ESP8266
Post by: grombl3 on Mar 09, 2016, 08:53 pm
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.
Title: Re: Socket.io v1.x Library for W5100 & ENC28J60 + ESP8266
Post by: washo4evr on Mar 09, 2016, 10:04 pm
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 (https://learn.adafruit.com/adafruit-feather-huzzah-esp8266/pinouts) to check which pins I need
Title: Re: Socket.io v1.x Library for W5100 & ENC28J60 + ESP8266
Post by: BhanuTejaJ on Mar 24, 2016, 02:33 pm
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.
Title: Re: Socket.io v1.x Library for W5100 & ENC28J60 + ESP8266
Post by: washo4evr on Mar 24, 2016, 04:57 pm
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
Title: Re: Socket.io v1.x Library for W5100 & ENC28J60 + ESP8266
Post by: BhanuTejaJ on Mar 26, 2016, 09:37 pm
Thanks for your ...quick response :)

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

Thanks,
Teja
Title: Re: Socket.io v1.x Library for W5100 & ENC28J60 + ESP8266
Post by: Aledav on Apr 05, 2016, 04:39 pm
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
Title: Re: Socket.io v1.x Library for W5100 & ENC28J60 + ESP8266
Post by: washo4evr on Apr 05, 2016, 07:11 pm
Hi,
this is a know issue with a fix on github
the fix will be added to the next version
Title: Re: Socket.io v1.x Library for W5100 & ENC28J60 + ESP8266
Post by: chip69 on Apr 14, 2016, 11:59 am
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?
Title: Re: Socket.io v1.x Library for W5100 & ENC28J60 + ESP8266
Post by: washo4evr on Apr 15, 2016, 01:13 am
Hi,

I have not tried the w5500 yet
I might order one at some point
most of the code should work though without any modification.
probably some changes in the ethernet library
I will investigate
meanwhile, you can try editing the lib
according to http://labs.arduino.org/Arduino%20Ethernet%20Shield%202
NB. You can reuse your code written for Arduino Ethernet Shield, simply replacing
#include <Ethernet.h>  -->  #include <Ethernet2.h>
#include <EthernetUdp.h>  -->  #include <EthernetUdp2.h>
Title: Re: Socket.io v1.x Library for W5100 & ENC28J60 + ESP8266
Post by: palsbo on May 09, 2016, 11:11 pm
I got the library working with communication between server and web-client and between server and ESP8266.

I have one problem: data are received on the ESP8266 (log-msg) but not delivered to the application.
Code: [Select]
  if (client.monitor()) {
    lastreply = millis();
    Serial.println(RID);
    Serial.println(Rname);
    Serial.println(Rcontent);
    }
  }


I get no print of RID, Rname and Rcontent in my client.monitor

I also tried to implement a callback routing like this:
Code: [Select]
void ondata(SocketIOClient client, char *data) {
  Serial.print(data);
}


registering the callback in setup() like this:

Code: [Select]
client.setDataArrivedDelegate(ondata);

But this also not works.

I cannot understand from the SocketIOClient.cpp how the callback is called???

Any help is highly appreciated.

Title: Re: Socket.io v1.x Library for W5100 & ENC28J60 + ESP8266
Post by: palsbo on May 10, 2016, 06:39 am
After looking into the library code, I see that the monitor function does not return true.

I added this and it works fine now.

For reference I attach my revised library.

Changes in SocketIOClient.cpp and example
Title: Re: Socket.io v1.x Library for W5100 & ENC28J60 + ESP8266
Post by: palsbo on May 10, 2016, 06:49 am
Sorry - I  try again.
Title: Re: Socket.io v1.x Library for W5100 & ENC28J60 + ESP8266
Post by: MichaelL65 on Jan 24, 2017, 06:04 pm
Sorry to bump an older post, but I have jumped into the world of websockets without a clue of what I am doing (the more I learn, the more I realize what I don't know). This is the only library that I've found that deals with socket.io after version 1.0, and the only one where I've gotten the example to actually work!

What I am working on currently will send and receive JSON data through a socket.io server on a computer that will in turn be sending and receiving data from another "black box" (doesn't really matter, which is the whole point of websockets).

I'm using an Adafruit capacitive touch sensor and some LEDs to indicate what has been touched at my end, sending that data and receiving data to also control the LEDs from the other end. This was originally done using the serial port to talk to the black box, but it ended up with considerable distance and the USB extender we used seems to have issues with being used for a serial port (drops the connection after a while - end up having to reboot both ends to get it working again). Websockets was the solution the programmer of the black box wanted, so here I am trying to catch up.

TLDR: I still don't know what I don't know. Would anyone who has used this library care to share some of their code so I can learn from the examples?
Title: Re: Socket.io v1.x Library for W5100 & ENC28J60 + ESP8266
Post by: washo4evr on Jan 24, 2017, 07:18 pm
Hi,

Thanks for bringing this thread back to life

I have been mostly on github lately.
I also replied to your PM.

Let me know if you need anything
Title: Re: Socket.io v1.x Library for W5100 & ENC28J60 + ESP8266
Post by: sarveshpawar29 on Jan 29, 2017, 06:13 am
Sir/Madam,

    I am using BH-MSD-2A driver with BH42SH38-1684 LA-TR 8X8 BIPOLAR stepper motor so how should I calibrate it with my arduino board to operate it with potentiometer of 1 M ohm and also to operate it for fixed rotation for clock wise and anti clockwise direction.
Title: Re: Socket.io v1.x Library for W5100 & ENC28J60 + ESP8266
Post by: vlp_arduino on Jul 06, 2017, 07:31 pm
As it been discussed on github, there is a bug, and the connection is lost after 3', does anyone succeeded in maintaining the connection during a long time ?
Title: Re: Socket.io v1.x Library for W5100 & ENC28J60 + ESP8266
Post by: melbinsteephan on Jul 26, 2017, 07:56 am
does w5100 ethernet module support websockets or long polling methods to communicate with server
Title: Re: Socket.io v1.x Library for W5100 & ENC28J60 + ESP8266
Post by: pixon on Aug 07, 2017, 03:32 pm
Why the lib won't work with an Arduino Wifi Uno? http://www.arduino.org/products/boards/arduino-uno-wifi
I there any chance I can set up a websocket on this board?
Title: Re: Socket.io v1.x Library for W5100 & ENC28J60 + ESP8266
Post by: washo4evr on Aug 08, 2017, 06:18 am
I never tried the uno wifi but my bet is that the communication to the ESP8266 is serial meaning we cannot establish directly the websocket on it.

Is there a websocketlib for the arduino wifi?
Title: Re: Socket.io v1.x Library for W5100 & ENC28J60 + ESP8266
Post by: vietthucet on Jul 18, 2019, 05:26 am
Hi, i can start server and connect by web browser but uno + ethernet shield is not, please help me solve this problem, many thanks
Title: Re: Socket.io v1.x Library for W5100 & ENC28J60 + ESP8266
Post by: washo4evr on Jul 19, 2019, 03:29 am
Hi,

could you post more information and the code here?
did you change the #define?