echo '' ;

Category Archives: ESP8266

ESP8266 NodeMCU Interface – LED

LED ON/OFF

Note : Assume the pin GPIO-5 is a LED (NodeMCU pin map is 1)

  • Set LED Mode
    • Set LED pin (gpio-5) as output using gpio.mode(pin, mode [, pullup])  function.
    • Example :  gpio.mode(1, gpio.OUTPUT)
  • Turn LED ON
    • Set LED pin (gpio-5) HIGH using gpio.write(pin, level)  function.
    • Example : gpio.write(1, gpio.HIGH)  or gpio.write(1, 1)
  • Turn LED  OFF
    • Set LED pin (gpio-5) Low using gpio.write(pin, level)  function.
    • Example : gpio.write(1, gpio.LOW) or gpio.write(1,0)

 


LED Blink Using Timer

  • Required NodeMCU Modules (Firmware) GPIO Module, Timer Module
  • Required Hardware ESP8266 with Programmer (or)  NodeMCU Dev Kit, LED- 3v3 or 5v,
  • Required Software Tools ESPlorer IDE Tool

ESP8266 with LED Connection Diagram

  • Will Add Soon

NodeMCU Lua code

-- http://www.ArunEworld.com/embedded/ESPressif/ESP8266/ESP82266_NodeMCU
--[[ Required NodeMCU Modules
 Timer Module
 GPIO Module
]]--

LED_Pin = 1 -- GPIO-5
LED_Blink_Time = 1000 -- ms
gpio.mode(LED_Pin, gpio.OUTPUT)
local function Blink()
 if ( 0 == gpio.read(LED_Pin)) then 
  gpio.write(LED_Pin, gpio.HIGH)
 elseif( 1 == gpio.read(LED_Pin)) then 
  gpio.write(LED_Pin, gpio.LOW)
 end 
end

tmr.alarm(0,LED_Blink_Time,1,function() Blink() end)

Follow steps

  • Connect the circuit as per the connection diagram
  • Save the above code as “AEW_LED-Blink.lua”
  • Open ESPlorer and upload the file “AEW_LED-Blink.lua”
  • Run the file  [ dofile(“AEW_LED-Blink.lua”) ]
  • Done.!(LED will Blink based on blink time)

LED Blink uisng While loop and Timer delay function

  • Use
    -- http://www.ArunEworld.com/embedded/ESPressif/ESP8266/ESP82266_NodeMCU 
    --[[ Required NodeMCU Modules Timer Module GPIO Module ]]--
    LED_Pin = 1 -- GPIO-5
    LED_Blink_Time = 1000 -- ms
    gpio.mode(LED_Pin, gpio.OUTPUT)
    
    while true do
        tmr.delay(1000000)
        if ( 0 == gpio.read(LED_Pin)) then
            gpio.write(LED_Pin, gpio.HIGH) 
        elseif( 1 == gpio.read(LED_Pin)) then
            gpio.write(LED_Pin, gpio.LOW)
        end
    end
    

     


LED Fade using PWM

  • Use this code
    pin = 1
    ------ PWM setup --------------
    pwm.setup(pin, 999, 512)    -- pwm.setup(pin, clock, duty) | set pin index 1 as pwm output, frequency is 100Hz, duty cycle is half.
    
    pwm.start(pin)          -- pwm.start(pin)
    duty = 1000
    
    for i=1000,0,-1 do
     --print(i)
     duty = i
     pwm.setduty(pin, duty)         -- pwm.setduty(pin, duty)
     tmr.delay(1000)
    end
    

     


 

 


Next :

Previous :


 

ESP8266 NodeMCU Project – Imperial March Ringtone Play


Playing the Imperial March ringtone on an ESP8266 NodeMCU involves using the NodeMCU’s capabilities to generate sound or control an external sound module. One common method is using a piezo buzzer to generate tones. Here’s a basic example of “ESP8266 Imperial March Ringtone play” using the NodeMCU and a piezo buzzer to play the Imperial March:

Read more… →

ESP8266 NodeMCU Tutorial – Web Server

The ESP8266 NodeMCU Tutorial – Web Server provides a comprehensive guide on how to set up a web server using the NodeMCU development board powered by the ESP8266 microcontroller.

Read more: ESP8266 NodeMCU Tutorial – Web Server

Simple Web Server

  • Simple web server display heap, ip, mac address some other details ..
  • First need to connect ESP8266 with WiFi Router. then access the web server using ip address
print("****** Wifi data's Initializing *********")
mode = wifi.STATION
ssid = "ArunEworld"
password = "Arun"

print("****** Setup Wifi Settings *********")
wifi.setmode(mode)
wifi.sta.config(ssid, password)

function Wif_Connect()
    WC = wifi.sta.status() --WC Wifi_Connect
    print("Wifi Status is : " .. WC)

    if WC == 0 then
        print("0.Satation is Idle ??")
        wifi.sta.autoconnect(auto)
    elseif WC == 1 then
        print("1.Satation Connecting....Wait a moment")
    elseif WC == 2 then
        print("2.password is wrong !")
    elseif WC == 3 then
        print("3.No Access Point Found !")
    elseif WC == 4 then
        print("4.Station connecting fail !")
    elseif WC == 5 then
        print("IP :" .. wifi.sta.getip())
        tmr.stop(0)
        -- dofile("AEW_Webserver.lua")
        -- print("IP :"..wifi.sta.getip())
        -- dofile("File_name.lua")
        -- please write your file name
    end
end

print("**** Webserver Running........ ****")
srv = net.createServer(net.TCP)
srv:listen(80, function(conn)
    conn:on("receive", function(client, request)
        buf = buf .. "<h1>Arun Eworld</h1>"
        buf = buf .. "Chip ID :<b>" .. node.chipid() .. "</b><BR>"
        --[[ 
        buf = buf.."Heap :<b>".. node.heap() .. "</b><BR>";
        buf = buf.."Station Mac Address :<b>".. wifi.sta.getmac() .. "</b><BR>";
        buf = buf.."AP Mac Address :<b>".. wifi.ap.getmac() .. "</b><BR>";
        buf = buf.."GetMode :<b>".. wifi.getmode() .. "</b><BR>";
        buf = buf.."Status :<b>".. wifi.sta.status() .. "</b><BR>";
        --buf = buf.."AP IP Address :<b>".. wifi.ap.getip() .. "</b><BR>";
        buf = buf.."Station IP Address :<b>".. wifi.sta.getip() .. "</b><BR>";
        buf = buf.."TMR.NOW :<b>" .. tmr.now() .. "</b><BR<BR><BR>";
        ]]--
        client:send(buf)
        client:close()
        collectgarbage()
    end)
end)

