• 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 Course Project 2.4

Q&A Forum › Category: ESP32 › Web Server Course Project 2.4
0 Vote Up Vote Down
Edward Wilson asked 3 years ago

I am continuing to work my way through the web server course and have reached Project 2.4, Web Server With Slider. The code does serve a web page with slider as expected and the slider does control the brightness of the on-board LED. The web sockets protocol does not seem to be working however.
 
If I move the slider on the web page displayed on my computer, the slider displayed at the same internal ip address on my phone does not move. If I reload the web page on the phone, I do see the updated slider position. I expected the slider on the phone to follow the one on the computer since the project uses web sockets.
 
I would appreciate any troubleshooting hints…all code was copied from the online text.
 
Thanks,
 
Ed Wilson

7 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 3 years ago

Hi.
You’re right. That’s not the expected behavior.

Open two web browser windows on the web server IP address.
Open the javascript console in both windows.
Drag the slider in one window. Tell me what do you get in the javascript debugging console for each browser window.

At the same time, check if you’re getting any error messages on the ESP32 board.

Regards,
Sara

0 Vote Up Vote Down
Edward Wilson answered 3 years ago

Sara,
Thanks for your response!
Can you tell me how to attach a screen shot file on this forum? Apparently you cannot just copy and paste.
 
Ed Wilson

0 Vote Up Vote Down
Sara Santos Staff answered 3 years ago

Hi.
You need to upload the pictures to a server and then share a link to them.
You can use google drive, dropbox, imgur, or other.
Regards,
Sara

0 Vote Up Vote Down
Edward Wilson answered 3 years ago

Ok, Sara, you should be able to download a screen shot (javascript.jpg) of two windows at the local IP address of Project 2.4 with the javascript console enabled at the following URL:
k0kc.ddns.net/uploads
As you can see, there is nothing to indicate a problem. I used the Google Chrome browser but I get similar results from Firefox.
 
When you mention error messages on the ESP32 board, do you mean compiler errors?
 
Thanks!
 
Ed Wilson

0 Vote Up Vote Down
Sara Santos Staff answered 3 years ago

Hi.
 
I’ve taken a look at the project, and it’s working as it’s supposed because it doesn’t have the required sections of code to update all clients simultaneously. 
I don’t know why at the time I created the eBook I didn’t do that.
 
To update all clients, there are a few modifications you need to do on the main.cpp and script.js files.
On the main.cpp you need to include a function that notifies all clients:

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

 
Then, on the handlwWebSocketMEssage() function you need to call the notifyClients() function to update all clients whenever we receive a message via websocket:

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;
dutyCycle = map(sliderValue.toInt(), 0, 100, 0, 255);
Serial.println(dutyCycle);
notifyClients(sliderValue);
}
}

 
On the Javascript file, you need to update the slider values when the client receives a message via websocket protocol:

function onMessage(event) {
console.log(event.data);
var sliderValue = event.data;
document.getElementById("pwmSlider").value = sliderValue;
document.getElementById("textSliderValue").innerHTML = sliderValue;
}

 
Here are links to the modified files:

  • main.cpp: https://gist.github.com/sarasantos/00208ce745b24f9ebb54edacaf2e28d1
  • script.js: https://gist.github.com/sarasantos/be179720497958b3798347d7342002f5

 
Regards,
Sara
 

0 Vote Up Vote Down
Edward Wilson answered 3 years ago

Sara,
 
Thank you so much! I certainly would have not figured this out on my own as I have not yet started trying to understand the code. I was starting to question my own abilities.
 
The project is working as expected now and I can move forward.
 
The link to the screen shot that I sent you is no longer active.
 
Ed Wilson

0 Vote Up Vote Down
Sara Santos Staff answered 3 years ago

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

  • [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.