Hello,
I would like to retrieve value when the button is pressed. on the html page to manage the countdown then display the countdown on the html page. Finally stop the countdown if you press the button a second time.
=> I don’t know how to retrieve the data from the html page to process it in my program of my esp32.
Can you help me (javascript?)?
Cordially
Hi.
I think the best way to send data from the webpage is to use websocket protocol. Using this protocol, the client doesn’t need a request from the server to send data to the server.
Take a look at the following tutorial and get familiar with websocket protocol first: https://randomnerdtutorials.com/esp32-websocket-server-arduino/
Do you have the countdown created on the HTML page? Can you share the code? You need to provide more details about your project, otherwise, it is very difficult to help.
Regards,
Sara
Thanks, I’m working on it with your directions. I’ll come back to you as soon as I’ve made enough progress.
I am stuck in the esp program on the push button to start or pause the countdown. see the program below.it stops but does not restart.
Cordially.
Start your code here
#include <Arduino.h>
const int buttonPin = 4;
int buttonState;
int lastButtonState = LOW;
unsigned long lastDebounceTime = 0;
unsigned long debounceDelay = 50;
hw_timer_t * timer = NULL;
volatile int interruptCounter;
volatile SemaphoreHandle_t timerSemaphore;
portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;
volatile uint32_t chrono = 10;
volatile int boutonstop = 0;
void IRAM_ATTR onTimer()
{
portENTER_CRITICAL_ISR(&timerMux);
interruptCounter–;
portEXIT_CRITICAL_ISR(&timerMux);
xSemaphoreGiveFromISR(timerSemaphore, NULL);
}
void setup()
{
Serial.begin(115200);
pinMode(buttonPin, INPUT);
timerSemaphore = xSemaphoreCreateBinary();
timer = timerBegin(0, 80, true);
timerAttachInterrupt(timer, &onTimer, true);
timerAlarmWrite(timer, 1000000, true);
timerAlarmEnable(timer);
}
void loop()
{
int reading = digitalRead(buttonPin);
if (reading != lastButtonState)
{
lastDebounceTime = millis();
}
if ((millis() – lastDebounceTime) > debounceDelay)
{
if (reading != buttonState)
{
buttonState = reading;
if (buttonState == HIGH)
{
if (boutonstop == 0)
{
timerStop(timer);
boutonstop = 1;
}
else
{
timerRestart(timer);
boutonstop = 0;
}
xSemaphoreGiveFromISR(timerSemaphore, NULL);
}
}
}
if (xSemaphoreTake(timerSemaphore, 0) == pdTRUE)
{
portENTER_CRITICAL(&timerMux);
if(chrono!=0)
{
chrono–;
Serial.print(“Decompte : “);
Serial.println(chrono);
}
else
{
timerEnd(timer);
timer = NULL;
}
portEXIT_CRITICAL(&timerMux);
}
lastButtonState = reading;
}