echo '' ;

Archives

ESP8266 Mongoose-OS Module – WiFi

Welcome to the ESP8266 Mongoose-OS Module on WiFi. In this module, we will explore how to configure and utilize WiFi connectivity on the ESP8266 microcontroller using Mongoose-OS firmware.

The ESP8266 is a powerful microcontroller with built-in WiFi capability, making it a popular choice for IoT (Internet of Things) projects. Mongoose-OS is an open-source firmware for microcontrollers that provides a development environment for building IoT applications.

Read more: ESP8266 Mongoose-OS Module – WiFi

In this module, we will cover topics such as configuring WiFi settings, connecting to WiFi networks, handling WiFi events, and utilizing WiFi functionalities in IoT applications. Whether you’re a beginner or an experienced developer, this module will provide you with the knowledge and skills to effectively use WiFi on the ESP8266 with Mongoose OS.

Let’s dive into the world of WiFi connectivity with the ESP8266 and Mongoose-OS!

Scan all available networks

Wifi.scan(function(results) {
    print(JSON.stringify(results));
});

Configure Access Point (Hotpots)

By default when flashing the firmware after ESP8266 WiFi configured as a AP mode in the WiFI AP SSID name of Mongoose_?????  here ????  is the chip id and password is Mongoose .

FAQ

  • How to Set ESP8266 to AP mode?
  • How to Set ESP8266 as Hotpots?

