Convert Figma logo to code with AI

nodemcu logonodemcu-firmware

Lua based interactive firmware for ESP8266, ESP8285 and ESP32

7,653
3,120
7,653
111

Top Related Projects

Latest ESP8266 SDK based on FreeRTOS, esp-idf style.

16,022

ESP8266 core for Arduino

esp8266 wifi-serial bridge, outbound TCP, and arduino/AVR/LPC/NXP programmer

Free and open (as much as possible) integrated SDK for ESP8266/ESP8285 chips

Open source FreeRTOS-based ESP8266 software framework

Quick Overview

NodeMCU is an open-source firmware and development kit for IoT devices, primarily based on the ESP8266 Wi-Fi SoC. It provides a complete environment for prototyping IoT applications using Lua scripting language, making it easier for developers to create connected devices and applications.

Pros

  • Easy to use with Lua scripting language, lowering the barrier to entry for IoT development
  • Large and active community, providing support and resources
  • Extensive library of modules for various sensors and peripherals
  • Over-the-Air (OTA) update capability for remote firmware updates

Cons

  • Limited resources on ESP8266, which can constrain complex applications
  • Lua language may have a learning curve for developers used to C/C++
  • Performance limitations compared to native C/C++ implementations
  • Some users report occasional stability issues with certain modules

Code Examples

  1. Connecting to Wi-Fi:
wifi.setmode(wifi.STATION)
wifi.sta.config({ssid="YourSSID", pwd="YourPassword"})
wifi.sta.connect()
tmr.create():alarm(1000, tmr.ALARM_AUTO, function()
    if wifi.sta.getip() then
        print("IP: ", wifi.sta.getip())
        tmr.stop()
    end
end)
  1. Reading a DHT22 sensor:
pin = 4
status, temp, humi, temp_dec, humi_dec = dht.read(pin)
if status == dht.OK then
    print("Temperature: "..temp.."."..temp_dec.." C")
    print("Humidity: "..humi.."."..humi_dec.."%")
end
  1. Creating a simple HTTP server:
srv = net.createServer(net.TCP)
srv:listen(80, function(conn)
    conn:on("receive", function(client, request)
        client:send("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<h1>Hello, NodeMCU!</h1>")
    end)
    conn:on("sent", function(client) client:close() end)
end)

Getting Started

  1. Download and flash the NodeMCU firmware to your ESP8266 board.
  2. Install ESPlorer or another Lua editor for NodeMCU.
  3. Connect your board to your computer and open the serial connection.
  4. Write and upload your Lua scripts to the board:
-- Hello World example
print("Hello, NodeMCU!")

-- Blink an LED
pin = 4
gpio.mode(pin, gpio.OUTPUT)
tmr.create():alarm(1000, tmr.ALARM_AUTO, function()
    gpio.write(pin, gpio.read(pin) == gpio.HIGH and gpio.LOW or gpio.HIGH)
end)
  1. Run your scripts and start building your IoT projects!

Competitor Comparisons

Latest ESP8266 SDK based on FreeRTOS, esp-idf style.

Pros of ESP8266_RTOS_SDK

  • Provides a full-fledged RTOS (FreeRTOS) for more complex applications
  • Offers direct access to ESP8266 hardware features and APIs
  • Supports a wider range of development tools and IDEs

Cons of ESP8266_RTOS_SDK

  • Steeper learning curve, especially for beginners
  • Requires more low-level programming knowledge
  • Less extensive community support compared to NodeMCU

Code Comparison

ESP8266_RTOS_SDK:

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"

void app_main()
{
    xTaskCreate(&my_task, "my_task", 2048, NULL, 5, NULL);
}

NodeMCU-firmware:

-- No explicit task creation needed
function init()
    print("Hello, NodeMCU!")
end

-- NodeMCU automatically calls init() on boot

