echo '' ;

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.

Mos tool features and use

This mos.exe  software works for many purpose like.

  • Installation of the flashing firmware into mcu.
  • Building the firmware from the C source files for mcu.
  • Managing the files on our MCU device.
  • Call and access the Remote Procedure Call (RPC protocol )  and many more features.

How mos tool works

  • mos tool  will be act as a local server.
  • We can access the mos tool server from any web browser like mozilz, chrome, internet explore, microsoft edge in the address of http://127.0.0.1:1992/ .
  • The server contains the web source of flashing & update firmware options, mcu interface option using uart.

Download & Install mos tool in windows

Note: Installed and tested on Windows 10, 64-bit.

  • Download the windows installer using this link here (Download page)
  • After pop up will get the mos.exe  file. save anywhere on your pc.
  • Click Run as administrator  in mos.exe  file. (Note : Sometime its may be show like “Malicious file This application may cause damage to your device. Sensitive personal data may also be at risk.” click more info  link , then click run anyway  link. Also allow network permission and firewall access.
  • Once done above the default browser will open with the local host address like http://127.0.0.1:1992/
  • Now you need to follow the steps of how to update mongoose os firmware into ESP8266  or flash the mongoose firmware into esp8266  see below.
  • Basically this server run using UART Serial communication, so our mcu should connect to our pc via usb port

How to update the mos tool

  • Automatic: update mos toll automatically by the web browser throw automatically, every time its will be the later release of the mos tool and update itself
  • Manual : update the mos tool via the web browser IDE Terminal command mos update or update .See the result below
[May 3 16:00:24.809] Update channel: release [May 3 16:00:26.377] Up to date.
  • Manual: You can specifically update the mos tool by this command mos update 1.18. See the results below (At the time I got some error, we will try later and update soon)
[May 3 16:15:57.316] Update channel: release
[May 3 16:15:58.704] Current version: 20180418-132622/2.1@d9490727+, available version: 20171001-163638/1.18@4bbec4b4+
[May 3 16:15:59.433] Downloading from https://mongoose-os.com/downloads/mos-1.18/win/mos.exe...
[May 3 16:16:19.877] Renaming old binary as C:\Users\HP\Desktop\ESP8266\ESP8266 Mongoose OS\mos.exe.bak...
Server Error: {"error":"rename C:\\Users\\HP\\Desktop\\ESP8266\\ESP8266 Mongoose OS\\mos.exe C:\\Users\\HP\\Desktop\\ESP8266\\ESP8266 Mongoose OS\\mos.exe.bak: Access is denied."}
  • Manual: you can update the latest mos tool by this command update latest. See the below result
[May 3 16:11:32.922] Changing update channel from "release" to "latest"
[May 3 16:11:33.258] Current version: 20180418-132622/2.1@d9490727+, available version: 20180426-184319/master@435a501a+
[May 3 16:11:34.038] Downloading from https://mongoose-os.com/downloads/mos-latest/win/mos.exe...
[May 3 16:12:29.385] Renaming old binary as C:\Users\HP\Desktop\ESP8266\ESP8266 Mongoose OS\mos.exe.bak...
[May 3 16:12:29.666] Saving new binary as C:\Users\HP\Desktop\ESP8266\ESP8266 Mongoose OS\mos.exe...
[May 3 16:12:29.756] Done.

Flash the Firmware

Notes : You should install the mos tool if you not install, Also tested JavaScript with ESP8266 & ESP32 in Windows 10, 64-bit machine using mos tool.

FAQ

  • How to update mongoose os firmware into ESP8266?
  • How flash the mongoose firmware into esp8266?

Required

  • mos tool
  • ESP8266

Wiring Connection

Note : Your using development board then don’t need to follow this below wiring methods because development board pr-build setup have already.

PlatformWiring Notes
bare bones ESP8266flash via UART: GPIO15 LOW , GPIO0 LOW, GPIO2 HIGH
flash to boot: GPIO15 LOW, GPIO0 HIGH, GPIO2 HIGH
boot from SD: GPIO15 HIGH
bare bones ESP32flash via UART: GPIO0 LOW
boot from flash: GPIO0 HIGH
CC3200 launchpadconnect J8 to SOP2 (see guide)

What is mean by bore bones?

  • Mostly development board has all features exposed with programmer. so easily can flash using in development
  • But if your working direct mcu chip or module (without programmer) you need to know what are the basic wiring required for boot, flash and normal running mode. Mostly this type of development is called bare bone.

Follow Steps

  • Connect your Device(ESP8266, ESP32, CC3220) board with PC using USB,
  • Run the mos tool and web browser will open the home page, and pop up will show the update or upload firmware page.
  • Choose device address in a drop-down, or type into the text field, then click Select. Possible formats of device addresses:
    • COMx – serial port on Windows (Donno COM PORT check in deceive manger)
    • /dev/ttyUSBx – serial port on Linux
    • /dev/cu.xxxxxx – serial port on MacOS
    • ws://IP_ADDRESS/rpc – device on a local network
    • mqtt://MQTT_SERVER:PORT/DEVICE_ID – device connected to an MQTT server
    • Note : if you PC can’t detect COM port then Check the COM port Enable. If not install the correct driver of your board.
  • Erlier mos  toll version upload the pr-build firmware called default firmware, but newer version may have many options like device platform : (ESP8266, ESP8266, CC2330)  based on memory and App : (JavaScript/C) based on programming language.
  • Then Choose platform (Ex : ESP8266), select app (Ex: js or c), click Flash 
  • Make sure (GPIO-0 Low) boot button  was pressed.
  • Initially it load the LED blink example.


Hello world Example

When flash the firmware into ESP8266, default load the LED blink example in init.js  file. (LED is in-build on development board GPIO-10.). Also automatically configured the ESP8266 WiFi as AP mode in the name of SSID Mongoose_?????? here ????? is the chip id. and the password is Mongoose.

Code

// Load required Mongoose OS modules
load('api_config.js');
load('api_events.js');
load('api_gpio.js');
load('api_mqtt.js');
load('api_net.js');
load('api_sys.js');
load('api_timer.js');

// Get GPIO pin configurations from device configuration
let led = Cfg.get('pins.led');
let button = Cfg.get('pins.button');

// Define MQTT topic for publishing events
let topic = '/devices/' + Cfg.get('device.id') + '/events';

// Print GPIO configurations
print('LED GPIO:', led, 'button GPIO:', button);

// Function to get device information
let getInfo = function() {
    return JSON.stringify({
        total_ram: Sys.total_ram(),
        free_ram: Sys.free_ram()
    });
};

// Blink built-in LED every second
GPIO.set_mode(led, GPIO.MODE_OUTPUT);
Timer.set(1000 /* 1 sec */, Timer.REPEAT, function() {
    let value = GPIO.toggle(led);
    print(value ? 'Tick' : 'Tock', 'uptime:', Sys.uptime(), getInfo());
}, null);

// Publish to MQTT topic on a button press. Button is wired to GPIO pin 0
GPIO.set_button_handler(button, GPIO.PULL_UP, GPIO.INT_EDGE_NEG, 20, function() {
    let message = getInfo();
    let ok = MQTT.pub(topic, message, 1);
    print('Published:', ok, topic, '->', message);
}, null);

// Monitor network connectivity events
Event.addGroupHandler(Net.EVENT_GRP, function(ev, evdata, 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);

Result

Note : Write code into mcu or rewrite code into mcu, you should restart the machine manual or by software.



Command line (Terminal)

  • Following any commands can list out all commands in terminal : help  or helpfull  or commands  or command
uiStart GUI
initInitialise firmware directory structure in the current directory
buildBuild a firmware from the sources located in the current directory
flashFlash firmware to the device
flash-readRead a region of flash
consoleSimple serial port console
lsList files at the local device’s filesystem
getRead file from the local device’s filesystem and print t
o stdout 
putPut file from the host machine to the local device’s filesystem
rmDelete a file from the device’s filesystem
config-getGet config value from the locally attached device
config-setSet config value at the locally attached device
callPerform a device API call. “mos call RPC.List” shows available methods
aws-iot-setupProvision the device for AWS IoT cloud
azure-iot-setupProvision the device for Azure IoT Hub
gcp-iot-setupProvision the device for Google IoT Core
updateSelf-update mos tool; optionally update channel can be given (eg. “latest”, “release”, or some exact version)
wifiSetup WiFi – shortcut to config-set wifi…
  • Global Flags:
    • –verbose  Verbose output. Optional, default value: “false”
    • –logtostderr  log to standard error instead of files. Optional, default value: “false”
    • –helpfull  Show full help, including advanced flags. Optional, default value: “false”

Notes

if your platform is JavaScript in Mongoose-OS, please read the basics below.

Declaring the variable

  • JavaScript : using var  keyword declare variables. Ex : var Arun  here Arun is a variable.
  • Mongoose-OS JavaScript : using let  keyword to declare variable. Ex: let Arun  here Arun is a variable

GPIO Module

These functions provide comprehensive control over GPIO pins in Mongoose OS, allowing you to configure pins, read and write values, toggle output levels, handle interrupts, and more.

FunctionDescription
GPIO.set_mode(pin, mode)Set GPIO pin mode as input or output. mode can be GPIO.MODE_INPUT for input or GPIO.MODE_OUTPUT for output.
GPIO.set_pull(pin, type)Set input or output pin as PULL-Up, PULL-Down, or None. type can be GPIO.PULL_NONE, GPIO.PULL_UP, or GPIO.PULL_DOWN.
GPIO.toggle(pin)Toggle output pin level between high and low. Returns 0 or 1.
GPIO.write(pin, level)Write a value (0 for low, 1 for high) to the specified pin.
GPIO.read(pin)Read the value (0 for low, 1 for high) from the specified pin.
GPIO.enable_int(pin)Enable interrupts on the specified pin. Returns 1 for success, 0 otherwise.
GPIO.disable_int(pin)Disable interrupts on the specified pin. Returns 1 for success, 0 otherwise.
GPIO.set_int_handler(pin, mode, handler)Set interrupt handler for the specified pin. mode specifies the interrupt mode.
GPIO.set_button_handler(pin, pull, intmode, period, handler)Set a button handler for the specified pin. pull sets the pull-up or pull-down resistor, intmode specifies the interrupt mode, period is the debounce interval in milliseconds, and handler is the callback function.

Timer Module

Timer Functions

  • Timer.set(milliseconds, flags, handler, userdata)
    • Milliseconds – timeout
    • Flag  – 0 Zero, for repeat condition Timer.REPEAT


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from ArunEworld

Subscribe now to keep reading and get access to the full archive.

Continue reading