HexArth WIFI Configuration
WIFI Mode
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).
2. 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 WiFi module can receive wireless signals from other devices or routers and access the Internet or other network resources through that wireless network.
3. AP+STA mode (or 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.
WiFi Configuration
When this product leaves the factory, the default WIFI 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 WiFi configuration.
Set Default WiFi Mode on Boot
First, you can use the CMD_WIFI_ON_BOOT command to set the default WiFi operation mode for the robot after boot:
{"T":401,"cmd":3}
- T: The type of the command. The command type is defined in the header file json_cmd.h of the HexArth open-source program. The code 401 indicates that this command is CMD_WIFI_ON_BOOT, which sets the robot's default WiFi operating mode at boot, and the setting is persistent after power loss.
- cmd: The code for the default operating mode.
- 0: WIFI is turned off.
- 1: AP mode.
- 2: STA mode.
- 3: AP+STA mode.
Set WIFI Mode
The following introduces the meaning of JSON command in different modes of WiFi.
CMD_SET_AP - Set AP Mode and Establish WIFI Hotspot
{"T":402,"ssid":"HexArth","password":"12345678"}
- 402: This command is CMD_SET_AP, indicating the setting of the WiFi mode to AP mode.
- ssid: The hotspot name in the 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 default mode is AP mode when it leaves the factory, there is no need to use this command initially to set the AP mode.
CMD_SET_STA - Set STA Mode and Connect to Existing WiFi
{"T":403,"ssid":"yourWiFiName","password":"yourWiFiPassword"}
- 403: This command is CMD_SET_STA, indicating the setting of the WiFi mode to STA mode.
- ssid: The name of the existing WIFI hotspot, which needs to be modified to the name of the WIFI hotspot you want to connect to.
- password: The password of the existing WIFI hotspot needs to be modified to the password corresponding to the WIFI 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 it's the robot's first time setting STA mode, it will automatically switch to AP+STA mode. If it fails to connect to the existing Wi-Fi within 15 seconds, it will automatically revert to AP mode.
CMD_WIFI_APSTA - Set AP+STA Mode and Establish a WIFI Hotspot While Connecting to Existing WIFI
{"T":404,"ap_ssid":"HexArth","ap_password":"12345678","sta_ssid":"yourWiFiName","sta_password":"yourWiFiPassword"}
- 404: This command is CMD_WIFI_APSTA, indicating the setting of the WiFi mode to AP+STA mode.
- ap_ssid: The hotspot name in the AP mode.
- ap_password: The hotspot password in AP mode.
- sta_ssid: The name of the existing WIFI hotspot in STA mode, which needs to be modified to the name of the WIFI hotspot you want to connect to.
- sta_password: The password of the existing WIFI hotspot in STA mode, which needs to be modified to the password corresponding to the WIFI hotspot in STA mode.
Using this command, the robot will connect to an existing Wi-Fi network while simultaneously creating 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 explanations provide the meanings of various JSON commands for configuring different WiFi modes.
View WiFi Configuration Information
View WiFi configuration information by using CMD_WIFI_INFO, input:
{"T":405}
- 405: This command is CMD_WIFI_INFO, indicating to retrieve the robot's Wi-Fi configuration information.
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 in STA or AP+STA mode. If the robot is only in AP mode, it displays "0.0.0.0".
- rssi: The Wi-Fi signal strength in STA mode. If the robot is only in AP mode, it displays 0.
- wifi_mode_on_boot: The default working mode of WIFI after power on, the specific meaning of the code is described in "CMD_WIFI_ON_BOOT".
- sta_ssid: Set to the name of the WIFI hotspot that STA mode connects to.
- sta_password: Set to the password of the WIFI hotspot that the STA mode connects to.
- ap_ssid: The hotspot name in the AP mode.
- ap_password: The hotspot password in AP mode.
Create WiFi Configuration File
The following introduces the command to generate a WiFi configuration file.
The WIFI 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"}
1. CMD_WIFI_CONFIG_CREATE_BY_STATUS - Save Current WIFI Mode Status and Generate wifiConfig.json File
{"T":406}
- 406: This command is CMD_WIFI_CONFIG_CREATE_BY_STATUS indicating that the wifiConfig.json file is generated with the current WIFI mode state.
- For example, if the current WIFI mode is AP mode, after calling this command, the next power on will automatically set to AP mode.
The following message will be fed back 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"}
2. CMD_WIFI_CONFIG_CREATE_BY_INPUT - Save Input Information and Generate 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 indicating that it will save the input and generate the wifiConfig.json file.
- mode: The code of the default operating mode.
- 0: WIFI is turned off.
- 1: AP mode.
- 2: STA mode.
- 3: AP+STA mode.
Turn off WIFI
Finally, you can turn off WiFi by using CMD_WIFI_STOP.
{"T":408}
- 408: This command is CMD_WIFI_STOP, indicating the turning off WIFI.