tmr.alarm(0, 5000, 1, Wif_Connect)

Code Explanation

Sure, here’s an explanation of the provided Lua code:

  1. Wifi Initialization:
    • The code begins by printing a message indicating the initialization of WiFi data.
    • It sets the WiFi mode to Station mode.
    • Defines the SSID and password for the WiFi connection.
  2. WiFi Connection Function (Wif_Connect):
    • This function is responsible for handling the WiFi connection process.
    • It retrieves the current WiFi connection status using wifi.sta.status().
    • Depending on the status, it performs different actions:
      • If the status is 0, it indicates that the station is idle, and it attempts to autoconnect.
      • If the status is 1, it indicates that the station is connecting.
      • If the status is 2, it indicates that the password is incorrect.
      • If the status is 3, it indicates that no Access Point (AP) is found.
      • If the status is 4, it indicates that the connection to the AP failed.
      • If the status is 5, it indicates a successful connection, and it prints the assigned IP address.
        • It also stops the timer (tmr.stop(0)), which triggers the connection attempt.
  3. Webserver Setup:
    • The code prints a message indicating that the web server is running.
    • It creates a TCP server (srv) that listens on port 80.
    • Upon receiving a connection, it defines a callback function to handle incoming requests.
    • The callback function constructs an HTML response (buf) containing the header <h1>Arun Eworld</h1> and the chip ID.
    • The response is sent back to the client, and the connection is closed.
  4. Timer Initialization:
    • A timer (tmr) is set to call the Wif_Connect function every 5 seconds (tmr.alarm(0, 5000, 1, Wif_Connect)).

This code initializes the WiFi connection, continuously attempts to connect to the configured network, and sets up a basic web server to handle incoming requests. (ESP8266 NodeMCU Tutorial Web Server)

TCP Server Listener

This code given below will configure the ESP to act as an Access Point and it has its own SSID=”ArunEworld” and Password=”Arun” and also act as the server which will continuously listen for a connection.

Code

This code initializes the ESP8266 module as an access point with the SSID “ArunEworld” and password “Arun”. It then creates a TCP server that listens on port 80. When a connection is established, it prints any received data and releases resources after sending a response.

print("ArunEworld - ESP8266 Server")
wifi.setmode(wifi.STATIONAP)
wifi.ap.config({ssid="ArunEworld", pwd="Arun"})
print("Server IP Address:", wifi.ap.getip())

sv = net.createServer(net.TCP)
sv:listen(80, function(conn)
    conn:on("receive", function(conn, receivedData)
        print("Received Data: " .. receivedData)
    end)
    conn:on("sent", function(conn)
        collectgarbage()
    end)
end)

Result

Host pot


Code Explanation

This code initializes the ESP8266 module as an access point with the SSID “ArunEworld” and password “Arun”, creates a TCP server listening on port 80, and defines callback functions to handle received and sent data.

LineCodeExplanation
1print("ArunEworld - ESP8266 Server")Prints a message indicating the initialization of the ESP8266 server.
2wifi.setmode(wifi.STATIONAP)Sets the mode of the WiFi module to STATIONAP, enabling it to function as both a station and an access point.
3wifi.ap.config({ssid="ArunEworld", pwd="Arun"})Configures the access point with the SSID “ArunEworld” and password “Arun”.
4print("Server IP Address:", wifi.ap.getip())Prints the IP address assigned to the ESP8266 access point.
6sv = net.createServer(net.TCP)Creates a TCP server object.
7sv:listen(80, function(conn)Starts the server and listens for connections on port 80.
8conn:on("receive", function(conn, receivedData)Sets up a callback function to handle received data.
9print("Received Data: " .. receivedData)Prints the received data.
10end)Ends the “receive” callback function definition.
11conn:on("sent", function(conn)Sets up a callback function to handle data sent.
12collectgarbage()Collects garbage to free up memory.
13end)Ends the “sent” callback function definition.
14end)Ends the server callback function definition.

NEXT

NodeMCU Get Start
NodeMCU Build Firmware
NodeMCU Flash Firmware
NodeMCU IDE
ESP8266 NodeMCU Modules
NodeMCU Module–Firmware Info
NodeMCU Module – GPIO
NodeMCU Module – Node
NodeMCU Module – WiFi
NodeMCU Module – Timer
NodeMCU Module – I2C
NodeMCU Module – File
NodeMCU Module – NET
NodeMCU Module – HTTP
NodeMCU Module – MQTT
ESP8266 NodeMCU Interface
NodeMCU Interface LED
NodeMCU Interface Button
NodeMCU Interface 7 Seg
NodeMCU Interface LCD
NodeMCU Interface ADC
NodeMCU Interface DHT11
NodeMCU Interface MCP23008
NodeMCU Interface MCP23017
NodeMCU Interface ADXL345
NodeMCU Interface DS18B20
ESP8266 NodeMCU Tutorials
NodeMCU Tutorials Google Time
NodeMCU Tutorials WebServer
ESP8266 NodeMCU Projects
Imperial March Ringtone Play
WiFi Router Status Indicator
ESP8266 Home Automation
Others
NodeMCU All Post
Sitemap

ESP8266 NodeMCU Module – WiFi (End User Module)

Welcome to the ESP8266 NodeMCU WiFi End User Module! The ESP8266 NodeMCU is a versatile and powerful microcontroller board that features built-in WiFi connectivity. This module aims to offer a user-friendly platform for IoT (Internet of Things) projects, facilitating the connection of devices to the Internet and enabling remote interaction with them.

With the ESP8266 NodeMCU, you can quickly prototype and deploy WiFi-enabled projects without the need for extensive hardware or networking expertise. Whether you’re a hobbyist, maker, or professional developer, this module offers a convenient solution for adding wireless connectivity to your applications.

Read more: ESP8266 NodeMCU Module – WiFi (End User Module)

WiFi NodeMCU Lua Module