Steps to follow

  • Go to the Device files tab in a web browser using the mos tool. (IP address http://127.0.0.1:1992/#files )
  • Change the ap credential or set the credential in the conf0.json  file. (Refer Below Image)

Code Example

  • Enable AP Mode : “enable”: true, .
  • Disable AP Mode : “enable”: false, .
  • You can hide ESP8266 AP mode list using “hidden”: false,  (Not shown WiFi available list).
const wifiConfig = {
  wifi: {
    ap: {
      enable: true,
      ssid: "ArunEworld",
      pass: "info@aruneworld.com",
      hidden: false,
      channel: 6,
      max_connections: 10,
      ip: "192.168.4.1",
      netmask: "255.255.255.0",
      gw: "192.168.4.1",
      dhcp_start: "192.168.4.2",
      dhcp_end: "192.168.4.100",
      trigger_on_gpio: -1,
      disable_after: 0,
      hostname: "",
      keep_enabled: true
    }
  }
};

ESP8266 connects to WiFi Router

Here’s an example code snippet to connect an ESP8266 to a WiFi router using Mongoose OS:

load('api_config.js');     // Load the Mongoose OS configuration API
load('api_net.js');        // Load the Mongoose OS network API

// Configure WiFi settings
let ssid = 'YourWiFiSSID'; // Replace 'YourWiFiSSID' with your WiFi network SSID
let password = 'YourWiFiPassword'; // Replace 'YourWiFiPassword' with your WiFi network password

// Connect to WiFi
Net.connect({
  ssid: ssid,
  pass: password,
  auth: Net.AUTH_WPA2_PSK // Use WPA2 authentication (change if necessary)
});

// Event handler for WiFi connection status change
Net.setStatusEventHandler(function(ev, arg) {
  if (ev === Net.STATUS_DISCONNECTED) {
    print('WiFi disconnected');
  } else if (ev === Net.STATUS_CONNECTING) {
    print('WiFi connecting...');
  } else if (ev === Net.STATUS_CONNECTED) {
    print('WiFi connected');
  }
});

Replace 'YourWiFiSSID' with the SSID of your WiFi network and 'YourWiFiPassword' with the password of your WiFi network. This code will attempt to connect the ESP8266 to the specified WiFi network using the provided credentials. It also includes event handlers to print status messages when the WiFi connection status changes.

NEXT

MongooseOS
Mongoose-OS Interface
ESP8266 MongooseOS Interface LED
ESP8266 MongooseOS Interface Button
Mongoose OS Tutorials
ESP8266 MongooseOS Tutorials Web Server
Others
ESP8266 MongooseOS All Post

ESP32 Mongoose OS – Basic Examples

This article is about ESP32 Mongoose OS – Basic Examples, Let’s go through a basic example of using UART (Universal Asynchronous Receiver-Transmitter), Button and blinking an LED using an ESP32 by Mongoose OS.

Mongoose OS is an open-source IoT operating system designed for low-power, connected microcontrollers. Below is a basic example to get you started with Mongoose OS on an ESP32. This example demonstrates how to create a simple firmware that blinks an LED.

This is a basic example to help you get started with Mongoose OS on an ESP32. It blinks an LED using the GPIO capabilities provided by Mongoose OS. From here, you can explore additional features and libraries provided by Mongoose OS to build more sophisticated IoT applications. Refer to the Mongoose OS documentation for detailed information and advanced usage.

Setup Required

  • PC
  • UART Terminal (Putty, Visual Studio Serial Terminal, DockLight)
  • LEDs

UART Serial

Print words, string, text, symbols

print('------------****************----------------');
print('ArunEworld');

ESP32 Mongoose OS – Basic Examples of UART Communication

// https://github.com/cesanta/mongoose-os/blob/master/fw/examples/mjs_uart/init.js
// Load Mongoose OS API
load('api_timer.js');
load('api_uart.js');
load('api_sys.js');

// Uart number used for this example
let uartNo = 1;
// Accumulated Rx data, will be echoed back to Tx
let rxAcc = "";

let value = false;

// Configure UART at 115200 baud
UART.setConfig(uartNo, {
  baudRate: 115200,
  esp32: {
    gpio: {
      rx: 16,
      tx: 17,
    },
  },
});

// Set dispatcher callback, it will be called whenver new Rx data or space in
// the Tx buffer becomes available
UART.setDispatcher(uartNo, function(uartNo, ud) {
  let ra = UART.readAvail(uartNo);
  if (ra > 0) {
    // Received new data: print it immediately to the console, and also
    // accumulate in the "rxAcc" variable which will be echoed back to UART later
    let data = UART.read(uartNo);
    print("Received UART data:", data);
    rxAcc += data;
  }
}, null);

// Enable Rx
UART.setRxEnabled(uartNo, true);

// Send UART data every second
Timer.set(1000 /* milliseconds */, true /* repeat */, function() {
  value = !value;
  UART.write(
    uartNo,
    "Hello UART! "
      + (value ? 'Tick' : 'Tock')
      + " uptime: " + JSON.stringify(Sys.uptime())
      + " RAM: " + JSON.stringify(Sys.free_ram())
      + (rxAcc.length > 0 ? (" Rx: " + rxAcc) : "")
      + "\n"
  );
  rxAcc = "";
}, null);

GPIO Module

Read more… →

ESP32 Lua-RTOS Module – PIO

The PIO (Programmable Input/Output) module in the ESP32 Lua-RTOS is a versatile feature that allows users to configure and control the GPIO pins of the ESP32 microcontroller dynamically. It provides an interface for performing various operations such as digital input, digital output, and pulse-width modulation (PWM) generation, among others.

Functionalities and Capabilities

  1. Digital Input/Output: The PIO module allows users to configure GPIO pins as digital inputs or outputs. Digital inputs can be used to read the state of external sensors or switches, while digital outputs can drive external devices such as LEDs, relays, or motors.
  2. Interrupt Handling: It supports interrupt handling on GPIO pins, allowing users to trigger actions based on changes in pin states. This feature is useful for implementing event-driven applications where real-time responses to external events are required.
  3. Pull-up/Pull-down Resistors: The PIO module enables users to enable or disable the internal pull-up or pull-down resistors on GPIO pins, ensuring stable and reliable signal readings.
  4. Pulse-Width Modulation (PWM): It provides support for generating PWM signals on GPIO pins, allowing users to control the intensity of analog devices such as LEDs, motors, or servos.
  5. Pin Configuration: Users can dynamically configure the functionality and characteristics of GPIO pins using the PIO module, including setting pin modes (input/output), configuring interrupt triggers, and adjusting PWM parameters.
  6. Low-Level Access: The PIO module offers low-level access to GPIO pins, allowing users to directly manipulate pin states and registers for advanced control and customization.
  7. Resource Management: It provides mechanisms for managing GPIO pin resources efficiently, preventing conflicts and ensuring proper allocation of resources across different tasks or modules.

Overall, the PIO module in the ESP32 Lua-RTOS enhances the flexibility and versatility of the ESP32 microcontroller, enabling users to implement a wide range of GPIO-based applications with ease and efficiency. Whether for simple digital I/O tasks or more complex PWM generation and interrupt handling, the PIO module offers powerful capabilities for interacting with external devices and sensors in Lua-RTOS projects.

Read more… →