• 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

Web Server with Slider doesn't update the connected clients

Q&A Forum › Category: ESP32 › Web Server with Slider doesn't update the connected clients
0 Vote Up Vote Down
Enrico asked 1 year ago

Hi,
The example 2.4 “Web Server with Slider” in the book “Build Web Servers with the ESP32 and ESP8266” doesn’t update the connected clients after moving the slider.
To fix this, after having given a look at the working example 2.3,  I made following changes to some of the files of example 2.4.
1) In the main.cpp file I added this method:
void notifyClients(String state) {
  ws.textAll(state);
}
and called it inside handleWebSocketMessage after getting the sliderValue and before calculating the dutyCycle:
sliderValue = (*char)data;
notifyClients(sliderValue);
dutyCycle = map(sliderValue.toInt(), 0, 100, 0, 255);
2) In the script.js file I added getCurrentValue inside the onMessage function:
function onMessage(event) {
  console.log(event.data);
  getCurrentValue();
}
3) In the index.html I changed “oninput” to “onchange” inside the <input> element to avoid sending a lot of wrong values during the moving of the slider. This sends only the last value leaving the slider:
<input type=”range” onchange=”updateSliderPWM(this)” id=”pwmSlider” …>
Please let me know if this is a good fix for the existing problem.
Many thanks!
Best regards,
Enrico

Question Tags: slider update clients
1 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 1 year ago

Hi.
Thank you for your suggestion.
I’ll test the project again and implement any required fixes.
Thank you so much for sharing your solution.
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

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

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

Copyright © 2013-2025 · 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.