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!
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 |
ESP8266 MongooseOS Interface LED |
ESP8266 MongooseOS Interface Button |
ESP8266 MongooseOS Tutorials Web Server |
ESP8266 MongooseOS All Post |
You must be logged in to post a comment.