NodeMCU is an open source firmware based on Lua, specifically designed for Espressif’s ESP8266/ESP32 WiFi SOC chips. It uses a modular flash-based SPIFFS file system. NodeMCU is written in C and is based on Espressif’s non-operating system SDK.
Initially, NodeMCU firmware was developed as a companion project for the popular ESP8266-based NodeMCU development module, but it has now become a community-supported project, and the firmware can now run on any ESP module.
NodeMCU Firmware: Lightweight, Flexible, and Powerful
The NodeMCU firmware is known for its lightweight, flexibility, and powerful features, making it the preferred tool for IoT developers.
Here are the key features of the NodeMCU firmware:
-
• Simple and easy-to-use programming for wireless nodes and/or access points: NodeMCU provides a simple programming model that allows you to easily create wireless nodes and/or access points.
-
• Based on Lua 5.1.4 or Lua 5.3: NodeMCU uses the Lua language as its programming language, which is a lightweight and easy-to-learn scripting language.
-
• Asynchronous event-driven programming model: NodeMCU adopts an asynchronous event-driven programming model, allowing you to easily create responsive applications.
-
• Rich modules: NodeMCU provides over 70 built-in C modules and nearly 20 Lua modules to meet various development needs.
-
• Optional floating-point support: NodeMCU provides two versions: one with floating-point support and one with integer support, allowing you to choose the version that best suits your needs.
-
• Latest documentation: NodeMCU provides the latest documentation, making it easy to find any information you need.
-
• LFS support: Since July 2018, NodeMCU has supported Lua Flash Store (LFS), allowing Lua code and its related constant data to be executed directly from flash memory, just like the firmware itself. This enables NodeMCU developers to create applications containing up to 256Kb of Lua code and read-only constants, with all RAM available for read/write data!
Programming Model
The programming model of NodeMCU is similar to Node.js, except that it uses the Lua language. It is asynchronous and event-driven. Therefore, many functions have callback function parameters. Here are some NodeMCU code snippets to help you understand the programming model of NodeMCU. More examples can be found in the /lua_examples folder of the GitHub repository.
-- A simple HTTP server
srv = net.createServer(net.TCP)
srv:listen(80,function(conn)
conn:on("receive",function(sck, payload)
print(payload)
sck:send("HTTP/1.0 200 OK\r\
Content-Type: text/html\r\
\r\
<h1> Hello, NodeMCU.</h1>")
end)
conn:on("sent",function(sck) sck:close()end)
end)
-- Connect to WiFi access point
wifi.setmode(wifi.STATION)
wifi.sta.config{ssid="SSID", pwd="password"}
Documentation
All NodeMCU documentation is stored in the /docs directory of the GitHub repository.
The documentation page includes the following:
-
• How to build the firmware
-
• How to flash the firmware
-
• How to upload code and use the NodeMCU IDE
-
• API documentation for each module
Conclusion
The NodeMCU firmware is a powerful tool that can help you easily build various IoT applications. It is easy to use, flexible, and supports multiple features, making it an excellent choice for IoT developers.
Project address: https://github.com/nodemcu/nodemcu-firmware