The ESP8266_RTOS_SDK example shows explicit task creation using FreeRTOS, while NodeMCU-firmware abstracts this complexity, allowing for simpler scripting in Lua. ESP8266_RTOS_SDK provides more control but requires more detailed programming, whereas NodeMCU-firmware offers a more accessible approach for rapid prototyping and simpler projects.

16,022

ESP8266 core for Arduino

Pros of Arduino

  • Larger community and more extensive library ecosystem
  • Familiar Arduino IDE and programming model for beginners
  • Supports multiple ESP8266 boards and modules out of the box

Cons of Arduino

  • Generally higher memory footprint compared to NodeMCU firmware
  • Slightly slower execution speed for some operations
  • Less optimized for ESP8266-specific features

Code Comparison

NodeMCU firmware (Lua):

gpio.mode(4, gpio.OUTPUT)
gpio.write(4, gpio.HIGH)
tmr.delay(1000000)
gpio.write(4, gpio.LOW)

Arduino:

pinMode(4, OUTPUT);
digitalWrite(4, HIGH);
delay(1000);
digitalWrite(4, LOW);

Both examples demonstrate blinking an LED connected to GPIO pin 4. The NodeMCU firmware uses Lua, which can be more concise but may have a steeper learning curve. Arduino uses C++, which is more familiar to many developers and offers strong typing.

The choice between these repositories depends on your project requirements, programming experience, and desired features. Arduino offers broader compatibility and ease of use, while NodeMCU firmware provides a more optimized and lightweight solution for ESP8266 devices.

esp8266 wifi-serial bridge, outbound TCP, and arduino/AVR/LPC/NXP programmer

Pros of esp-link

  • Simpler and more lightweight, focusing on WiFi connectivity and serial bridge functionality
  • Provides a web-based configuration interface for easy setup and management
  • Supports MQTT out of the box, making it suitable for IoT projects

Cons of esp-link

  • Less feature-rich compared to nodemcu-firmware
  • Limited scripting capabilities, as it doesn't include a Lua interpreter
  • Smaller community and fewer resources available for support and development

Code Comparison

esp-link (main.c):

void user_init(void) {
  uart_init(BIT_RATE_115200, BIT_RATE_115200);
  gpio_init();
  wifi_init();
  tcp_link_init();
}

nodemcu-firmware (app/lua/luaconf.h):

#define LUA_PATH_DEFAULT  \
    "./?.lua;"  LUA_LDIR"?.lua;" LUA_LDIR"?/init.lua;" \
    LUA_CDIR"?.lua;" LUA_CDIR"?/init.lua;" "./?.lc;" \
    LUA_LDIR"?.lc;" LUA_LDIR"?/init.lc;" LUA_CDIR"?.lc"

The code snippets highlight the different focus of each project. esp-link emphasizes low-level hardware initialization, while nodemcu-firmware includes Lua-specific configurations for scripting support.

Free and open (as much as possible) integrated SDK for ESP8266/ESP8285 chips

Pros of esp-open-sdk

  • Provides a complete toolchain for ESP8266 development
  • Offers more flexibility and control over the development environment
  • Supports a wider range of ESP8266-based projects beyond NodeMCU

Cons of esp-open-sdk

  • Requires more setup and configuration compared to nodemcu-firmware
  • Has a steeper learning curve for beginners
  • Less user-friendly documentation and community support

Code Comparison

esp-open-sdk example:

#include "ets_sys.h"
#include "osapi.h"
#include "gpio.h"
#include "os_type.h"

void user_init(void) {
    // Custom initialization code
}

nodemcu-firmware example:

gpio.mode(1, gpio.OUTPUT)
tmr.alarm(0, 1000, 1, function()
    gpio.write(1, gpio.read(1) == gpio.HIGH and gpio.LOW or gpio.HIGH)
end)

The esp-open-sdk uses C programming and provides lower-level access to the ESP8266 hardware, while nodemcu-firmware uses Lua scripting for easier and faster development. esp-open-sdk offers more control but requires more expertise, whereas nodemcu-firmware simplifies development at the cost of some flexibility.

