Convert Figma logo to code with AI

SuperHouse logoesp-open-rtos

Open source FreeRTOS-based ESP8266 software framework

1,531
491
1,531
211

Top Related Projects

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

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

Sample ESP32 snippets and code fragments

Lua based interactive firmware for ESP8266, ESP8285 and ESP32

Quick Overview

ESP-OPEN-RTOS is an open-source FreeRTOS-based framework for the ESP8266 Wi-Fi chip. It provides a development environment for building applications on ESP8266 hardware, offering a more familiar and flexible alternative to the Espressif SDK.

Pros

  • Provides a familiar FreeRTOS-based environment for developers
  • Offers a wide range of libraries and drivers for various peripherals
  • Supports both C and C++ programming languages
  • Includes an easy-to-use build system based on make

Cons

  • Limited documentation compared to more mainstream ESP8266 development frameworks
  • May require more low-level knowledge compared to Arduino-based alternatives
  • Not as actively maintained as some other ESP8266 frameworks
  • Might have compatibility issues with certain ESP8266 modules

Code Examples

  1. Blinking an LED:
#include "espressif/esp_common.h"
#include "esp/gpio.h"
#include "FreeRTOS.h"
#include "task.h"

#define LED_PIN 2

void blink_task(void *pvParameters)
{
    gpio_enable(LED_PIN, GPIO_OUTPUT);
    while(1) {
        gpio_write(LED_PIN, 1);
        vTaskDelay(1000 / portTICK_PERIOD_MS);
        gpio_write(LED_PIN, 0);
        vTaskDelay(1000 / portTICK_PERIOD_MS);
    }
}

void user_init(void)
{
    xTaskCreate(blink_task, "blink_task", 256, NULL, 2, NULL);
}
  1. Connecting to Wi-Fi:
#include "espressif/esp_common.h"
#include "esp/uart.h"
#include "FreeRTOS.h"
#include "task.h"
#include "ssid_config.h"

void wifi_task(void *pvParameters)
{
    sdk_wifi_set_opmode(STATION_MODE);
    sdk_wifi_station_set_config(STATION_CONFIG);
    sdk_wifi_station_connect();
    
    while(1) {
        printf("Waiting for Wi-Fi connection...\n");
        vTaskDelay(1000 / portTICK_PERIOD_MS);
        if (sdk_wifi_station_get_connect_status() == STATION_GOT_IP) {
            printf("Connected to Wi-Fi\n");
            break;
        }
    }
    
    vTaskDelete(NULL);
}

void user_init(void)
{
    uart_set_baud(0, 115200);
    xTaskCreate(wifi_task, "wifi_task", 256, NULL, 2, NULL);
}
  1. Reading a DHT22 sensor:
#include "espressif/esp_common.h"
#include "esp/uart.h"
#include "FreeRTOS.h"
#include "task.h"
#include "dht.h"

#define DHT_PIN 4

void dht_task(void *pvParameters)
{
    int16_t temperature, humidity;
    
    while(1) {
        if (dht_read_data(DHT_TYPE_DHT22, DHT_PIN, &temperature, &humidity)) {
            printf("Temperature: %.1f°C, Humidity: %.1f%%\n", 
                   temperature / 10.0, humidity / 10.0);
        } else {
            printf("Failed to read DHT22 sensor\n");
        }
        vTaskDelay(2000 / portTICK_PERIOD_MS);
    }
}

void user_init(void)
{
    uart_set_baud(0, 115200);
    xTaskCreate(dht_task, "dht_task", 256, NULL, 2, NULL);
}

Getting Started

  1. Clone the repository:
    git clone --recursive https://github.com/
    

Competitor Comparisons

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

Pros of ESP8266_RTOS_SDK

  • Official SDK from Espressif, ensuring better compatibility and support
  • More comprehensive documentation and examples
  • Regular updates and maintenance from the chip manufacturer

Cons of ESP8266_RTOS_SDK

  • Larger codebase and potentially higher resource usage
  • Steeper learning curve for beginners
  • Less flexibility for customization compared to community-driven projects

Code Comparison

ESP8266_RTOS_SDK:

#include "esp_system.h"
#include "esp_wifi.h"
#include "esp_event_loop.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"

esp-open-rtos:

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

The ESP8266_RTOS_SDK uses a more modular approach with separate headers for different functionalities, while esp-open-rtos combines some functions into a single header. The official SDK also includes specific ESP8266 headers, whereas esp-open-rtos uses more generic naming conventions.

Both SDKs utilize FreeRTOS, but ESP8266_RTOS_SDK integrates it more tightly with the ESP8266 ecosystem. esp-open-rtos provides a more lightweight and customizable approach, which may be preferable for experienced developers or those working on resource-constrained projects.

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

Pros of esp-open-sdk

  • More comprehensive toolchain, including compiler and linker
  • Supports a wider range of ESP8266 development tasks
  • Includes additional tools for firmware manipulation and analysis

