Copyright © https://mongoose-os.com

Mongoose OS Forum

frame

Wi-Fi connection RSSI, signal strength

Is there a way to get RSSI of current connection? Without scanning for available hotspots

Comments

  • SergeySergey Dublin, Ireland

    At the moment mOS API does not have that.
    Look in the SDK API.

  • I wrote a simple wrapper for ESP8266 and ESP32:
    wifi.h

    #pragma once
    
    struct WifiInfo
    {
        int8_t rssi;
        uint8_t channel;
    };
    
    void getWifiInfo(WifiInfo& info);
    
    

    wifi.cpp

    #include <mgos.h>
    #include "wifi.h"
    
    extern "C"
    {
    #if CS_PLATFORM == CS_P_ESP8266
        int8_t wifi_station_get_rssi(void);
        uint8_t wifi_get_channel(void);
    #elif CS_PLATFORM == CS_P_ESP32
    #include <esp_wifi.h>
    #endif
    }
    
    void getWifiInfo(WifiInfo& info)
    {
        info.rssi = 0;
        info.channel = 0;
    #if CS_PLATFORM == CS_P_ESP8266
        info.rssi = wifi_station_get_rssi();
        info.channel = wifi_get_channel();
    #elif CS_PLATFORM == CS_P_ESP32
        wifi_ap_record_t wifidata;
        esp_wifi_sta_get_ap_info(&wifidata);
        if (wifidata.primary != 0) {
            info.rssi = wifidata.rssi;
            info.channel = wifidata.primary;
        }
    #endif
    }
    

    It works on ESP8266 and compiles on ESP32. I don't have yet an ESP32 to test.

  • nliviunliviu Romania
    edited September 13

    Sure.
    I use C++, but it might be rewritten for C too.

Sign In or Register to comment.