Skip to main content

Wi-Fi Configuration

Wi-Fi Modes

Wireless network devices typically support the following three operating modes:

  1. AP Mode (Access Point Mode):

Configure the wireless router or wireless access point as the primary network entry point. In this mode, the device acts as the center of the network, allowing other devices to connect to it so that they can access the Internet or local network resources. AP mode is commonly used to create a wireless local area network (WLAN).

  1. STA Mode (Station Mode):

STA mode configures a wireless device as a client to connect to an existing wireless network, typically an access point (AP) mode device. In STA mode, the Wi-Fi module can receive wireless signals from other devices or routers and access the Internet or other network resources through that wireless network.

  1. AP+STA Mode (also known as Repeater Mode):

AP+STA is a combination mode that allows a device to function as both an Access Point and a Station simultaneously. In this mode, the device can connect to an existing wireless network (STA mode) and simultaneously create a new wireless network (AP mode), allowing other devices to connect to it and access the Internet or other network resources through it. This mode is often used to extend the coverage range of a wireless network and relay the signal to more distant areas.

Wi-Fi Configuration

When this product leaves the factory, the default Wi-Fi is in AP mode. If you want to set it to another mode, you can input the corresponding JSON command in the JSON command input box in the Web interface, or input the JSON command through UART/USB communication. Below, we will explain the specific meanings of the JSON commands related to Wi-Fi configuration.

Set Default Wi-Fi Mode on Boot

First, use the CMD_WIFI_ON_BOOT command to set the default Wi-Fi working mode after the robot powers on:

{ "T": 401, "cmd": 3 }
  • T: The type of this command. Command types are defined in the header file json_cmd.h of the HexArth open-source program. 401 indicates that this command is CMD_WIFI_ON_BOOT, which sets the robot's default Wi-Fi working mode at power-on, and the setting is saved after power loss.
  • cmd: The code for the default operating mode.
    • 0: The Wi-Fi is turned off.
    • 1: AP mode.
    • 2: STA mode.
    • 3: AP+STA mode.

Set Wi-Fi Mode

The meanings of JSON commands for setting each Wi-Fi mode are explained below:

CMD_SET_AP - Set AP Mode, Create a Wi-Fi Hotspot

{ "T": 402, "ssid": "HexArth", "password": "12345678" }
  • 402: This command is CMD_SET_AP, meaning set the Wi-Fi mode to AP mode.
  • ssid: The hotspot name in AP mode.
  • password: The hotspot password in AP mode. Using this command, the robot will create a Wi-Fi hotspot, allowing other devices (e.g., phones, computers) to connect to it. Since the factory default is AP mode, you do not need to use this command initially to set AP mode.

CMD_SET_STA - Set STA Mode, Connect to an Existing Wireless Network

{ "T": 403, "ssid": "yourWiFiName", "password": "yourWiFiPassword" }
  • 403: This command is CMD_SET_STA, meaning set the Wi-Fi mode to STA mode.
  • ssid: The hotspot name of the existing Wi-Fi network; you need to change this to the Wi-Fi hotspot name you want to connect to.
  • password: The password of the existing Wi-Fi hotspot; you need to change this to the corresponding password for the Wi-Fi hotspot. Using this command, the robot will connect to the existing wireless network. The wireless network will assign an IP address to the robot, which will be displayed on the second line of the OLED screen. This IP address can be used for JSON command communication via HTTP requests. Note: If the robot is setting STA mode for the first time, it will automatically switch to AP+STA mode; if it fails to connect to the existing Wi-Fi after 15 seconds, it will automatically switch to AP mode.

CMD_WIFI_APSTA - Set AP+STA Mode, Create a Wi-Fi Hotspot While Connecting to an Existing Wi-Fi Network

