I worked through the course “Build Web Servers”, and I want to extend the example 4.4 of Multiple Web Page, with an extra web page with a slider. Finally the slider of example 2.4 was added. However to get it realy working I get error messages like: E (25176) gpio: gpio_set_level(226): GPIO output gpio_num error
Probably this error comes from two voids in the main.cpp with the same name handleWebSocketMessage(..) used for the outputs and for the slider. This probably mixes up data, resulting in the LED’s connected to the outputs go onn/off when I move the slider, as well as the error message comes up in the Serial Monitor.
How can I pass information from outputs (switches) and sliders, without interfering?
After studying a project “ESP32_Nultiple_Sliders_Web_Server, I was finally able to make the project working for 3 servo’s. The intention was to oparate 4 servo’s but maybe the traffic and memory was short a I used SD car, OLED ssd1306, 4 switches and a DHT22. After removing SD card operations, 1 servo and increasing the DHT time interval from 10 to 60 sec, the system works.
Because I use switches and sliders, the handleWebSocketMessage had to be changed, see piece of code below.
// outputs and slider
void handleWebSocketMessage(void *arg, uint8_t *data, size_t len) {
AwsFrameInfo *info = (AwsFrameInfo*)arg;
// sliders
if (info->final && info->index == 0 && info->len == len && info->opcode == WS_TEXT) {
data[len] = 0;
message = (char*)data;
if (message.indexOf(“1s”) >= 0) {
sliderValue1 = message.substring(2);
dutyCycle1 = map(sliderValue1.toInt(), 0, 100, 0, 180);
notifyClients(getOutputStates(),getSliderValues());
}
if (message.indexOf(“2s”) >= 0) {
sliderValue2 = message.substring(2);
dutyCycle2 = map(sliderValue2.toInt(), 0, 100, 0, 180);
notifyClients(getOutputStates(),getSliderValues());
}
if (message.indexOf(“3s”) >= 0) {
sliderValue3 = message.substring(2);
dutyCycle3 = map(sliderValue3.toInt(), 0, 100, 0, 180);
notifyClients(getOutputStates(),getSliderValues());
}
/*
if (message.indexOf(“4s”) >= 0) {
sliderValue3 = message.substring(2);
dutyCycle3 = map(sliderValue4.toInt(), 0, 100, 0, 180);
notifyClients(getOutputStates(),getSliderValues());
}
*/
if (strcmp((char*)data, “getValues”) == 0) {
notifyClients(getOutputStates(),getSliderValues());
}
// Outputs
if (strcmp((char*)data, “states”) == 0) {
notifyClients(getOutputStates(),getSliderValues());
}
else{
int gpio = atoi((char*)data);
digitalWrite(gpio, !digitalRead(gpio));
notifyClients(getOutputStates(),getSliderValues());
}
}
}
Hopefully this is helpfull for anyone who wants to combine outputs and sliders.
This question can be closed.
Start your code here