Go Down

Topic: Two ESP8266 on one Fastled webserver (Read 341 times) previous topic - next topic


So I used your code and they communicate perfectly. I saw some things I haven't used before like #ifndef but these things were pretty self-explanatory. So to make it more understandable what's going on I split the code into two parts, the server and client. This made it better to follow.

As I understand, you programmed a part into the HTML script that sends the data, I am not an expert on HTML, but your script was pretty short. However, the webpage I'm using is quite a bit longer. I haven't figured out how it functions yet.

Anyway, I think I understand what you are doing and I should be able to implement this into the code I'm using. At least for the server-side that is. I'm not so sure how I would edit the code for the client that is doest use its own websurfer anymore but instead uses the information of the server ESP.

I will just dump everything I am using right now in the attechment, except for the secrets.h file.

Anyway, I think I should be able to figure out how to make it all works now. If not, I will let you know. Thanks a lot


Aug 13, 2019, 02:51 pm Last Edit: Aug 13, 2019, 03:16 pm by Hiddenvision
No worries on how you prefer the code.
I just did it like that as an easy way to keep it all in the one file.
Easier to edit common functions for me that way.
Also it was just yet another example of how to do something.

I took a look at the sketch you supplied.
I notice that the code already contains some stuff for websockets_server.

So you are actually 98% there.

Get your code using the websocket bits that exist and then just bolt in the websocket_clients stuff on top.
That way you can broardcast to any devices that are connected with setting updates or whatever.
You could use the MDNS stuff to find all devices if needed.

Just make sure you don't trigger a chain reaction where every device wants to constantly update the others!

The example I gave should have enough info for implementing something,
I will continue to play with it but I think the motor is almost started.

Also have a look at the McLighting code.
It fully uses Websockets_server already.


Aug 13, 2019, 03:41 pm Last Edit: Aug 13, 2019, 04:02 pm by Hiddenvision
Although this link is not Arduino

I have seen somewhere mention that someone has Arduino has a version.
Ahh https://github.com/esp8266/Arduino/tree/master/libraries/ESP8266WiFiMesh

Just another way to do the same sort of thing.

Re the example.
The HTML part is just the little page for the browser to work.
Simple 3 sliders, txt box and enough javascript to get the websocket connection going.

The fastled example uses a page(s) from SPIFFS, you will find in the data folder.
Focus on the .js files as they are the bulk of local code.
But don't bother with reading the bootstrap and jquery _min.js files.!!
I see that some are one liners,(no linefeeds)
you want to spend some time formatting those so they are easy to read and or edit.

Also the edit page is all squished(hard to edit), I have an unsquished version if needed.

There is no reason why all the devices cannot contain mostly the same code.
They can all have webserver and both websocket Servers and Clients for the background traffic.
When you browse to any device it could present a list of reachable units so you can select some or all to apply the settings you are changing. Then the unit that you are connected to can distribute the settings to the other devices as per the list.


Tried to compile your example, failed for some reason.
So I did download the original source but for some reason it fails to compile also.
Not looked too deep but it did not look like an easy to edit example.
I found the McLighting example far easier to dive in and adapt.

Anyway, just to further comment,
you do not need to use the websockets stuff for the web pages.
You can leave them as they are for now.

You just need to patch in the example I gave to your fastled code if you only have two modules.
Just get rid of all the webserver related stuff and it should not conflict with the current fastled code.
If I can get the FastLed example to compile then I will give it a go, just to know if I am talking rubbish or not.


Aug 14, 2019, 05:22 pm Last Edit: Aug 15, 2019, 02:15 pm by Hiddenvision
Ok Well I manage to stop the error enough to compile.

So I looked closer at the code and had noticed that it has some bits for sending out the settings already.

Code: [Select]

void setup(){

  autoPlayTimeout = millis() + (autoplayDuration * 1000); 

void sendInt(uint8_t value){ sendString(String(value));}
void sendString(String value){ webServer.send(200, "text/plain", value);}
void broadcastInt(String name, uint8_t value){
  String json = "{\"name\":\"" + name + "\",\"value\":" + String(value) + "}";
  PassedData = json;
  if (WS_ClientNum != 99){
    if(PassedData == ""){PassedData = "NONE_#";}
    S_webSocket.sendTXT(WS_ClientNum, PassedData);     

void broadcastString(String name, String value){
  String json = "{\"name\":\"" + name + "\",\"value\":\"" + String(value) + "\"}";
  PassedData = json;
  if (WS_ClientNum != 99){
    if(PassedData == ""){PassedData = "NONE_#";}
    S_webSocket.sendTXT(WS_ClientNum, PassedData);     


void loop() {
  // Add entropy to random number generator; we use a lot of it.

  //  dnsServer.processNextRequest();
  //  webSocketsServer.loop();
  //  handleIrInput();


So I added in the passeddata= json; bit
Then I just edited the client/server example a little and included it to the fastled example.

Add the include line just above where your first function is or at least below any variable declarations it needs.

Code: [Select]

#include "FORUM_ESP_FastLed.h"

// scale the brightness of all pixels down
void dimAll(byte value){
  for (int i = 0; i < NUM_LEDS; i++) {

Then add WS_setup(); as the last line of your current setup()
Then add WS_loop(); as the first line of your current loop()

At least that is a super fast way to try it out.

Go Up