In this module, we’ll explore the capabilities of the ESP8266 NodeMCU, learn how to configure WiFi settings, connect to wireless networks, and develop IoT applications. By the end of this module, you’ll have the knowledge and skills to create your own WiFi-enabled projects using the ESP8266 NodeMCU.

Let’s dive into the world of WiFi and IoT with the ESP8266 NodeMCU End User Module!

This table provides a comprehensive overview of the various functions available for configuring and interacting with WiFi on the ESP8266 module.

Note: ESP8266 does not support numbers as passwords in NodeMCU firmware

General Functions:

FunctionDescription
wifi.getchannel()Gets the current WiFi channel.
wifi.getdefaultmode()Gets default WiFi operation mode.
wifi.getmode()Gets WiFi operation mode.
wifi.getphymode()Gets WiFi physical mode.
wifi.nullmodesleep()Configures whether or not WiFi automatically goes to sleep in NULL_MODE.
wifi.resume()Wake up WiFi from suspended state or cancel pending wifi suspension.
wifi.setmode()Configures the WiFi mode to use.
wifi.setphymode()Sets WiFi physical mode.
wifi.startsmart()Starts auto configuration, if successful sets up SSID and password automatically.
wifi.stopsmart()Stops the smart configuring process.
wifi.suspend()Suspend Wifi to reduce current consumption.
wifi.eventmon.register()Register/unregister callbacks for WiFi event monitor.
wifi.eventmon.unregister()Unregister callbacks for WiFi event monitor.
wifi.eventmon.reasonTable containing disconnect reasons.

Station Functions:

FunctionDescription
wifi.sta.autoconnect()Auto connects to AP in station mode.
wifi.sta.changeap()Select Access Point from list returned by wifi.
wifi.sta.clearconfig()Clears the currently saved WiFi station configuration, erasing it from the flash.
wifi.sta.config()Sets the WiFi station configuration.
wifi.sta.connect()Connects to the configured AP in station mode.
wifi.sta.disconnect()Disconnects from AP in station mode.
wifi.sta.eventMonReg()Registers callbacks for WiFi station status events.
wifi.sta.eventMonStart()Starts WiFi station event monitor.
wifi.sta.eventMonStop()Stops WiFi station event monitor.
wifi.sta.getap()Scans AP list as a Lua table into callback function.
wifi.sta.getapindex()Get index of current Access Point stored in AP cache.
wifi.sta.getapinfo()Get information of APs cached by ESP8266 station.
wifi.sta.getbroadcast()Gets the broadcast address in station mode.
wifi.sta.getconfig()Gets the WiFi station configuration.
wifi.sta.getdefaultconfig()Gets the default WiFi station configuration stored in flash.
wifi.sta.gethostname()Gets current station hostname.
wifi.sta.getip()Gets IP address, netmask, and gateway address in station mode.
wifi.sta.getmac()Gets MAC address in station mode.
wifi.sta.getrssi()Gets the RSSI (Received Signal Strength Indicator) of the Access Point which ESP8266 station connected to.
wifi.sta.setaplimit()Set Maximum number of Access Points to store in flash.
wifi.sta.sethostname()Sets station hostname.
wifi.sta.setip()Sets IP address, netmask, gateway address in station mode.
wifi.sta.setmac()Sets MAC address in station mode.
wifi.sta.sleeptype()Configures the WiFi modem sleep type to be used while station is connected to an Access Point.
wifi.sta.status()Gets the current status in station mode.

Access Point Functions:

FunctionDescription
wifi.ap.config()Sets SSID and password in AP mode.
wifi.ap.deauth()Deauths (forcibly removes) a client from the ESP access point by sending a corresponding IEEE802.
wifi.ap.getbroadcast()Gets broadcast address in AP mode.
wifi.ap.getclient()Gets table of clients connected to device in AP mode.
wifi.ap.getconfig()Gets the current SoftAP configuration.
wifi.ap.getdefaultconfig()Gets the default SoftAP configuration stored in flash.
wifi.ap.getip()Gets IP address, netmask and gateway in AP mode.
wifi.ap.getmac()Gets MAC address in AP mode.
wifi.ap.setip()Sets IP address, netmask and gateway address in AP mode.
wifi.ap.setmac()Sets MAC address in AP mode.
wifi.ap.dhcp.config()Configure the DHCP service.
wifi.ap.dhcp.start()Starts the DHCP service.
wifi.ap.dhcp.stop()Stops the DHCP service.
wifi.eventmon.register()Register/unregister callbacks for WiFi event monitor.
wifi.eventmon.unregister()Unregister callbacks for

Examples

Scan for available all station networks

  • Scans AP list as a Lua table into callback function. wifi.sta.getap()

This Lua code includes various functions related to scanning and retrieving information about available WiFi access points (APs) and their configurations. Each function defines itself separately for different purposes and formats itself for readability.

-- Print AP list in old format (format not defined)
function listap(t)
    for k, v in pairs(t) do
        print(k .. " : " .. v)
    end
end

wifi.sta.getap(listap)

-- Print AP list that is easier to read
function listap(t)
    -- (SSID : Authmode, RSSI, BSSID, Channel)
    print("\n" .. string.format("%32s", "SSID") .. "\tBSSID\t\t\t\t RSSI\t\tAUTHMODE\tCHANNEL")
    for ssid, v in pairs(t) do
        local authmode, rssi, bssid, channel = string.match(v, "([^,]+),([^,]+),([^,]+),([^,]+)")
        print(string.format("%32s", ssid) .. "\t" .. bssid .. "\t " .. rssi .. "\t\t" .. authmode .. "\t\t\t" .. channel)
    end
end

wifi.sta.getap(listap)

-- Print AP list in new format
function listap(t)
    for k, v in pairs(t) do
        print(k .. " : " .. v)
    end
end

wifi.sta.getap(1, listap)

-- Print AP list that is easier to read
function listap(t)
    -- (SSID : Authmode, RSSI, BSSID, Channel)
    print("\n\t\t\tSSID\t\t\t\t\tBSSID\t\t\t RSSI\t\tAUTHMODE\t\tCHANNEL")
    for bssid, v in pairs(t) do
        local ssid, rssi, authmode, channel = string.match(v, "([^,]+),([^,]+),([^,]+),([^,]*)")
        print(string.format("%32s", ssid) .. "\t" .. bssid .. "\t " .. rssi .. "\t\t" .. authmode .. "\t\t\t" .. channel)
    end