Open source FreeRTOS-based ESP8266 software framework

Pros of esp-open-rtos

  • More lightweight and flexible, allowing for greater customization
  • Direct access to FreeRTOS features and APIs
  • Better suited for advanced users and complex projects

Cons of esp-open-rtos

  • Steeper learning curve, requiring more low-level programming knowledge
  • Less extensive documentation and community support
  • Fewer built-in libraries and modules compared to NodeMCU

Code Comparison

esp-open-rtos example:

#include "espressif/esp_common.h"
#include "esp/uart.h"
#include "FreeRTOS.h"
#include "task.h"

void hello_task(void *pvParameters) {
    while(1) {
        printf("Hello world!\n");
        vTaskDelay(1000 / portTICK_PERIOD_MS);
    }
}

NodeMCU example:

tmr.create():alarm(1000, tmr.ALARM_AUTO, function()
    print("Hello world!")
end)

The esp-open-rtos example demonstrates the use of FreeRTOS tasks and C programming, while the NodeMCU example showcases its simpler Lua-based approach with built-in timer functionality.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

NodeMCU 3.0.0

Lua-based firmware for ESP8266 WiFi SOC

Join the chat at https://gitter.im/nodemcu/nodemcu-firmware CI Documentation Status License

NodeMCU is an open source Lua based firmware for the ESP8266 WiFi SOC from Espressif and uses an on-module flash-based SPIFFS file system. NodeMCU is implemented in C and is layered on the Espressif NON-OS SDK.

The firmware was initially developed as is a companion project to the popular ESP8266-based NodeMCU development modules, but the project is now community-supported, and the firmware can now be run on any ESP module.

Summary

  • Easy to program wireless node and/or access point
  • Based on Lua 5.1.4 or Lua 5.3 but without debug, io, os and (most of the) math modules
  • Asynchronous event-driven programming model
  • More than 70 built-in C modules and close to 20 Lua modules
  • Firmware available with or without floating point support (integer-only uses less memory)
  • Up-to-date documentation at https://nodemcu.readthedocs.io

LFS support

In July 2018 support for a Lua Flash Store (LFS) was introduced. LFS allows Lua code and its associated constant data to be executed directly out of flash-memory; just as the firmware itself is executed. This now enables NodeMCU developers to create Lua applications with up to 256Kb Lua code and read-only constants executing out of flash. All of the RAM is available for read-write data!

Programming Model

The NodeMCU programming model is similar to that of Node.js, only in Lua. It is asynchronous and event-driven. Many functions, therefore, have parameters for callback functions. To give you an idea what a NodeMCU program looks like study the short snippets below. For more extensive examples have a look at the /lua_examples folder in the repository on GitHub.

-- 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\nContent-Type: text/html\r\n\r\n<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

The entire NodeMCU documentation is maintained right in this repository at /docs. The fact that the API documentation is maintained in the same repository as the code that provides the API ensures consistency between the two. With every commit the documentation is rebuilt by Read the Docs and thus transformed from terse Markdown into a nicely browsable HTML site at https://nodemcu.readthedocs.io.

Pages:

Releases

Due to the ever-growing number of modules available within NodeMCU, pre-built binaries are no longer made available. Use the automated custom firmware build service to get the specific firmware configuration you need, or consult the documentation for other options to build your own firmware.

This project uses two main branches, release and dev. dev is actively worked on and it's also where PRs should be created against. release thus can be considered "stable" even though there are no automated regression tests. The goal is to merge back to release roughly every 2 months. Depending on the current "heat" (issues, PRs) we accept changes to dev for 5-6 weeks and then hold back for 2-3 weeks before the next snap is completed.

A new tag is created every time the dev branch is merged back to release. They are listed in this repo's releases.

Tag names follow the <SDK-version>-release_yyyymmdd pattern.

Support

See https://nodemcu.readthedocs.io/en/release/support/.

License

MIT © zeroday/nodemcu.com