echo '' ;
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 – WiFiIn 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!
Wifi.scan(function(results) { print(JSON.stringify(results)); });
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 .
Code Example
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 } } };
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.
MongooseOS |
ESP8266 MongooseOS Interface LED |
ESP8266 MongooseOS Interface Button |
ESP8266 MongooseOS Tutorials Web Server |
ESP8266 MongooseOS All Post |
// 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 :
Note : You can use arduino example code instead of below code because both are same (File > Example > WiFi> WiFiScan)
/* https://aruneworld.com/embedded/espressif/esp32 * Tested By : Arun(20170429) * Example Name : AEW_WiFi_Scan.ino * This sketch demonstrates how to scan WiFi networks. * The API is almost the same as with the WiFi Shield library, * the most obvious difference being the different file you need to include: */ #include "WiFi.h" void setup() { Serial.begin(115200); // Set WiFi to station mode and disconnect from an AP if it was previously connected WiFi.mode(WIFI_STA); WiFi.disconnect(); delay(100); Serial.println("Setup done"); } void loop() { Serial.println("scan start"); // WiFi.scanNetworks will return the number of networks found int n = WiFi.scanNetworks(); Serial.println("scan done"); if (n == 0) { Serial.println("no networks found"); } else { Serial.print(n); Serial.println(" networks found"); for (int i = 0; i < n; ++i) { // Print SSID and RSSI for each network found Serial.print(i + 1); Serial.print(": "); Serial.print(WiFi.SSID(i)); Serial.print(" ("); Serial.print(WiFi.RSSI(i)); Serial.print(")"); Serial.println((WiFi.encryptionType(i) == WIFI_AUTH_OPEN)?" ":"*"); delay(10); } } Serial.println(""); // Wait a bit before scanning again delay(5000); }
Serial Terminal Output
scan start scan done 5 networks found 1: ArunEworld (-34)* 2: Exuber_365 (-59)* 3: Bangalore Police (-66)* 4: Tagos-2.4 (-80)* 5: RRL_Internet (-93)*
This article is a continuation of the series on the ESP32 ArduinoCore Project using the ESP32 Dev board and carries the discussion on WiFi Web Server LED Blink. This series aims to provide easy and practical examples that anyone can understand. In our previous tutorial, we saw how to use the inbuilt code to toggle the onboard LED. This is the ESP32 LED Blinky in Wifi Webserver In this tutorial
A simple web server that lets you blink an LED via the web.
You must be logged in to post a comment.