end

wifi.sta.getap(1, listap)

-- Check for specific AP
function listap(t)
    print("\n\t\t\tSSID\t\t\t\t\tBSSID\t\t\t RSSI\t\tAUTHMODE\t\tCHANNEL")
    for bssid, v in pairs(t) do
        local ssid, rssi, authmode, channel = string.match(v, "([^,]+),([^,]+),([^,]+),([^,]*)")
        print(string.format("%32s", ssid) .. "\t" .. bssid .. "\t " .. rssi .. "\t\t" .. authmode .. "\t\t\t" .. channel)
    end
end

scan_cfg = {}
scan_cfg.ssid = "myssid"
scan_cfg.bssid = "AA:AA:AA:AA:AA:AA"
scan_cfg.channel = 0
scan_cfg.show_hidden = 1

wifi.sta.getap(scan_cfg, 1, listap)

-- Get RSSI for currently configured AP
function listap(t)
    for bssid, v in pairs(t) do
        local ssid, rssi, authmode, channel = string.match(v, "([^,]+),([^,]+),([^,]+),([^,]*)")
        print("CURRENT RSSI IS: " .. rssi)
    end
end

ssid, tmp, bssid_set, bssid = wifi.sta.getconfig()

scan_cfg = {}
scan_cfg.ssid = ssid

if bssid_set == 1 then
    scan_cfg.bssid = bssid
else
    scan_cfg.bssid = nil
end

scan_cfg.channel = wifi.getchannel()
scan_cfg.show_hidden = 0

ssid, tmp, bssid_set, bssid = nil, nil, nil, nil

wifi.sta.getap(scan_cfg, 1, listap)

Sets the WiFi station configuration.

This Lua code demonstrates various configurations for connecting the ESP8266 to an access point (AP) using the wifi.sta.config() function. You can choose whether to save the configuration to flash memory, specify a MAC address for the AP, or configure the station without immediately connecting to an AP.

-- Connect to Access Point (DO NOT save config to flash)
station_cfg = {}
station_cfg.ssid = "NODE-AABBCC"
station_cfg.pwd = "password"
wifi.sta.config(station_cfg)

-- Connect to Access Point (DO save config to flash)
station_cfg = {}
station_cfg.ssid = "NODE-AABBCC"
station_cfg.pwd = "password"
station_cfg.save = true
wifi.sta.config(station_cfg)

-- Connect to Access Point with specific MAC address
station_cfg = {}
station_cfg.ssid = "NODE-AABBCC"
station_cfg.pwd = "password"
station_cfg.bssid = "AA:BB:CC:DD:EE:FF"
wifi.sta.config(station_cfg)

-- Configure station but don't connect to Access point
station_cfg = {}
station_cfg.ssid = "NODE-AABBCC"
station_cfg.pwd = "password"
station_cfg.auto = false
wifi.sta.config(station_cfg)

Connect ESP8266 to WiFi Router

This Lua code initializes the WiFi module, sets it to both station and access point mode, and then connects to a specified access point with the provided SSID and password without saving the configuration to flash memory.

print("wifi init")
wifi.set.mode(wifi.STATIONAP)

-- Connect to Access Point (DO NOT save config to flash)
station_cfg = {}
station_cfg.ssid = "ArunEworld"
station_cfg.pwd = "Arun"
wifi.sta.config(station_cfg)
wifi.sta.connect()

Disconnect ESP8266 from WiFi Router

  • Disconnects from AP in station mode. wifi.sta.disconnect()

View the ESP8266 Stored Access Point information

  • Retrieve information about the Access Points cached by the ESP8266 station using the function wifi.sta.getapinfo().

This Lua code prints the stored access point information obtained from the ESP8266 module in both a non-formatted and formatted manner.

-- Print stored access point info
do
    for k, v in pairs(wifi.sta.getapinfo()) do
        if (type(v) == "table") then
            print(" " .. k .. " : " .. type(v))
            for k, v in pairs(v) do
                print("\t\t" .. k .. " : " .. v)
            end
        else
            print(" " .. k .. " : " .. v)
        end
    end
end

-- Print stored access point info (formatted)
do
    local x = wifi.sta.getapinfo()
    local y = wifi.sta.getapindex()
    print("\n Number of APs stored in flash:", x.qty)
    print(string.format(" %-6s %-32s %-64s %-18s", "index:", "SSID:", "Password:", "BSSID:"))
    for i = 1, x.qty, 1 do
        print(string.format(" %s%-6d %-32s %-64s %-18s", (i == y and ">" or " "), i, x[i].ssid, x[i].pwd and x[i].pwd or type(nil), x[i].bssid and x[i].bssid or type(nil)))
    end
end

Gets the WiFi station configuration.

This Lua code retrieves and prints the current station configuration of the ESP8266 module, both in new and old formats. It displays the SSID, password, and BSSID settings if available.

-- Get current Station configuration (NEW FORMAT)
do
    local def_sta_config = wifi.sta.getconfig(true)
    print(string.format("\tDefault station config\n\tssid:\"%s\"\tpassword:\"%s\"%s",
        def_sta_config.ssid, def_sta_config.pwd,
        (type(def_sta_config.bssid) == "string" and "\tbssid:\"" .. def_sta_config.bssid .. "\"" or "")))
end

-- Get current Station configuration (OLD FORMAT)
ssid, password, bssid_set, bssid = wifi.sta.getconfig()
print("\nCurrent Station configuration:\nSSID : " .. ssid .. "\nPassword : " .. password ..
    "\nBSSID_set : " .. bssid_set .. "\nBSSID: " .. bssid .. "\n")
ssid, password, bssid_set, bssid = nil, nil, nil, nil

Clears the currently saved WiFi station configuration

  • Clears the currently saved WiFi station configuration, erasing it from the flash. This action may be useful for certain factory-reset scenarios when a full node.restore() is not desired, or to prepare for using End-User Setup so that the SoftAP can lock onto a single hardware radio channel.
  • Ex : wifi.sta.clearconfig()

WiFi station status events

This Lua code registers event callbacks for various WiFi states, starts and stops the WiFi event monitor with different intervals, and unregisters callbacks as needed.

