• 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

esp32 countdown management, display and go/stop button on an html page as well as time entry.

Q&A Forum › Category: ESP32 › esp32 countdown management, display and go/stop button on an html page as well as time entry.
0 Vote Up Vote Down
Xavier MORIN asked 3 years ago

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

Question Tags: esp32 -asynchweb - javascript
2 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 3 years ago

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

0 Vote Up Vote Down
Xavier MORIN answered 3 years ago

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;
}

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] Learn Raspberry Pi Pico/Pico W with MicroPython eBook – Version 1.2 May 26, 2025
  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition 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.