{
"T": 404,
"ap_ssid": "HexArth",
"ap_password": "12345678",
"sta_ssid": "yourWiFiName",
"sta_password": "yourWiFiPassword"
}
  • 404: This command is CMD_WIFI_APSTA, meaning set the Wi-Fi mode to AP+STA mode.
  • ap_ssid: The hotspot name in AP mode.
  • ap_password: The hotspot password in AP mode.
  • sta_ssid: The hotspot name of the existing Wi-Fi network for STA mode; you need to change this to the Wi-Fi hotspot name you want to connect to.
  • sta_password: The password of the existing Wi-Fi hotspot for STA mode; you need to change this to the corresponding password for the STA mode Wi-Fi hotspot.
  • Using this command, the robot will connect to the existing Wi-Fi network and simultaneously create a hotspot named HexArth. In this mode, the OLED screen will display the Wi-Fi name of the AP on the first line and the IP address assigned by the wireless network on the second line.
  • The above explains the usage meanings of JSON commands for setting each Wi-Fi mode.

View Wi-Fi Settings

Use CMD_WIFI_INFO to view Wi-Fi settings. Enter:

{"T":405}

405: This command is CMD_WIFI_INFO, meaning retrieve the robot's Wi-Fi settings. The return value is shown below:

{
"ip": "192.168.10.90",
"rssi": -50,
"wifi_mode_on_boot": 3,
"sta_ssid": "yourWiFiName",
"sta_password": "yourWiFiPassword",
"ap_ssid": "HexArth",
"ap_password": "12345678"
}
  • ip: The IP address of the robot when in STA mode or AP+STA mode; if the robot is only in AP mode, it shows '0.0.0.0'.
  • rssi: The Wi-Fi signal strength in STA mode; if the robot is only in AP mode, it shows 0.
  • wifi_mode_on_boot: The default Wi-Fi working mode after power-on; the meaning of the code is described in "CMD_WIFI_ON_BOOT".
  • sta_ssid: The Wi-Fi hotspot name set for STA mode to connect to.
  • sta_password: The Wi-Fi hotspot password set for STA mode to connect to.
  • ap_ssid: The hotspot name in AP mode.
  • ap_password: The hotspot password in AP mode.

View Wi-Fi Configuration File

The following introduces the command to generate a Wi-Fi configuration file. The Wi-Fi configuration file is a wifiConfig.json stored in Flash, and the file will be created when the first content to be saved is generated, and the content of the file is as follows:

{
"wifi_mode_on_boot": 3,
"sta_ssid": "JSBZY-2.4G",
"sta_password": "waveshare0755",
"ap_ssid": "HexArth",
"ap_password": "12345678"
}

CMD_WIFI_CONFIG_CREATE_BY_STATUS - Save the Current Wi-Fi Mode State and Generate the wifiConfig.json File

{"T":406}
  • 406: This command is CMD_WIFI_CONFIG_CREATE_BY_STATUS, meaning generate the wifiConfig.json file based on the current Wi-Fi mode state.
  • For example, if the current Wi-Fi mode is AP mode, after calling this command, the robot will automatically be set to AP mode the next time it powers on. The following feedback is provided after the input:
{
"info": "/wifiConfig.json created.",
"wifi_mode_on_boot": 1,
"sta_ssid": "JSBZY-2.4G",
"sta_password": "waveshare0755",
"ap_ssid": "HexArth",
"ap_password": "12345678"
}

CMD_WIFI_CONFIG_CREATE_BY_INPUT - Save the Entered Information and Generate the wifiConfig.json File

{
"T": 407,
"mode": 3,
"ap_ssid": "HexArth",
"ap_password": "12345678",
"sta_ssid": "JSBZY-2.4G",
"sta_password": "waveshare0755"
}
  • 407: This command is CMD_WIFI_CONFIG_CREATE_BY_INPUT, meaning save the entered information and generate the wifiConfig.json file.
  • mode: The code of the default operating mode.
    • 0: The Wi-Fi is turned off.
    • 1: AP mode.
    • 2: STA mode.
    • 3: AP+STA mode.

Turn Off Wi-Fi

Finally, you can use CMD_WIFI_STOP to turn off the Wi-Fi function.

{"T":408}
  • 408: This command is CMD_WIFI_STOP, meaning turn off Wi-Fi.