-- Register callbacks
wifi.sta.eventMonReg(wifi.STA_IDLE, function() print("STATION_IDLE") end)
wifi.sta.eventMonReg(wifi.STA_CONNECTING, function() print("STATION_CONNECTING") end)
wifi.sta.eventMonReg(wifi.STA_WRONGPWD, function() print("STATION_WRONG_PASSWORD") end)
wifi.sta.eventMonReg(wifi.STA_APNOTFOUND, function() print("STATION_NO_AP_FOUND") end)
wifi.sta.eventMonReg(wifi.STA_FAIL, function() print("STATION_CONNECT_FAIL") end)
wifi.sta.eventMonReg(wifi.STA_GOTIP, function() print("STATION_GOT_IP") end)

-- Register callback: use previous state
wifi.sta.eventMonReg(wifi.STA_CONNECTING, function(previous_State)
    if (previous_State == wifi.STA_GOTIP) then
        print("Station lost connection with access point\n\tAttempting to reconnect...")
    else
        print("STATION_CONNECTING")
    end
end)

-- Start WiFi event monitor with default interval
wifi.sta.eventMonStart()

-- Start WiFi event monitor with 100ms interval
wifi.sta.eventMonStart(100)

-- Stop WiFi event monitor
wifi.sta.eventMonStop()

-- Stop WiFi event monitor and unregister all callbacks
wifi.sta.eventMonStop(1)

-- Unregister callback
wifi.sta.eventMonReg(wifi.STA_IDLE)

Gets current station hostname.

  • Ex : print(“Current hostname is: \””..wifi.sta.gethostname()..”\””)

Sets station hostname.

This Lua code checks if the hostname was successfully changed using the wifi.sta.sethostname() function and prints the corresponding message.

if (wifi.sta.sethostname("ArunEworld") == true) then
    print("hostname was successfully changed")
else
    print("hostname was not changed")
end

Gets IP address, netmask, and gateway address in station mode.

This Lua code retrieves and prints the current IP address, netmask, and gateway information using the wifi.sta.getip() function. It demonstrates different ways to handle the returned values.

-- Print current IP address, netmask, gateway
print(wifi.sta.getip()) -- Output: 192.168.0.111 255.255.255.0 192.168.0.1

ip = wifi.sta.getip()
print(ip) -- Output: 192.168.0.111

ip, nm = wifi.sta.getip()
print(nm) -- Output: 255.255.255.0

Gets IP address, netmask and gateway in AP mode.

This Lua code retrieves and prints the current IP address, netmask, and gateway information for the Access Point (AP) mode using the wifi.ap.getip() function. It demonstrates different ways to handle the returned values.

-- Print current IP address, netmask, gateway
print(wifi.ap.getip()) -- Output: 192.168.4.1 255.255.255.0 192.168.4.1

ip = wifi.ap.getip()
print(ip) -- Output: 192.168.4.1

ip, nm = wifi.ap.getip()
print(nm) -- Output: 255.255.255.0

ip, nm, gw = wifi.ap.getip()
print(gw) -- Output: 192.168.4.1

Gets MAC address in station mode.

  • Ex : print(wifi.sta.getmac())

Set MAC address in AP mode.

  • Ex : print(wifi.ap.setmac())

Retrieve the RSSI (Received Signal Strength Indicator).

  • Retrieve the RSSI (Received Signal Strength Indicator) from the Access Point to which the ESP8266 station is currently connected.

RSSI=wifi.sta.getrssi() print(“RSSI is”, RSSI)

Retrieves a table of clients connected to the device in AP mode.

This Lua code retrieves the client MAC addresses and IPs connected to the Access Point (AP) and prints them. It demonstrates two ways to iterate over the table returned by wifi.ap.getclient().

-- Get client MAC addresses and IPs connected to the AP
table = wifi.ap.getclient()

-- Iterate over the table to print MAC addresses and IPs
for mac, ip in pairs(table) do
    print(mac, ip)
end

-- Alternatively, using a shorter loop syntax
for mac, ip in pairs(wifi.ap.getclient()) do
    print(mac, ip)
end

Gets the current SoftAP configuration.

This Lua code retrieves and prints the SoftAP configuration in both new and old formats. It demonstrates two different ways of handling the configuration data returned by wifi.ap.getconfig().

-- Get SoftAP configuration table (NEW FORMAT)
do
    print("\n Current SoftAP configuration:")
    for k, v in pairs(wifi.ap.getconfig(true)) do
        print(" "..k.." :", v)
    end
end

-- Get current SoftAP configuration (OLD FORMAT)
do
    local ssid, password = wifi.ap.getconfig()
    print("\n Current SoftAP configuration:\n SSID : "..ssid.. "\n Password :", password)
    ssid, password = nil, nil
end

Retrieve the default SoftAP configuration stored in flash.

This Lua code retrieves and prints the default SoftAP configuration in both new and old formats. It demonstrates two different ways of handling the configuration data returned by wifi.ap.getdefaultconfig().

-- Get default SoftAP configuration table (NEW FORMAT)
do
    print("\n Default SoftAP configuration:")
    for k, v in pairs(wifi.ap.getdefaultconfig(true)) do
        print(" "..k.." :", v)
    end
end

-- Get default SoftAP configuration (OLD FORMAT)
do
    local ssid, password = wifi.ap.getdefaultconfig()
    print("\n Default SoftAP configuration:\n SSID : "..ssid.. "\n Password :", password)
    ssid, password = nil, nil
end

End User Setup NodeMCU Lua

ESP8266 NodeMCU WiFi End User Module

FunctionDescription
enduser_setup.manual()Controls whether manual AP configuration is used.
enduser_setup.start()Starts the captive portal.
enduser_setup.stop()Stops the captive portal.

Example

This Lua code sets up the ESP8266 to operate in both station and access point modes, configures the access point with the SSID “ArunEworld” and no password (open authentication), enables manual end-user setup, and starts the setup process with callbacks for success and failure.

//Configure the End User Setup
wifi.setmode(wifi.STATIONAP)
wifi.ap.config({ ssid = "ArunEworld", auth = wifi.OPEN })

