ESP8266 NodeMCU Module – Timer

 

ESP8266 NodeMCU timer provides 7 (0-6) static timer function of timer module. we can’t use more than 7. Also you can create object based timer function with custom name. we can use this timer function like following applications

  • To blink LED for certain time duration its like repeated process.
  • To monitor the WiFi Status of ESP8266 IP address.


Functions

  • tmr.alarm()  – This is a convenience function combining tmr.
  • tmr.create()  – Creates a dynamic timer object.
  • tmr.delay()  – Busyloops the processor for a specified number of microseconds.
  • tmr.interval()  – Changes a registered timer’s expiry interval.
  • tmr.now() – Returns the system counter, which counts in microseconds.
  • tmr.register()  – Configures a timer and registers the callback function to call on expiry.
  • tmr.resume()  – Resume an individual timer.
  • tmr.resume_all()  – Resume all timers.
  • tmr.softwd()  – Provides a simple software watchdog, which needs to be re-armed or disabled before it expires, or the system will be restarted.
  • tmr.start()  – Starts or restarts a previously configured timer.
  • tmr.state()  – Checks the state of a timer.
  • tmr.stop()  – Stops a running timer, but does not unregister it.
  • tmr.suspend()  –  Suspend an armed timer.
  • tmr.suspend_all()  – Suspend all currently armed timers.
  • tmr.time()  – Returns the system uptime, in seconds.
  • tmr.unregister()  – Stops the timer (if running) and unregisters the associated callback.
  • tmr.wdclr()  – Feed the system watchdog.

 


Timer Example – Print Hello word Every 2 Sec Once

 

Basic Connection Diagram

Note : this below diagram for flash nodeMCU Firmware to ESP8266. We use the same circuit. But GPIO-0 Should be High or float Mode

Pr-Request

Note : NodeMCU Firmware should be contains tmr  modules.

 

Required

  • Any ESP8266 Module – 1Nos
  • ESPlorer IDE

 

Code

 

Code Explanation

  • First checking the required NodeMCU Lua modules tmr  is present in ESP8266. if not present the required  function will give error, its does not goes next line.
  • Set the Timer parameters like id, delay duration, and mode in TIMER_ID , TIMER_DELAY_DURATION , TIMER_MODE  variables.
  • Then execute the timer-0 with 2sec delay duration in repeat mode(No need to call the tmr.start()  function). Every one second once the timer call function call the used defined lua
  • Timer call back function prints Hello World  using  print().

 

 


Timer Example – Blink or Toggle LED

 

Code

  • Add Soon

 

Output

 

 

 


Timer Example – WiFi IP address status monitor

 

Aim

To continuously monitor whether ESP8266 gets IP address from the router in station mode using timer function with 1000ms delay. If ESP8266 got IP Address from the router, then ESP8266 timer stops.

 

Pr-Request

  • Embedded Applications – Timer
  • Lua Predefined Function
    • required()
    • print()
    • local function_name()  (user defined)
  • Lua Loop functions
    • if , else
  • NodeMCU Timer Module function
    • tmr.alarm()
    • tmr.stop()
  • NodeMCU WiFi Modules functions
    • wifi.sta.config()

Note : NodeMCU Firmware should be contains tmr  and wifi  modules.

 

Required

  • Any ESP8266 Module – 1Nos
  • ESPlorer IDE

 

Connection Diagram

Note : this below diagram for flash nodeMCU Firmware to ESP8266. We use the same circuit. But GPIO-0 Should be High or float Mode

 

 

Flow Chart

 

 

Code

Code Explanation

  • First checking the required NodeMCU Lua modules tmr , wifi  are present in ESP8266. if not present the required  function will give error, its does not goes next line.
  • Set the WiFi credentials in SSID  and PASSWORD  variable.
  • Set the Timer parameters like id, delay duration, and mode in TIMER_ID , TIMER_DELAY_DURATION , TIMER_MODE  variables.
  • Configure the SSID  and PASSWORD  variable strings in NodeMCU WiFi Module function wifi.sta.config()
  • Configuration once done, then execute the timer-0 with 1sec delay duration in repeat mode(No need to call the tmr.start()  function). Every one second once the timer call function call the used defined lua function  WiFi_IP_ADDRESS_STATUS_MONITOR()  with no arguments .
  • The User defined function   WiFi_IP_ADDRESS_STATUS_MONITOR()  is a local function with no arguments, its has one user-defined functions  print() and two NodeMCU firmware wifi  and tmr  functions wifi.sta.getip()  and tmr.stop() .

 

FAQ

What is WiFi Credentials

  • WIFi User name and password like a parameters called WiFi Credentials

 


 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

if you have any queries call us +918300026060 or WhatsApp Dismiss

0

Your Cart

%d bloggers like this: