echo '' ;

Archives

Mongoose-OS – Get Start

Getting started with Mongoose OS (MOS) is pretty straightforward. That’s a basic overview of getting started with Mongoose OS. As you become more familiar with the platform, you can explore more advanced features and capabilities offered by Mongoose OS for developing IoT applications.

Read more: Mongoose-OS – Get Start

Get started

Here’s a shortened version of the installation and setup process for Mongoose OS:

  1. Installation: Install Mongoose OS on your machine by following the instructions on the Mongoose OS documentation website. You can use a package manager like npm or pip, or download the binaries directly.
  2. Environment Setup: Configure your IDE or text editor to work with Mongoose OS projects. Install any additional tools or SDKs required for your target platform.
  3. Creating a Project: Use the Mongoose OS CLI to create a new project. Run mos init in your desired directory to initialize a new project.
  4. Project Configuration: Customize your project by editing the mos.yml file in your project directory. Configure settings such as device type and communication protocols.
  5. Application Development: Write your application code in C/C++ or JavaScript. Create new source files in the fs directory of your project.
  6. Building and Flashing: Compile your application code with mos build. Flash the firmware to your device with mos flash. Ensure your device is connected via USB.
  7. Device Monitoring: Monitor your device’s logs and interact with it using mos console. View debug output and send commands from the console.
  8. Debugging and Iteration: Test your application on the device, debug any issues, and iterate on your code. Use mos command-line tools for managing your device and updating firmware as needed.

Mongoose-OS IDE’s

  • Web Browser based
  • Visual basic extensions

mos tool

What is mos tool ?

  • We need IDE for our project development.
  • mos tool like a web browser-based IDE.
  • we can use the mos tool to firmware upload & update, Build the firmware from c source, debug purpose and so on.
Read more… →

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 Interface – WiFi

WiFi Status Monitor

// Monitor network connectivity.
Net.setStatusEventHandler(function(ev, arg) {
  let evs = "???";
  if (ev === Net.STATUS_DISCONNECTED) {
    evs = "DISCONNECTED";
  } else if (ev === Net.STATUS_CONNECTING) {
    evs = "CONNECTING";
  } else if (ev === Net.STATUS_CONNECTED) {
    evs = "CONNECTED";
  } else if (ev === Net.STATUS_GOT_IP) {
    evs = "GOT_IP";
  }
  print("== Net event:", ev, evs);
}, null);

 


Next :

Previous :


 

ESP8266 Mongoose-OS Interface – Button

Code

 

// https://www.aruneworld.com/
// Tested By  : Arun(20170430)
// Example Name : AEW_Button_Message.js
// Firmware  : Mongoose OS for ESP32
//*******************************//

// This example demonstrates how to react on a button press
// by printing a message on a console.
//
// To try this example,
//   1. Download <code>{{EJS1}}</code> tool from https://mongoose-os.com/software.html
//   2. Run <code>{{EJS2}}</code> tool and install Mongoose OS
//   3. In the UI, navigate to the <code>{{EJS3}}</code> tab and load this example

// Load Mongoose OS API
load('api_gpio.js');

let pin = 0;   // GPIO 0 is typically a 'Flash' button
GPIO.set_button_handler(pin, GPIO.PULL_UP, GPIO.INT_EDGE_NEG, 200, function(x) {
  print('Button press, pin: ', x);
}, true);

print('Flash button is configured on GPIO pin ', pin);
print('Press the flash button now!');

 


Next :

Previous :


 

ESP8266 Mongoose-OS Tutorials – TCP Web Server

Welcome to the ESP8266 Mongoose-OS Tutorials on the TCP Web Server. In this series of tutorials, we will explore how to create a TCP Web Server using the ESP8266 microcontroller and the Mongoose-OS firmware.

The ESP8266 is a powerful microcontroller known for its built-in WiFi capability, making it suitable for IoT (Internet of Things) projects. Mongoose-OS is an open-source firmware for microcontrollers that provides a development environment for building IoT applications. “ESP8266 Mongoose OS Tutorials TCP Web Server”

In this tutorial series, we will demonstrate how to create a TCP Web Server using Mongoose-OS on the ESP8266. We will cover topics such as setting up the development environment, writing code to create a TCP server, handling incoming connections, and sending data over the network.

Whether you’re a beginner or an experienced developer, these tutorials will provide you with the knowledge and skills to create your own TCP Web Server on the ESP8266 using Mongoose-OS.

Let’s get start!

TCP Web Server Uses

UseDescription
Data LoggingLogging data received from clients, such as sensor readings or system status updates, for later analysis or archival purposes.
Remote MonitoringProviding remote access to real-time data, allowing users to monitor and control devices or systems from anywhere with an internet connection.
Home AutomationControlling smart home devices remotely, such as lights, thermostats, or security cameras, to manage home environments more conveniently.
Industrial ControlMonitoring and controlling machinery, production processes, or environmental conditions in industrial settings, enabling remote access for maintenance.
IoT ApplicationsExchanging data between connected IoT devices, gathering sensor data from remote locations, or controlling IoT devices remotely.
CommunicationFacilitating communication between devices on a network, allowing them to exchange data, synchronize operations, or coordinate tasks.
Remote ConfigurationRemotely configuring devices or systems, updating settings, adjusting parameters, or performing firmware upgrades without physical access to the device.
Real-Time NotificationsSending real-time notifications to connected clients, such as alerts, alarms, or status updates, to keep users informed of important events.
Custom ApplicationsBuilding custom applications tailored to specific needs, such as remote control interfaces, monitoring dashboards, or interactive user interfaces.
Distributed SystemsIntegrating into distributed systems or networked applications to enable communication and data exchange between multiple nodes or components.

Code

// https://www.aruneworld.com/embedded/espressif/esp8266/esp8266_mongoose-os/
// Tested By : Arun(20170430)
// Example Name : AEW_TCP_Web_Server.js
// Firmware : Mongoose OS for ESP32

//*******************************//

// This example demonstrates how to create a TCP echo server.
//
// To try this example,
// 1. Download mos tool from https://mongoose-os.com/software.html
// 2. Run mos tool and install Mongoose OS
// 3. In the UI, navigate to the Examples tab and load this example

// Load Mongoose OS API
load('api_net.js');

let port = '1234';

Net.bind(port, function(conn, ev, ev_data) {
    if (ev !== Net.EV_ACCEPT) return;
    Net.send(conn, JSON.stringify({a: 1, b: 'hey!'}));
    Net.close(conn);
}, true);

print('TCP server is listening on port ', port);

Code Explanation

Line(s)Explanation
1-4Comments providing information about the source of the code, the tester, example name, and firmware used.
7Load the Mongoose OS API module to enable network functionality.
9Define the port number (e.g., ‘1234’) on which the TCP server will listen for incoming connections.
11-18Bind a TCP server to the specified port. When a connection is accepted, send a JSON-encoded message {a: 1, b: 'hey!'} to the client and close the connection.
15Check if the event received is an accept event.
16Send a JSON-encoded message {a: 1, b: 'hey!'} to the client.
17Close the connection after sending the message.
19Print a message indicating that the TCP server is listening on the specified port.

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

ESP8266 Mongoose-OS Interface – LED

To turn on the led you need to load the gpio_api.js file.


LED Turn ON/OFF

Note : This below example was tested mongoose os with java script app demo-js in ESP8266 NodeMCU Dev Board(ESP-12E)

  • This below example turn on the LED GPIO-4 (NodeMCU Dev Board digital pin 2)
  • Set the GPIO pin mode as OUPUT uisng gpio set mode function ex: GPIO.set_mode(led, GPIO.MODE_OUTPUT)
  • Turn off the LED call the gpio write function with low-0 ex : GPIO.write(led, 0) .
  • Turn on the LED call the gpio write function with low-1 ex : GPIO.write(led, 1) .

Code

load('api_gpio.js');
 
// Configure LED
let led = 4; //lde pin GPIO04
GPIO.set_mode(led, GPIO.MODE_OUTPUT);
GPIO.write(led,1);

 


LED turn ON/OFF using button

  • Use Boot button(GPIO-0)
  • The example code used blink in-build LED, It’s connected to GPIO-10.
  • You can change any other pin Ex : led = 4; // Get LED GPIO-04 pin; 
  • Note : Code 1 and Two are same application and functionality. Main difference is calling function.

Code 1 :

  • Used GPIO-0 pin (Boot button in NodeMCU Dev Board), as interrupt and used Button interrupt handler function.
// http://www.ArunEworld.com/Embedded/ESPressif/ESP8266/ESP8266_Mongoose-os/
// Tested By  : Arun(20170430)
// Example Name : AEW_LED-Blink_Using_Button.js
// Firmware  : Mongoose OS for ESP32
//*******************************//
// This example demonstrates how to react on a button press by toggling LED.
//
// To try this example,
//   1. Download <code>{{EJS8}}</code> tool from https://mongoose-os.com/software.html
//   2. Run <code>{{EJS9}}</code> tool and install Mongoose OS
//   3. In the UI, navigate to the <code>{{EJS10}}</code> tab and load this example

// Load Mongoose OS API
load('api_gpio.js');

// Configure LED
let led = ffi('int get_led_gpio_pin()')();  // Get built-in LED GPIO pin
GPIO.set_mode(led, GPIO.MODE_OUTPUT);

let pin = 0;   // GPIO 0 is typically a 'Flash' button
GPIO.set_button_handler(pin, GPIO.PULL_UP, GPIO.INT_EDGE_NEG, 200, function(x) {
  let value = GPIO.toggle(led);
  print('Button press, pin:', x, 'LED pin:', led, ' Value: ', value);
}, true);

print('Flash button is configured on GPIO pin ', pin);
print('Press the flash button now!');

 

Code 2:

  • In this code i was used GPIO-0 pin (Boot button in NodeMCU dev Kit) as interrupt and used interrupt handler function.
  • If your using interruot handler function then you need o enable the interrupt using GPIO.enable_int(pin)  function
load('api_gpio.js');

GPIO.set_mode(4, 1);
//GPIO.write(10, 0);


GPIO.set_int_handler(0, GPIO.INT_EDGE_NEG, function(pin) {
   print('Pin', 0, 'got interrupt');
   GPIO.toggle(4);
   
}, null);
GPIO.enable_int(0);

 

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… →