enduser_setup.manual(true)
enduser_setup.start(
    function()
        print("Connected to wifi as: " .. wifi.sta.getip())
        --enduser_setup.stop()
    end,
    function(err, str)
        print("enduser_setup: Err #" .. err .. ": " .. str)
    end
);

NEXT

NodeMCU Get Start
NodeMCU Build Firmware
NodeMCU Flash Firmware
NodeMCU IDE
ESP8266 NodeMCU Modules
NodeMCU Module–Firmware Info
NodeMCU Module – GPIO
NodeMCU Module – Node
NodeMCU Module – WiFi
NodeMCU Module – Timer
NodeMCU Module – I2C
NodeMCU Module – File
NodeMCU Module – NET
NodeMCU Module – HTTP
NodeMCU Module – MQTT
ESP8266 NodeMCU Interface
NodeMCU Interface LED
NodeMCU Interface Button
NodeMCU Interface 7 Seg
NodeMCU Interface LCD
NodeMCU Interface ADC
NodeMCU Interface DHT11
NodeMCU Interface MCP23008
NodeMCU Interface MCP23017
NodeMCU Interface ADXL345
NodeMCU Interface DS18B20
ESP8266 NodeMCU Tutorials
NodeMCU Tutorials Google Time
NodeMCU Tutorials WebServer
ESP8266 NodeMCU Projects
Imperial March Ringtone Play
WiFi Router Status Indicator
ESP8266 Home Automation
Others
NodeMCU All Post
Sitemap

ESP8266 Arduino-Core Cayenne – Get Start with Cayenne MyDevice

What is Cayenne MyDevice?

myDevices Cayenne allows you to quickly design, prototype, and visualize IoT solutions. You can use Cayenne as a tool to visualize real-time and historical data, sent over to The Things Network. Let’s discuss “ESP8266 Arduino-Core Cayenne – Get Start with Cayenne MyDevice

Cayenne is a platform for building IoT (Internet of Things) projects that provides tools for creating dashboards, monitoring devices, and controlling connected devices remotely. The Cayenne platform supports various microcontrollers and single-board computers, including the ESP8266, through the use of Cayenne MQTT or Cayenne MQTT API.

Read more… →

ESP8266 NodeMCU – Getting Started

NodeMCU Introduction

    ESP8266 NodeMCU Platform is really very good platform for beginners, you don’t need to remember all ESP8266 registers, address, and so on. You just call the lua function and make your DIY application very quick and easily. Frequently updating thier firmware based on new sensors, and many interfaces. Here below discussed many things and you can lean all the followings

FAQ,

  • what are the different IDE’s are available for ESP8266 NodeMCU Platform?
  • How to build a firmware for ESP8266?
  • How to upload the firmware in to ESP8266 chip?
  • Hello world examples : Printing letters in Serial (UART) and LED Blink.
  • Reference Links

Read more… →

ESP8266 – Programmer and Flasher IDE

The programmer also in-builds design when you buy a NodeMCU Dev board, Sparkfun Thing Dev Board, and some other boards. Three more ways to program and flash firmware to ESP8266. Mostly using CP2102 USB-TTL UART or PL2303 USB-TTL programmer. you can use your Arduino board as an ESP8266 programmer. But you can also use your Arduino board as an ESP8266 Programmer (like another Programmer).

Ai-thinkers Modules: Ai-Thinkers modules are designed with external flash memory. so need a serial programmer to upload and flash the program into it. you can use any one of the serial USB to UART programmer.

Read more… →

ESP8266 – How to build and flash firmware?

ESP8266 Build and flash the firmware is a very easy job. before that, you need to choose the correct esp8266 platform (Arduino Core, AT Command, NodeMCU, Mangoes OS, Micro-python) for your requirements. First, you should know,

  • What is esp8266 firmware? esp8266 Firmware contains a collection of library files or binary files.
  • Why need to flash Firmware into esp8266? like when we think, we can’t able to write all the code ourselves. so we will follow some open source. if you use open source you need to flash the selected open source library file into esp8266 before starting your application.
Read more… →

ESP8266 – Boards Types

The ESP8266 is a popular Wi-Fi module that enables microcontrollers to connect to Wi-Fi networks and communicate with the Internet. Nowadays this wifi chip-based various kinds of modules are available, we are discussing ESP8266 Boards Types and those specifications, which you can select for your requirements.

ESPressif ESP-WROOM Modules

The ESP-WROOM-x is a module developed by Espressif. Four different types of ESP WROOM Modules are available.

  • All the board’s pitch is 1.5mm.
  • All the Boards are shielded.
  • All the Boards do not have LEDs.
ESPressif ESP-WROOM Modules List

ESP-WROOM-02

ESP-WROOM-02 Front View
Front View
ESP-WROOM-02 Back View
Back View
  • Fully Certified: Wi-Fi Alliance, SRRC, FCC, CE, TELEC, IC & KCC Certified
  • Interfaces: Network Communication Protocol: TCP/IP network stacks,
  • Interfaces: Wired Communication Protocols: HSPI, UART, PWM, I2C, I2S
  • Fully Certified: RoHS, Halogen Free, REACH & CFSI Compliant
  • Fully Certified: HTOL, ESD-HM, MSL, μHAST, HTSL
  • Fully Certified: Output Power: +22dBm peak power in FCC certification
  • This Module can be easily integrated into space-limited devices, it’s small size.
  • PCB Design and Module Placement Guide
  • Data Sheet:

ESP WROOM-S2

  • The ESP-WROOM-S2 is part of the ESP32 series, which is a family of low-cost, low-power system-on-chip (SoC) microcontrollers with integrated Wi-Fi and Bluetooth capabilities.
  • Dual-Core Processor: Xtensa LX6 processor,
  • Peripheral Interfaces: GPIO pins, I2C, SPI, UART, and more
  • Datasheets by Espressif for ESP-WROOM-S2

 Ai-Thinker’s ESP8266 Modules

The AI-Thinker modules are sequentially labeled ESP-01 through ESP-13. NodeMCU boards extend upon the AI-Thinker modules. Here below tables about”Summary of All AI-Tinkers ESP8266 Module Boards”

Summary of All AI-Tinkers ESP8266 Module Boards

ESP-01

  • PCB Antenna, through matching, distance open 400 Meters, easy to use
  • This Module does not Support PWM hardware.
  • You can able to use the software PWM feature in the “NodeMCU” Platform.
