Skip to main content

WiFi

The WiFi component is called WiFi. It handles wireless connection services of a device. It supports the following methods:

WiFi.GetStatus#

This method returns the status of the component instance.

Request#

This method takes no parameters.

http://192.168.33.1/rpc/WiFi.GetStatus

Response#

Attributes in the result:

  • sta_ip: string or null, ip of the device in the network (null if disconnected)
  • status: string, status of the connection. Range of values: {disconnected, connecting, connected, got ip}
  • ssid: string or null, ssid of the network (null if disconnected)
  • rssi: number, strength of the signal in dBms.
{
"sta_ip": "10.33.55.131",
"status": "got ip",
"ssid": "TestZone",
"rssi": -56
}

WiFi.GetConfig#

This method returns the configuration of the component instance.

Request#

This method takes no parameters.

http://192.168.33.1/rpc/WiFi.GetConfig

Response#

Attributes in the result:

  • ap: JSON object, information about the access point
    • ssid: string or null, ssid of the access point
    • is_open: boolean, true if the access point is open, false otherwise
    • enable: boolean, true if the acces point is enabled, false otherwise
  • sta: JSON object, information about the sta configuration
    • ssid: string or null, ssid of the network
    • is_open: boolean, true if the network is open, false otherwise
    • enable: boolean, true if the configuration is enabled, false otherwise
    • ipv4mode: string, IPv4 mode. Range of values: {dhcp, static}
    • ip: string or null, ip to use when ipv4mode is static
    • netmask: string or null, netmask to use when ipv4mode is static
    • gw: string or null, gateway to use when ipv4mode is static
    • nameserver: string or null, nameserver to use when ipv4mode is static
  • sta1: JSON object, identical to sta
  • roam: JSON object, WiFi roaming configuration
    • rssi_thr: number, rssi threshold - when reached will trigger the access point roaming. Default value: -80.
    • interval: number, interval at which to scan for better acsess points. Enabled if set to positive number, disabled if set to 0. Default value: 60.
{
"ap": {
"ssid": "shellypro4pm-f008d1d8b8b8",
"is_open": true,
"enable": true
},
"sta": {
"ssid": "TestZone",
"is_open": false,
"enable": true,
"ipv4mode": "dhcp",
"ip": null,
"netmask": null,
"gw": null,
"nameserver": null
},
"sta1": {
"ssid": null,
"is_open": true,
"enable": false,
"ipv4mode": "dhcp",
"ip": null,
"netmask": null,
"gw": null,
"nameserver": null
},
"roam": {
"rssi_thr": -80,
"interval": 60
}
}

WiFi.SetConfig#

This method makes changes in the configuration of the component instance.

Request#

Parameters:

  • config: JSON object, configuration to be applied. This object should be identical in structure to the JSON returned by WiFi.GetConfig, containing only the keys that need to be modified. Required
caution

In case you want to set a new password-protected WiFi network in your configuration through WiFi.SetConfig, you must include the property pass: string (specifying the network password), together with the ssid in the config object. This property is not shown in the response of WiFi.GetConfig to prevent leaking credentials.

Set STA1 to be a network called 'Home' with password 'Isx8c2gf6Et45'.
curl -X POST -d '{"id":1, "src":"user_1", "method":"WiFi.SetConfig",
"params":{"config":{"sta1":{"ssid":"Home", "pass":"Isx8c2gf6Et45"}}}}' http://${SHELLY}/rpc

Response#

Attributes in the result:

  • restart_required: boolean, true if restart is required to apply the changes, false otherwise
{
"id": 1,
"src": "shellypro4pm-f008d1d8b8b8",
"dst": "user_1",
"result": {
"restart_required": false
}
}

WiFi.Scan#

This method returns list of all available networks.

Request#

This method takes no parameters.

http://192.168.33.1/rpc/WiFi.Scan

Response#

Attributes in the result:

  • results: array of JSON objects, each of these JSON object contains:
    • ssid: string or null, ssid of the network (null in case of hidden network)
    • bssid: string, bssid of the network
    • auth: number, authentication method. Range of values: {0->OPEN, 1->WEP, 2->WPA_PSK, 3->WPA2_PSK, 4->WPA_WPA2_PSK, 5->WPA2_ENTERPRISE}
    • channel: number, network channel
    • rssi: number, strength of the signal in dBms
{
"results":[
{
"ssid": "ShellyPro4PM-F008D1D89064",
"bssid": "f0:08:d1:d8:90:65",
"auth": 0,
"channel": 11,
"rssi": -70
},
{
"ssid": "Shelly",
"bssid": "26:18:d6:82:2b:80",
"auth": 3,
"channel": 11,
"rssi": -87
},
{
"ssid": "Allterco Guests",
"bssid": "ba:fb:e4:f7:0f:7f",
"auth": 0,
"channel": 6,
"rssi": -59
}
]
}

Notifications#

This section describes notifications for events specific to the Wifi component. For general information please see this page.

The Wifi component can send notifications for the following events:

  • Wifi STA connection attempt failed:

Example 1:

Notify that Wifi STA connection attempt has failed.
{
"src": "shellypro4pm-f008d1d8b8b8",
"dst": "user_1",
"method": "NotifyEvent",
"params": {
"ts": 1631267074.94,
"events": [
{
"component": "wifi",
"event": "sta_connect_fail",
"reason": 15,
"ts": 1631267074.94
}
]
}
}

reason: number, see this reference for details

  • Wifi STA disconnect:

Example 2:

Notify that Wifi STA has disconnected.
{
"src": "shellypro4pm-f008d1d8b8b8",
"dst": "user_1",
"method": "NotifyEvent",
"params": {
"ts": 1631267029.96,
"events": [
{
"component": "wifi",
"event": "sta_disconnected",
"sta_ip": null,
"ssid": null,
"reason": 8,
"ts": 1631267029.96
}
]
}
}

reason: number, see this reference for details