RoArm-M2-S WIFI Configuration

From Waveshare Wiki
Jump to: navigation, search

WiFi Mode

Generally, Wifi configuration includes the following three 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 Wi-Fi 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) while also creating a new wireless network (AP mode) that allows other devices to connect to it and access the internet or other network resources. This mode is often used to extend the coverage range of a wireless network and relay the signal to more distant areas.

WiFi Configuration

RoArm-M2-S is shipped with the default configuration of WiFi in AP mode. If you wish to change it to a different mode, you can achieve this by entering the corresponding JSON commands in the JSON command input box on the web interface or through serial/USB communication. Below, we will explain the specific meanings of the JSON commands related to WiFi configuration.

Set The Default Mode of WiFi Upon Startup

First, you can use the CMD_WIFI_ON_BOOT command to set the default operation mode of WiFi after booting the robotic arm.

{"T":401,"cmd":3}
  • T: This command's type is defined in the "json_cmd.h" header file of the RoArm-M2-S open-source demo. The value "401" represents that this command is "CMD_WIFI_ON_BOOT," which can set the default operating mode of the robotic arm's WiFi upon startup, and it will be retained even after power loss.
  • cmd: The code for the default operating mode.
    • 0: Wi-Fi is in a turned-off state.
    • 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 up AP Mode to Create A WIFI Hotspot

{"T":402,"ssid":"RoArm-M2","password":"12345678"}
  • 402: This command is "CMD_SET_AP," indicating the setting of the WiFi mode to AP mode.
  • ssid: the hotspot name in AP mode.
  • password: Wi-Fi password in AP mode.

By using this command, the robotic arm will establish a Wi-Fi hotspot, allowing other devices (e.g., smartphones, and computers) to connect to this hotspot. 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 to Connect the 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 hotspot name of the existing WIFI needs to be changed to the name of the WIFI hotspot you want to connect to.
  • password: the password of the current WiFi hotspot needs to be changed to the corresponding password of the WiFi hotspot.

Using this command, the robotic arm will connect to an existing wireless network. The wireless network will assign an IP address to the robotic arm, 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 robotic arm is set to STA mode for the first time, it will automatically switch to AP+STA mode. If it fails to connect to an existing Wi-Fi network after 15 seconds, the robotic arm will automatically switch to AP mode.

CMD_WIFI_APSTA - Set up AP+STA Mode to Establish a WIFI Hotspot While Connecting to an Existing WIFI

{"T":404,"ap_ssid":"RoArm-M2","ap_pawword":"12345678","sta_ssid":"yourWiFiName","sta_password":"yourWiFiPassword"}
  • 404: this command is CMD_WIFI_APSTA indicating the WiFi mode is set as AP+STA.
  • ap_ssid: the hotspot name in AP mode.
  • ap_password: the password of the hotspot in AP mode.
  • sta_ssid: The hotspot name of the existing WIFI in STA mode needs to be changed to the WIFI hotspot name you want to connect to.
  • sta_password: The password of the existing WIFI hotspot in STA mode needs to be changed to the password corresponding to the WIFI hotspot in STA mode.

Using this command, the robotic arm will connect to an existing Wi-Fi network while simultaneously creating a hotspot named "RoArm-M2." 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 inidcating the WiFi 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":"RoArm-M2","ap_password":"12345678"}
  • ip: the IP address of the robotic arm in STA mode or AP+STA mode. If the robotic arm is only in AP mode, it will display "0.0.0.0".
  • rssi: WIFI signal strength in STA mode; if the robotic arm is in STA mode only, it is displayed as 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 name of the hotspot in 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.
WiFi configuration file storage in wifiConfig.json of Flash. When you store the content for the first time, the file will be created. The content of the file is shown below:

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

1. CMD_WIFI_CONFIG_CREATE_BY_STATUS - Save the 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":"RoArm-M2","ap_password":"12345678"}


2. CMD_WIFI_CONFIG_CREATE_BY_INPUT - Save the input and generate the wifiConfig.json file

{"T":407,"mode":3,"ap_ssid":"RoArm-M2","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 off.
    • 1: AP mode.
    • 2: STA mode.
    • 3: AP+STA mode.

Turning off WiFi

Finally, you can turn off WiFi by using CMD_WIFI_STOP.

{"T":408}
  • 408: this command is CMD_WIFI_STOP for turning off WIFI.

This section describes what it means to use the JSON commands for robot arm WIFI configuration and return to the RoArm-M2-S main interface to learn more aspects of robot arm use.

RoArm-M2-S Tutorial Directory

RoArm-M2-S User Tutorial

RoArm-M2-S ROS2 Basic Tutorial