ESP-01 Front View (Black Board)
ESP-01 Back View (Blackboard)
ESP-01 Front View (Blue Board)

ESP-02

ESP-02 Front View
  • SMD package for the commit limit, the antenna can be used IPX End leading housing.
ESP-02 Back View

ESP-03

ESP-03 Front View
  • SMD package,
  • Built-in ceramic antenna technology
  • All available IO Leads.
ESP-03 Back View

ESP-04

ESP-04 Front View
  • SMD package
  • Customers can custom antenna types
  • Flexible design and all available IO Leads.
ESP-04 Back View

ESP-05

ESP-05 Front View
  • SMD package,
  • Only leads to serial RST Feet,
  • Small size,
  • External antenna.

ESP-06

ESP-06 Front View
  • Bottom mount technology
  • All IO Mouth leads with metal shielding shell, can be had FCC CE Certification is recommended.
ESP-06 Back View

ESP-07

ESP-07 Front View
  • Half-hole chip technology,
  • All IO Leads with metal shielding shell,
  • Can be had FCE Certification,
  • External IPX Antenna,
  • The built-in ceramic antenna can be used.
ESP-07 Back View

ESP-07S

ESP-07S Front View

Same ESP-07 with 4MB Flash

  • Size 16mm*17mm*3mm
  • Pads:1mmx1.2mm
  • Pads Spacing: 2mm
ESP-07S Back View

ESP-08

ESP-08 Front View

With ESP-07 the antenna customers can define their form.

ESP-08 Back View

ESP-09

ESP-09 Front View
  • Ultra-small size package
  • Only 10 * 10 Mm
  • Four-layer board technology
  • 1M byte.
ESP-09 Back View

ESP-10

ESP-10 Front View
ESP-10 Back View

ESP-11

ESP-11 Front View
  • Chip interfaces
  • Ceramic antenna
  • Small volume.
ESP-11 Back View

ESP-12

  • Semi-hole patch process, all IO Leads, with metal shielding shell, passed FCE Certification, built PCB On board antenna, 4M byte Flash.

ESP-12E

ESP-12E Front View
  • On the top of the ESP-12 leads to 6 feet and more
  • Greatly enhanced anti-jamming capability,
  • The main recommendation of this section!

ESP-12F

ESP-12S

  • ESP-12S Datasheet
  • Size: 24mm*16mm*3mm, Weight: 0.01kg.
  • 16pins count based On ESP8266 WiFi IC
  • Fully compatible with forecast version ESP-12E or ESP12F
  • FCC and CE & RHOS all passed
  • Improved antenna design
  • Better signal performance
  • Note: ESP-12S does not have an SPI pin at the bottom of the board

ESP-13

The 4-layer design, semi-hole chip technology, all IO leads, with metal shielding shell, the antenna redesigned, RF performance!

ESP-14

  • In ESP-12E prototype design,
  • Interior adds STM8S003F3P6, and by STM8S ESP8266 AT commands to control the module is a complete STM8S micro-controller can operate via WIFI STM8 micro-controller programming.

NodeMCU DEVKIT

  • ESP8266 NodeMCU Dev has an Ai-thinkers ESP8266 module on it
  • The module comes with the latest version of AT Firmware.
  • Make sure to refer to the image above to determine which pins are which On top it has a micro-USB socket, for connecting to the computer.
  • Next to it are two buttons, one for reset and one for flashing.

NodeMCU DevKit Pin Details

ESP8266 NodeMCU DEv Board Pin Details

The other pins are used internally by the board, and we will not be connecting anything to them.

Difference in Ai Thinker’s ESP8266 Boards

Difference Between ESP-01 Blue Board and ESP-01S Black Board

Memory Flash Size is differ

  • ESP-01 Blue Board – 500Kb
  • ESP-01S Black Board – 1Mb

Difference Between ESP-07 and ESP-07S?

  • PCB Layers
    • ESP-07S – 4 Layers of PCB
    • ESP-07 – 2 Layer of PCB
  • Flash Memory
    • ESP-07S – 4M
    • ESP-07 – 1M
  • IPEX Connector and Ceramic Antenna
    • ESP-07S – Only have IPEX Connector and not have ceramic antenna
    • ESP-07 – Have IPEX Connector and ceramic antenna
  • Certification
    • ESP-07S -Have FCC, CE, ROSH Certification
    • ESP-07 – 1M – Not have certification
  • Note :
    •  ESP-07S is upgraded from ESP-07.
    • Both are same pins

Difference Between ESP-12E and ESP12F?

  • Please refer to the antenna design in the below ESP-12E and ESP-12F images.
  • PCB Layers
    • ESP-12F – 4 Layers of PCB
    • ESP-12E – 2 Layer of PCB
  • Certification
    • ESP-12F -Have FCC, CE, ROSH Certification
    • ESP-12E – 1M – Not have certification
  • Note
    • ESP-12F is upgraded from ESP-12E.
    • Both are the same pins

Olimex ESP8266 Module

Olimex provides two different types of ESP8266-based boards.

The below list is common for both boards

  • Both boards of the Main chip are EPS8266 from ESPressif
  • 2MB (16MB) SPI Flash Memory
  • Power LED
  • User-programmable LED
  • SMT jumpers for different boot modes (FLASH, UART, SDO)
  • PCB antenna
  • OSHW design
  • Pads for a U.FL antenna connector (if you want to use an external antenna)

The below table about differences between Olimex MOD_WIFI-ESP8266 and DEV Boards

Differences between Olimex MOD_WIFI-ESP8266 and DEV Boards
Olimex MOD-WIFI-ESP8266
Olimex MOD-WIFI-ESP8266-DEV


Adafruit Huzzah ESP8266 Modules

Adafruits has two diffrent ESp8266 Boards “Adafruit Feather HUZZAH with ESP8266” and “Adafruit HUZZAH ESP8266 Breakout”. The Below list is common specs for both boards

  • Reset button
  • 9 x GPIO (3.3V logic), which can be used for I2C or SPI
  • 1 x Analog input (1.0V max)

Adafruit Feather HUZZAH with ESP8266

