WiFi
The WiFi component handles wireless connection services of a device. The Wifi component uses Wifi
as RPC namespace and provides the methods:
Wifi.GetConfig
to obtain the component's configurationWifi.SetConfig
to update the component's configurationWifi.GetStatus
to obtain the component's statusWifi.Scan
to scan for available WiFi APsWifi.ListAPClients
lists clients connnected to the device's AP.
It uses the key wifi
when enumerated in objects including multiple component payloads, like Shelly.GetStatus
.
RangeExtender
Since version 0.11.0
Range extender functionality is part of the device's WiFi characteristcs. It enables a Gen2+ Shelly device to provide internet connectivity to other shellies connected to its access point with otherwise poor WiFi coverage. It is available on non battery operated devices. Some of the configuration and status properties are specific to this functionality and only available when it is present. It is advisable to enable range extender functionality only when the AP is secured.
Methods
Wifi.SetConfig
Find more about the config properties in config section
Wifi.GetConfig
Find the Wifi.GetConfig response properties in config section
Wifi.GetStatus
Find more about the status response properties in status section
WiFi.Scan
This method returns list of all available networks.
Request
This method takes no parameters.
Response
Attributes in the result:
Property | Type | Description | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| array of objects | Each of these JSON object contains:
|
WiFi.ListAPClients
This method returns list of clients currently connected to the device's access point. Available only when the range extender functionality is available on the device and both AP and RangeExtender are enabled. This method does not require authentication (even when authentication is enabled).
Request
This method takes no parameters.
Response
Attributes in the result:
Property | Type | Description | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| number or null | Unix timestamp of the request, | ||||||||||||||||||
| array of objects | List of objects with information about clients currently connected to the AP of the device containing:
|
Configuration
The configuration of the WiFi component contains information about the access point of the device, the network stations and the roaming settings.
Properties:
Property | Type | Description | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| object | Information about the access point
| ||||||||||||||||||||||||||||||
| object | Information about the sta configuration
| ||||||||||||||||||||||||||||||
| object | Identical to | ||||||||||||||||||||||||||||||
| object | WiFi roaming configuration
|
When changing WiFi station configuration the proccess of applying it causes the Shelly to perform reconnection to the AP(s) about a second after the new config is stored. Connected agents, inbound websocket or outbound MQTT, might experience disconnect events if IP connectivity is over WiFi. Implementations should consider timeouts, LWT notifications, and reconnects after this configuration change.
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.
Status
The status of the WiFi component contains information about the state of the WiFi connection of the device.
Properties:
Property | Type | Description |
---|---|---|
| string or null | Ip of the device in the network ( |
| string | Status of the connection. Range of values: |
| string or null | Ssid of the network ( |
| number | Strength of the signal in dBms |
| number | Number of clients connected to the access point. Present only when AP is enabled and range extender functionality is present and enabled. |
Notifications
This section describes notifications for events specific to the Wifi component. For general information please see this page.
Example
Wifi.SetConfig example
- WiFi.SetConfig HTTP GET Request
- WiFi.SetConfig Curl Request
- WiFi.SetConfig Mos Request
http://192.168.33.1/rpc/WiFi.SetConfig?config={"sta":{"ssid":"Shelly","pass":"Shelly","enable":true}}
curl -X POST -d '{"id":1,"method":"WiFi.SetConfig","params":{"config":{"sta":{"ssid":"Shelly","pass":"Shelly","enable":true}}}}' http://${SHELLY}/rpc
mos --port ${PORT} call WiFi.SetConfig '{"config":{"sta":{"ssid":"Shelly","pass":"Shelly","enable":true}}}'
Response
- WiFi.SetConfig HTTP GET Response
- WiFi.SetConfig Curl Response
- WiFi.SetConfig Mos Response
{
"restart_required": false
}
{
"id": 1,
"src": "shellypro4pm-f008d1d8b8b8",
"params": {
"restart_required": false
}
}
{
"restart_required": false
}
Wifi.GetConfig example
- WiFi.GetConfig HTTP GET Request
- WiFi.GetConfig Curl Request
- WiFi.GetConfig Mos Request
http://192.168.33.1/rpc/WiFi.GetConfig
curl -X POST -d '{"id":1,"method":"WiFi.GetConfig"}' http://${SHELLY}/rpc
mos --port ${PORT} call WiFi.GetConfig
Response
- WiFi.GetConfig HTTP GET Response
- WiFi.GetConfig Curl Response
- WiFi.GetConfig Mos Response
{
"ap": {
"ssid": "ShellyPlus2PM-A8032AB636EC",
"is_open": true,
"enable": true,
"range_extender": {
"enable": false
}
},
"sta": {
"ssid": "Allterco WiFi",
"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
}
}
{
"id": 1,
"src": "shellypro4pm-f008d1d8b8b8",
"params": {
"ap": {
"ssid": "ShellyPlus2PM-A8032AB636EC",
"is_open": true,
"enable": true,
"range_extender": {
"enable": false
}
},
"sta": {
"ssid": "Allterco WiFi",
"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
}
}
}
{
"ap": {
"ssid": "ShellyPlus2PM-A8032AB636EC",
"is_open": true,
"enable": true,
"range_extender": {
"enable": false
}
},
"sta": {
"ssid": "Allterco WiFi",
"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.GetStatus example
- WiFi.GetStatus HTTP GET Request
- WiFi.GetStatus Curl Request
- WiFi.GetStatus Mos Request
http://192.168.33.1/rpc/WiFi.GetStatus
curl -X POST -d '{"id":1,"method":"WiFi.GetStatus"}' http://${SHELLY}/rpc
mos --port ${PORT} call WiFi.GetStatus
Response
- WiFi.GetStatus HTTP GET Response
- WiFi.GetStatus Curl Response
- WiFi.GetStatus Mos Response
{
"sta_ip": "192.168.206.97",
"status": "got ip",
"ssid": "Allterco WiFi",
"rssi": -56,
"ap_client_count": 0
}
{
"id": 1,
"src": "shellypro4pm-f008d1d8b8b8",
"params": {
"sta_ip": "192.168.206.97",
"status": "got ip",
"ssid": "Allterco WiFi",
"rssi": -56,
"ap_client_count": 0
}
}
{
"sta_ip": "192.168.206.97",
"status": "got ip",
"ssid": "Allterco WiFi",
"rssi": -56,
"ap_client_count": 0
}
WiFi.Scan example
- WiFi.Scan HTTP GET Request
- WiFi.Scan Curl Request
- WiFi.Scan Mos Request
http://192.168.33.1/rpc/WiFi.Scan
curl -X POST -d '{"id":1,"method":"WiFi.Scan"}' http://${SHELLY}/rpc
mos --port ${PORT} call WiFi.Scan
Response
- WiFi.Scan HTTP GET Response
- WiFi.Scan Curl Response
- WiFi.Scan Mos Response
{
"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
}
]
}
{
"id": 1,
"src": "shellypro4pm-f008d1d8b8b8",
"params": {
"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
}
]
}
}
{
"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
}
]
}
Wifi.ListAPClients example
- WiFi.ListAPClients HTTP GET Request
- WiFi.ListAPClients Curl Request
- WiFi.ListAPClients Mos Request
http://192.168.33.1/rpc/WiFi.ListAPClients
curl -X POST -d '{"id":1,"method":"WiFi.ListAPClients"}' http://${SHELLY}/rpc
mos --port ${PORT} call WiFi.ListAPClients
Response
- WiFi.ListAPClients HTTP GET Response
- WiFi.ListAPClients Curl Response
- WiFi.ListAPClients Mos Response
{
"ts": 1655723139,
"ap_clients": [
{
"mac": "a4:97:b1:d0:59:65",
"ip": "192.168.33.64",
"ip_static": false,
"mport": 0,
"since": 1655723070
}
]
}
{
"id": 1,
"src": "shellypro4pm-f008d1d8b8b8",
"params": {
"ts": 1655723139,
"ap_clients": [
{
"mac": "a4:97:b1:d0:59:65",
"ip": "192.168.33.64",
"ip_static": false,
"mport": 0,
"since": 1655723070
}
]
}
}
{
"ts": 1655723139,
"ap_clients": [
{
"mac": "a4:97:b1:d0:59:65",
"ip": "192.168.33.64",
"ip_static": false,
"mport": 0,
"since": 1655723070
}
]
}
Notifications example
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