# Connect to websocket on ESP8266

**URL:** <https://discourse.nodered.org/t/connect-to-websocket-on-esp8266/12906>\
**Category:** General\
**Created:** [4 July 2019 14:20 UTC](https://discourse.nodered.org/t/connect-to-websocket-on-esp8266/12906 "2019-07-04T14:20:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![AD3D](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ad3d/32/2731_2.png) [@AD3D](https://discourse.nodered.org/u/AD3D)\
**Post date:** [4 July 2019 14:20 UTC](https://discourse.nodered.org/t/connect-to-websocket-on-esp8266/12906/1 "2019-07-04T14:20:49Z")

</div>

**Is it possible?**  
**Yes it is** , and mostly because of the good eye of dceejay.  
So this is solved, althrough it could use some tweaking at the time.  
For now, I think it would not hurt to leave it here.

I was, but still am wondering about this and maybe my fantasies is going to wild here... but maybe.

I have an ESP8266 with a RGB controller on it. Nothing fancy.  
It has a webpage on it to control the RGB.

 ![lolwebpage](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/0/0abb5c8e600be149e04dae890c7a980cb315d5c7.jpeg)  
The RGB lamp works perfect with the websocket library on it.!  
 ![websocket_event_code1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/5/568cf2df9dbd4424a99b42cde53011a60d860af4.jpeg)  
A websocket.js file is containing the JavaScript code  
 ![websocket_js_file](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/6/6f7e37d652991671993f16557a0003658dc82567.jpeg)  
Part of the code for sending after hitting a button.  
 ![send_example](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/b/be8d68495d4e76724c0d6b80f2c6ab562accee62.jpeg)

Is it possible to make something with Node-RED to control it?  
A button on the dashboard to set it on or off, or maybe even change the color!?  
I tryed the websocket node like this,  
 ![node-red_test1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/b/beed648b7ebfa9440386682f5f59eaf06d6cdd36.jpeg)  
but, sure I am doing something wrong.  
I treid to follow a few examples on the web, maybe it's the language barrier, I can not find a way to set this up.  
Anybody an idea what I must do?  
Thanks in advance.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [4 July 2019 14:57 UTC](https://discourse.nodered.org/t/connect-to-websocket-on-esp8266/12906/2 "2019-07-04T14:57:57Z")

</div>

In your js code you have ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/7/7e9cd2f0e084fbec7be64fcea9a8c744d787c13a.png)  
and in your Node-RED example you have port 1881, and your web page just shows lol05.local - so which port is that ? so one or other isn't correct.

---

<div class="post-metadata">

**Author:** ![AD3D](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ad3d/32/2731_2.png) [@AD3D](https://discourse.nodered.org/u/AD3D)\
**Post date:** [4 July 2019 15:29 UTC](https://discourse.nodered.org/t/connect-to-websocket-on-esp8266/12906/3 "2019-07-04T15:29:44Z")

</div>

Good eye.  
In the sketch for the ESP8266 it creates a websocket on port 81.  
 ![websocket_port](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/a/a0ef4e94a626289cfe351951c33bcebcdbd933ad.jpeg)

One of the many examples (don't now the link any more) it was an advice to put 18 before the used port! I was wondering myself WHY? but it could not hurt to try.  
Sorry that I have left it there.  
At the same time I treid it without the 18 and it just works.  
Great. But stupid me that I didn't see that any more.  
Thanks man.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [6 July 2019 13:50 UTC](https://discourse.nodered.org/t/connect-to-websocket-on-esp8266/12906/4 "2019-07-06T13:50:15Z")

</div>

The main reason for not using ports below 1024 is that, on most servers, they require admin/root permission to handle the port. That is one of the reasons that Node-RED uses a port above 1024.

Doesn't apply of course on such a simplistic device as the ESP8266.
