• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

Build Webservers Module 3, 2.4 WebServer with slider

Q&A Forum › Category: Questions › Build Webservers Module 3, 2.4 WebServer with slider
0 Vote Up Vote Down
Manfred Haefner asked 6 months ago

Hi there,  in your esp webserver course, item \”2.4 – Web Server with Slider: Control LED Brightness (PWM)\” seems to be a bug:  the example works fine with only 1 client connected, but if more than one clients connected, the slider value is not updated on all clients, only on the one that makes the change. How can this be solved ? Manfred

5 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 6 months ago

Hi.
That’s normal.
Because, contrary to the code in the previous example (2.3), it doesn’t include the sections of code to notify all clients when a change is detected.
Take a look at the notifyClients() function in example 2.3.
You need to implement that in the 2.4 example to make it work that way.
 
If you want, I can modify the code to do that and send it to you.
 
Let me know if you need it.
 
Regards,
Sara

0 Vote Up Vote Down
Manfred Haefner answered 6 months ago

Hi Sara,
thanks for the answer. Yes please send me the modified code, just to help me understanding how everything works together.
Thanks in advance
Manfred

0 Vote Up Vote Down
Sara Santos Staff answered 5 months ago

Hi.
 
I’m sorry for taking so long back to you. I’ve been sick for the past few days, and I’m slowly recovering.
 
Here’s the arduino code:
https://gist.github.com/sarasantos/ed1f4b0f780a0da060fd7616e546aa42
Basically, you need to create this function that notifies all clients

void notifyClients(String state) {
  ws.textAll(state);
}

 
Then, you need to call it inside the handleWebSocketMessage() so that when a client sends a new slider value, we notify all other clients of the change:

void handleWebSocketMessage(void *arg, uint8_t *data, size_t len) {
  AwsFrameInfo *info = (AwsFrameInfo*)arg;
  if (info->final && info->index == 0 && info->len == len && info->opcode == WS_TEXT) {
    data[len] = 0;
    sliderValue = (char*)data;
    notifyClients (sliderValue);
    dutyCycle = map(sliderValue.toInt(), 0, 100, 0, 255);
    Serial.println(dutyCycle);
  }
}

 
You also need to add just a couple of lines to the Javascript file. Here’s the code: https://gist.github.com/sarasantos/2363ea3a335e0fadbc0cb5de7a2d4441
 
Basically, you need to add the following lines to the onMessage function so that when it receives a new slider value, it updates the interface:

document.getElementById('textSliderValue').innerHTML = event.data;
document.getElementById('pwmSlider').value = event.data;

And that’s it.

I hope this is useful.
 
Regards,
Sara

0 Vote Up Vote Down
Manfred Haefner answered 5 months ago

Hi Sara,
after adding your code lines to my project everything works fine now. Also i understand better now, how everything works together …
Thanks for your help, 
Manfred

0 Vote Up Vote Down
Sara Santos Staff answered 5 months ago

That’s great.
I’ll mark this issue as resolved. If you need further help, you just need to open a new question in our forum.
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [eBook Updated] Smart Home with Raspberry Pi, ESP32, and ESP8266 Version 1.7 November 28, 2025
  • [eBook Updated] Smart Home with Raspberry Pi, ESP32, and ESP8266 V1.6 September 9, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2026 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.