echo '' ;

Archives

Embedded Protocol – WiFi

WiFi, short for “Wireless Fidelity,” is a technology that allows devices to connect to the internet or communicate with each other wirelessly using radio waves. It’s widely used in homes, businesses, and public spaces to provide internet access without the need for physical wired connections. WiFi operates within the unlicensed radio frequency bands, typically 2.4 GHz and 5 GHz, and it’s governed by the IEEE 802.11 family of standards. These standards define different WiFi versions, such as 802.11n, 802.11ac, and the latest, 802.11ax (Wi-Fi 6), each offering various speeds, range, and features. WiFi routers and access points transmit signals that devices like smartphones, laptops, tablets, and smart home gadgets can receive, enabling them to access the internet or network resources.

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 :


 

ESP32 ArduinoCore Interface – Wi-Fi

The ESP32 ArduinoCore interface for Wi-Fi provides a straightforward and flexible way to enable Wi-Fi connectivity in projects developed using the ESP32 microcontroller platform with the Arduino IDE. With this interface, developers can easily incorporate Wi-Fi functionality into their projects, enabling devices to connect to wireless networks, access the internet, and communicate with other devices over Wi-Fi.

Features and Capabilities

  1. Access Point (AP) Mode: The ESP32 can act as an access point, allowing other devices to connect to it and access resources or services hosted by the ESP32.
  2. Station (STA) Mode: The ESP32 can connect to existing Wi-Fi networks as a client, enabling devices to access the internet or communicate with other networked devices.
  3. Soft Access Point (SoftAP) Mode: This mode enables the ESP32 to simultaneously act as both an access point and a station, allowing it to connect to an existing Wi-Fi network while also providing Wi-Fi access to other devices.
  4. Wi-Fi Protected Setup (WPS): The ESP32 supports WPS, a method for easily configuring Wi-Fi network security settings without needing to enter a password manually.
  5. Advanced Configuration Options: The interface provides access to advanced configuration options for fine-tuning Wi-Fi settings, such as specifying static IP addresses, setting up captive portals, and configuring Wi-Fi sleep modes to optimize power consumption.
  6. Event Handling: Developers can implement event handlers to respond to Wi-Fi-related events, such as successful connections, disconnections, or errors, allowing for more robust and responsive Wi-Fi functionality.
  7. Security Features: The ESP32 ArduinoCore interface supports various Wi-Fi security protocols, including WPA and WPA2, to ensure secure communication over Wi-Fi networks.

Overall, the ESP32 ArduinoCore interface for Wi-Fi simplifies the process of adding Wi-Fi connectivity to ESP32-based projects, making it easier for developers to create IoT devices, home automation systems, and other wireless applications.

Scan WiFi

Note: You can use Arduino example code instead of the below code because both are the 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)*

Code Explanation

Certainly! Here’s the code with explanations provided as snippets:

#include "WiFi.h"

This line includes the WiFi library necessary for working with WiFi on the ESP32.

void setup()
{
    Serial.begin(115200);

    WiFi.mode(WIFI_STA);
    WiFi.disconnect();
    delay(100);

    Serial.println("Setup done");
}

In the setup() function:

  • The code initializes serial communication at a baud rate of 115200.
  • The WiFi mode is set to station mode (WIFI_STA) and any previous connection is disconnected using WiFi.disconnect().
  • The code adds a delay of 100 milliseconds.
  • The code prints “Setup done” to the serial monitor.
void loop()
{
    Serial.println("scan start");

    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) {
            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("");

    delay(5000);
}

In the loop() function:

  • The code begins by printing “scan start” to the serial monitor.
  • Next, the ESP32 scans for nearby WiFi networks using the WiFi.scanNetworks() function, storing the number of networks found in variable n.
  • After completing the scan, the code prints “scan done” to the serial monitor.
  • The code prints the number of networks found when it detects networks, followed by details of each network, including index, SSID (network name), RSSI (signal strength), and encryption type.
  • If no networks are found (when n == 0), the message “no networks found” is printed.
  • When networks are found, the code prints the number of networks found, followed by details of each network, including index, SSID (network name), RSSI (signal strength), and encryption type.
  • Finally, the code adds a delay of 5 seconds before initiating the next scan.

These snippets provide an overview of how the code initializes WiFi and continuously scans for nearby networks, printing details to the serial monitor.

ESP32 ArduinoCore Project – WiFi Web Server LED Blink

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.

Wifi Web Server Info

  • This code will print the IP address of your WiFi Module (ESP32) (once connected) to the Serial monitor.
  • From that IP Address, you can open that address in a web browser to turn on and off the LED on pin-5.
  • If the IP address of your ESP32 is 192.168.1.143:
    • http://192.168.1.143/H turns the LED on
    • http://192.168.1.143/L turns it off
  • This example is written for a network using WPA encryption.
  • For WEP or WPA, change the Wifi.begin() call accordingly.

Read more… →