Cons of esp-open-sdk

  • Larger download and installation footprint
  • May have a steeper learning curve for beginners
  • Less focus on real-time operating system features

Code Comparison

esp-open-sdk example:

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

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

esp-open-rtos example:

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

void user_init(void) {
    // RTOS task creation and initialization
}

The esp-open-sdk focuses on low-level SDK access, while esp-open-rtos provides a higher-level abstraction with FreeRTOS integration. esp-open-sdk offers more flexibility for custom implementations, whereas esp-open-rtos simplifies development with built-in RTOS features. Choose esp-open-sdk for greater control over the ESP8266 hardware or esp-open-rtos for easier multitasking and real-time applications.

Sample ESP32 snippets and code fragments

Pros of esp32-snippets

  • Focuses specifically on ESP32, providing more targeted and optimized code examples
  • Includes a wider range of examples covering various ESP32 features and functionalities
  • Regularly updated with new snippets and improvements

Cons of esp32-snippets

  • Less structured as a complete development framework compared to esp-open-rtos
  • May require more effort to integrate snippets into a full project
  • Lacks some of the higher-level abstractions provided by esp-open-rtos

Code Comparison

esp32-snippets (BLE example):

BLEDevice::init("MyESP32");
BLEServer *pServer = BLEDevice::createServer();
BLEService *pService = pServer->createService(SERVICE_UUID);
BLECharacteristic *pCharacteristic = pService->createCharacteristic(
    CHARACTERISTIC_UUID,
    BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE
);

esp-open-rtos (Task creation example):

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

xTaskCreate(some_task, "some_task", 256, NULL, 2, NULL);

Both repositories offer valuable resources for ESP development, with esp32-snippets providing more focused ESP32 examples and esp-open-rtos offering a more structured development environment.

Lua based interactive firmware for ESP8266, ESP8285 and ESP32

Pros of nodemcu-firmware

  • Built-in Lua interpreter for easier scripting and rapid development
  • Extensive library support for various modules and sensors
  • Active community with frequent updates and contributions

Cons of nodemcu-firmware

  • Higher memory footprint due to Lua interpreter
  • Slightly slower execution compared to native C code
  • Limited low-level hardware access compared to esp-open-rtos

Code Comparison

esp-open-rtos (C):

#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-firmware (Lua):

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

The esp-open-rtos example uses C and FreeRTOS tasks, providing more control over the system but requiring more code. The nodemcu-firmware example uses Lua, resulting in more concise code but with less low-level control. esp-open-rtos offers better performance and resource efficiency, while nodemcu-firmware provides easier development and a gentler learning curve for beginners.

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

esp-open-rtos

A community developed open source FreeRTOS-based framework for ESP8266 WiFi-enabled microcontrollers. Intended for use in both commercial and open source projects.

Originally based on, but substantially different from, the Espressif IOT RTOS SDK.

Resources

Build Status

Email discussion list: https://groups.google.com/d/forum/esp-open-rtos

IRC channel: #esp-open-rtos on Freenode (Web Chat Link).

Github issues list/bugtracker: https://github.com/superhouse/esp-open-rtos/issues

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

