ESP8266 NodeMCU Module Node
Lua API functions in NodeMCU under the node module. They give you system information and control for the ESP8266. Lets get started ESP8266 NodeMCU Module Node
node.chipid()
Returns the unique Chip ID of your ESP8266 (usually the last 3 bytes of the MAC address).
Example:
print(node.chipid())
Output: 1234567
Useful for uniquely identifying each device in an IoT network.
node.flashid()
Returns the Flash chip ID connected to ESP8266.
Example:
print(node.flashid())
Output: 1458208
Helps verify the flash memory chip type and model.
node.flashsize()
Returns the size of the Flash memory (in bytes).
Example:
print(node.flashsize())
Output: 4194304 → means 4 MB Flash.
Useful to know how much program/data space you have.
node.heap()
Returns the available heap memory (in bytes).
Example:
print(node.heap())
Output: 19792 (bytes free).
Important for memory monitoring → If heap gets too low, device may crash.
node.info()
Returns multiple system details in one go:
- NodeMCU version
- Build date/time
- Chip ID
- Flash size
- Flash ID
- Flash mode
- CPU frequency
Example:
print(node.info())
Output (example):
1 5 4 14307726 4194304 1458400 0 80
(where values correspond to NodeMCU version, build, chip ID, flash size, etc.)
node.restart()
node.restore()
Soft restarts (resets) the ESP8266.
Example:
node.restart()
Equivalent to pressing the reset button on the board.
if(nil == node.restore()) then
print("Systerm restored")
else
print("system not restored")
end
node.setcpufreq()
- Used to set the CPU frequency of the ESP8266.
- Supported values:
node.CPU80MHZ(default)node.CPU160MHZ(for higher performance, but higher power usage).
Example:
print("Before:", node.getcpufreq()) -- Show current frequency
node.setcpufreq(node.CPU160MHZ) -- Set CPU to 160 MHz
print("After:", node.getcpufreq())
Output:
Before: 80 After: 160
Use Case:
- Increase CPU speed when running heavy tasks (encryption, real-time data).
- Keep at 80MHz for low power consumption (battery-powered IoT).
node.random()
- Generates a pseudo-random number.
- Usage:
node.random()→ returns a random 32-bit integer.node.random(max)→ returns between1andmax.node.random(min, max)→ returns betweenminandmax.
Example:
print(node.random()) -- any 32-bit random number print(node.random(10)) -- between 1 and 10 print(node.random(50, 100)) -- between 50 and 100
Use Case:
- Generating random sensor test values.
- Random IDs for messages.
- Security (salts, nonces).
node.task.post()
Used to schedule a task that will run later, after the current task finishes.
It avoids blocking the CPU with heavy operations.
Example:
function task1()
print("Task 1 executed")
end
function task2()
print("Task 2 executed")
end
node.task.post(task1)
node.task.post(task2)
print("Main program")
Output order:
Main program Task 1 executed Task 2 executed
Use Case:
Non-blocking code execution (important for networking on ESP8266).
Break large tasks into smaller pieces to prevent watchdog resets.









You must be logged in to post a comment.