Skip to content

RaftNetworkManagerSysMod

Rob Dobson edited this page Oct 12, 2024 · 1 revision

NetworkManager SysMod

Overview

The Network Manager module is responsible for managing the network state, including WiFi and Ethernet configuration, retries, and connection monitoring. It provides APIs to configure WiFi in both STA (Station) and AP (Access Point) modes, manage Ethernet settings, and monitor network status.

NetworkManager Settings

When constructed normally (in RaftCoreApp for instance) the NetworkManager is configured using the contents of the SysTypes key NetMan. The settings available to configure Network are described in Network Manager Settings


Constructor

NetworkManager::NetworkManager

  • Parameters:
    • pModuleName: The name of the network module.
    • sysConfig: The system configuration object.

Initializes the Network Manager with the given module name and system configuration. It also sets the module as a singleton instance.


Setup

NetworkManager::setup

Sets up the network based on the provided configuration, including enabling WiFi STA and AP modes, setting SSID and password, and configuring the hostname.

  • Steps:
    • Retrieves the network settings from the system configuration.
    • Sets the hostname based on the system's friendly name (if available).
    • Configures the network (WiFi STA/AP modes and Ethernet).
    • Logs the network configuration.
    • Configures WiFi STA and AP SSID and passwords.

Loop

NetworkManager::loop

The loop function is called frequently to service the network system and monitor changes in connection status. It triggers registered callbacks on status changes.

  • Functionality:
    • Services the network system.
    • Checks for changes in connection status (whether an IP address is assigned).
    • Notifies registered callbacks if the status changes.

API Endpoints

The NetworkManager exposes several REST API endpoints to control network settings. These include configuring WiFi, scanning for networks, and managing WiFi credentials.

API List

The API for DeviceManager is included in the Raft API List

Endpoint Method Description
/w GET Setup WiFi in STA mode, e.g., /w/SSID/password.
/wap GET Setup WiFi in AP mode, e.g., /wap/SSID/password.
/wc GET Clear WiFi settings.
/wifipause GET Pause or resume WiFi, e.g., /wifipause/pause, /wifipause/resume.
/wifiscan GET Scan for WiFi networks, e.g., /wifiscan/start, /wifiscan/results.

API Details

/w (WiFi STA Setup)

  • Description: Configures the WiFi STA mode by setting the SSID and password.
  • Method: GET
  • URL Parameters:
    • SSID: The WiFi SSID.
    • Password: The WiFi password.
  • Example: /w/SSID/password
  • Response: JSON with success or failure of configuration.

/wap (WiFi AP Setup)

  • Description: Configures the WiFi AP mode by setting the SSID and password.
  • Method: GET
  • URL Parameters:
    • SSID: The WiFi AP SSID.
    • Password: The WiFi AP password.
  • Example: /wap/SSID/password
  • Response: JSON with success or failure of configuration.

/wc (WiFi Clear)

  • Description: Clears the stored WiFi credentials and optionally restarts the system.
  • Method: GET
  • URL Parameters: Optionally, norestart to avoid restarting the system.
  • Example: /wc/norestart
  • Response: JSON with success or failure of the WiFi clear operation.

/wifipause (WiFi Pause/Resume)

  • Description: Pauses or resumes WiFi operations.
  • Method: GET
  • URL Parameters:
    • pause to pause WiFi.
    • resume to resume WiFi.
  • Example: /wifipause/pause
  • Response: JSON with the WiFi pause status.

/wifiscan (WiFi Scan)

  • Description: Scans for available WiFi networks.
  • Method: GET
  • URL Parameters:
    • start to start scanning.
    • results to get scan results.
  • Example: /wifiscan/start
  • Response: JSON with the list of available networks.

JSON Status and Debug

NetworkManager::getStatusJSON

Returns the current network status in JSON format, including the system version and connection status.

  • Example:
    {
      "rslt": "ok",
      "v": "1.0.0",
      "hostname": "mydevice"
    }

Clone this wiki locally