Quick Start

  • Install esp-open-sdk, build it with make toolchain esptool libhal STANDALONE=n, then edit your PATH and add the generated toolchain bin directory. The path will be something like /path/to/esp-open-sdk/xtensa-lx106-elf/bin. (Despite the similar name esp-open-sdk has different maintainers - but we think it's fantastic!)

    (Other toolchains may also work, as long as a gcc cross-compiler is available on the PATH and libhal (and libhal headers) are compiled and available to gcc. The proprietary Tensilica "xcc" compiler will probably not work.)

  • Install esptool.py and make it available on your PATH. If you used esp-open-sdk then this is done already.

  • The esp-open-rtos build process uses GNU Make, and the utilities sed and grep. If you built esp-open-sdk then you have these already.

  • Use git to clone the esp-open-rtos project (note the --recursive):

git clone --recursive https://github.com/Superhouse/esp-open-rtos.git
cd esp-open-rtos
  • To build any examples that use WiFi, create include/private_ssid_config.h defining the two macro defines:
#define WIFI_SSID "mywifissid"
#define WIFI_PASS "my secret password"
  • Build an example project (found in the 'examples' directory) and flash it to a serial port:
make flash -j4 -C examples/http_get ESPPORT=/dev/ttyUSB0

Run make help -C examples/http_get for a summary of other Make targets.

(Note: the -C option to make is the same as changing to that directory, then running make.)

The Build Process wiki page has in-depth details of the build process.

Goals

  • Provide professional-quality framework for WiFi-enabled RTOS projects on ESP8266.
  • Open source code for all layers above the MAC layer, ideally lower layers if possible (this is a work in progress, see Issues list.
  • Leave upstream source clean, for easy interaction with upstream projects.
  • Flexible build and compilation settings.

Current status is alpha quality, actively developed. AP STATION mode (ie wifi client mode) and UDP/TCP client modes are tested. Other functionality should work. Contributors and testers are welcome!

Code Structure

  • examples contains a range of example projects (one per subdirectory). Check them out!
  • include contains header files from Espressif RTOS SDK, relating to the binary libraries & Xtensa core.
  • core contains source & headers for low-level ESP8266 functions & peripherals. core/include/esp contains useful headers for peripheral access, etc. Minimal to no FreeRTOS dependencies.
  • extras is a directory that contains optional components that can be added to your project. Most 'extras' components will have a corresponding example in the examples directory. Extras include:
    • mbedtls - mbedTLS is a TLS/SSL library providing up to date secure connectivity and encryption support.
    • i2c - software i2c driver (upstream project)
    • rboot-ota - OTA support (over-the-air updates) including a TFTP server for receiving updates (for rboot by @raburton)
    • bmp180 driver for digital pressure sensor (upstream project)
  • FreeRTOS contains FreeRTOS implementation, subdirectory structure is the standard FreeRTOS structure. FreeRTOS/source/portable/esp8266/ contains the ESP8266 port.
  • lwip contains the lwIP TCP/IP library. See Third Party Libraries wiki page for details.
  • libc contains the newlib libc. Libc details here.

Open Source Components

For details of how third party libraries are integrated, see the wiki page.

Binary Components

Binary libraries (inside the lib dir) are all supplied by Espressif as part of their RTOS SDK. These parts were MIT Licensed.

As part of the esp-open-rtos build process, all binary SDK symbols are prefixed with sdk_. This makes it easier to differentiate binary & open source code, and also prevents namespace conflicts.

Espressif's RTOS SDK provided a "libssl" based on axTLS. This has been replaced with the more up to date mbedTLS library (see below).

Some binary libraries appear to contain unattributed open source code:

  • libnet80211.a & libwpa.a appear to be based on FreeBSD net80211/wpa, or forks of them. (See this issue).
  • libudhcp has been removed from esp-open-rtos. It was released with the Espressif RTOS SDK but udhcp is GPL licensed.

Licensing

  • BSD license (as described in LICENSE) applies to original source files, lwIP. lwIP is Copyright (C) Swedish Institute of Computer Science.

  • FreeRTOS (since v10) is provided under the MIT license. License details in files under FreeRTOS dir. FreeRTOS is Copyright (C) Amazon.

  • Source & binary components from the Espressif IOT RTOS SDK were released under the MIT license. Source code components are relicensed here under the BSD license. The original parts are Copyright (C) Espressif Systems.

  • Newlib is covered by several copyrights and licenses, as per the files in the libc directory.

  • mbedTLS is provided under the Apache 2.0 license as described in the file extras/mbedtls/mbedtls/apache-2.0.txt. mbedTLS is Copyright (C) ARM Limited.

Components under extras/ may contain different licenses, please see those directories for details.

Contributions

Contributions are very welcome!

  • If you find a bug, please raise an issue to report it.

  • If you have feature additions or bug fixes then please send a pull request.

  • There is a list of outstanding 'enhancements' in the issues list. Contributions to these, as well as other improvements, are very welcome.

If you are contributing code, please ensure that it can be licensed under the BSD open source license. Specifically:

  • Code from Espressif IoT SDK cannot be merged, as it is provided under either the "Espressif General Public License" or the "Espressif MIT License", which are not compatible with the BSD license.

  • Recent releases of the Espressif IoT RTOS SDK cannot be merged, as they changed from MIT License to the "Espressif MIT License" which is not BSD compatible. The Espressif binaries used in esp-open-rtos were taken from revision ec75c85, as this was the last MIT Licensed revision.

For code submissions based on reverse engineered binary functionality, please either reverse engineer functionality from MIT Licensed Espressif releases or make sure that the reverse engineered code does not directly copy the code structure of the binaries - it cannot be a "derivative work" of an incompatible binary.

The best way to write suitable code is to first add documentation somewhere like the esp8266 reverse engineering wiki describing factual information gained from reverse engineering - such as register addresses, bit masks, orders of register writes, etc. Then write new functions referring to that documentation as reference material.

Coding Style

For new contributions in C, please use BSD style and indent using 4 spaces.

For assembly, please use the following:

  • Instructions indented using 8 spaces.
  • Inline comments use # as a comment delimiter.
  • Comments on their own line(s) use /*..*/.
  • First operand of each instruction should be vertically aligned where possible.
  • For xtensa special registers, prefer wsr aX, SR over wsr.SR aX

If you're an emacs user then there is a .dir-locals.el file in the root which configures cc-mode and asm-mode (you will need to approve some variable values as safe). See also the additional comments in .dir-locals.el, if you're editing assembly code.

Upstream code is left with the indentation and style of the upstream project.

Sponsors

Work on parts of esp-open-rtos has been sponsored by SuperHouse Automation.