It’s along with Ai-Thinker’s boards

  • Measures 2.0″ x 0.9″ x 0.28″ (51mm x 23mm x 8mm) without headers soldered-in
  • Light as a (large?) feather – 9.7 grams
  • 3.3V regulator with 500mA peak current output
  • CP2104 USB-Serial converter onboard with 921600 max baud rate for speedy uploading
  • Auto-reset support for getting into bootloader mode.
  • Built-in 100mA LiPoly charger pin available. Charging Status indicator LED is available. This can cut a trace to disable the charger.
  • Pin #0 red LED for general purpose blinking.
  • Pin #2 blue LED for boot loading debug & general purpose blinking
  • Power/enable pin
  • 4 mounting holes

Adafruit HUZZAH ESP8266 Breakout

Its Just breakout board on top of the Ai-Thinker’s boards

  • 3.3V out, 500mA regulator (you need to assume the ESP8266 can draw up to 250mA.)
  • User button that can use the chip in bootloader mode,
  • Red LED you can blink
  • Level shifting on the UART and resetting the pin
  • Two diode-protected power inputs (USB cable and battery)
  • Two parallel, breadboard-friendly breakouts on either side give you access to: 2 x UART pins and 2 x 3-6V power inputs, reset, enable, LDO-disable, 3.3V output

SparkFun ESP8266 Boards

SparkFun ESP8266 Thing

  • All module pins breakout
  • On-board LiPo charger/power supply
  • 802.11 b/g/n
  • Wi-Fi Direct (P2P), soft-AP
  • Integrated TCP/IP protocol stack
  • Integrated TR switch, balun, LNA, power amplifier, and matching network
  • Integrated PLLs, regulators, DCXO, and power management units
  • Integrated low-power 32-bit CPU could be used as an application processor
  • +19.5dBm output power in 802.11b mode

SparkFun WiFi Shield – ESP8266

  • Arduino R3 Layout
  • 802.11 b/g/n
  • Wi-Fi Direct (P2P), soft-AP
  • Integrated TCP/IP protocol stack
  • Integrated TR switch, balun, LNA, power amplifier, and matching network
  • Integrated PLLs, regulators, DCXO, and power management units
  • Integrated low-power 32-bit CPU could be used as an application processor
  • +19.5dBm output power in 802.11b mode

Other ESP8266 Boards

KNEWRON Technologies smartWIF

  • Arduino-like hardware IO: The board allows you to code like Arduino in an interactive manner with Lua scripting language.
  • NodeJS style network API: The firmware provides event-driven API for network applications, which facilitates developers writing code running this tiny little board in NodeJS style. Greatly speed up your Wi-Fi / IOT application development process.
  • Reprogramming possibility: The IO button available on the kit also functions as a re-flashing button.
  • Multiple uses: serial to USB converter as well as 3.7V LiPo battery charger.

WeMos

These WeMos boards work with Arduino and NodeMCU firmware

WEMos D1 Mini

  • 11 digital IO, interrupt/PWM/I2C/one-wire supported(except D0)
  • 1 analog input(3.2V max input)
  • Type-C USB Port
  • LOLIN I2C Port
  • Compatible with MicroPython, Arduino, nodemcu

WEMos D1 mini Pro

  • 11 digital input/output pins
  • Interrupt/pwm/I2C/one-wire
  • 1 analog input(3.2V max input)
  • 16M bytes(128M bit) Flash
  • External antenna connector
  • Built-in PCB antenna
  • Lithium battery interface, 500mA Max charging current
  • LOLIN I2C Port
  • Compatible with Arduino, MicroPython, NodeMCU
  • Default firmware: latest MicroPython

WEMos D1 mini Lite

  • 11 digital IO, interrupt/pwm/I2C/one-wire supported(except D0)
  • 1 analog input(3.2V max input)
  • a Micro USB connection
  • 1M Bytes FLASH inside
  • Compatible with MicroPython, Arduino, nodemcu

Sweetpea ESP-210 Module

  • Flash 4MB
  • Total Pins 14
  • Programmable Pins 11


Wireless-Tag

WT8266-S1
WT8266-S1
WT8266-DK V2
WT8266-S2
WT8266-DK

Next Topic

More Topics

ESP8266 Get Start
ESP8266 Various Boards
ESP8266 Programming Methods
ESP8266 Various Programmer
ESP8266 Build&Flash Firmware
ESP8266 Resource
ESP8266 FQA
ESP8266 MQTT broker BONDAR.
ESP8266 Platforms
ESP8266 Arduino-Core
ESP8266 AT-Commands
ESP8266 Mongoose OS
ESP8266 NodeMCU
Others
ESP8266 Sitemap
ESP8266 All post

ESP8266 – Resource

ESP8266 Resources : Here you can get all resources of ESP8266 Books and useful website. Keep learn about ESP8266 using this blog. Everyday updating new projects and tutorials about ESP8266 so keep on this site .


ESP8266 Books

Useful Links

 

Agus Kurniawan : SparkFun ESP8266 Thing Development Workshop

 

: MicroPython for ESP8266 Development Workshop

 

Agus Kurniawan : NodeMCU Development Workshop

 

 

Kolban’s book on ESP32 –

 

Kolban’s Book on the ESP32 & ESP8266

 

Marco Schwartz : Home Automation With The Esp8266

 

 


Websites


Next topic

ESP8266 Get Start
ESP8266 Various Boards
ESP8266 Programming Methods
ESP8266 Various Programmer
ESP8266 Build&Flash Firmware
ESP8266 Resource
ESP8266 FQA
ESP8266 MQTT broker BONDAR.
ESP8266 Platforms
ESP8266 Arduino-Core
ESP8266 AT-Commands
ESP8266 Mongoose OS
ESP8266 NodeMCU
Others
ESP8266 Sitemap
ESP8266 All post


 

ESP8266 – Platforms

ESP8266 is a powerful microcontroller with built-in Wi-Fi. You can program the ESP8266 using various languages such as C, C++, Lua, MicroPython, JavaScript, and AT Command as well. It depends on your requirements. If you are a beginner, my suggestion is C++ and Lua. This is because, with the Arduino Core for ESP8266, you can utilize your Arduino C++ library for the ESP8266. Additionally, with the NodeMCU Core for ESP8266, you can use the eLua Embedded Module Library for the ESP8266. These Arduino and Lua methods have a lot of built-in library files, making it easy for beginners and learners. Also will discuss “ESP8266 Platforms”

Read more… →