SONOFF

BASICR3/RFR3/MINI HTTP API

Version: 2.2  Date: 2021-11-1

BASICR3/RFR3/MINI HTTP API

The device type is diy_plug (type=diy_plug) and the device API interface version is 1 (apivers=1).

  • When the device firmware version < 3.7.6, the device ID can be left blank.
    e.g. “deviceid”: “”
  • When the device firmware version ≥ 3.7.6, the device ID must be filled in.
    e.g. “deviceid”: “1000000001”

ON/OFF Switch

URL: http://[ip]:[port]/zeroconf/switch
Return value format: json
Method: HTTP post

e.g.

1
2
3
4
5
6
{ 
"deviceid": "",
"data": {
"switch": "on"
}
}

 

AttributeTypeOptionalDescription
switchStringNoon: turn the switch on, off: turn the switch off

Power-on State

URL: http://[ip]:[port]/zeroconf/startup
Return value format: json
Method: HTTP post

e.g.

1
2
3
4
5
6
{ 
    "deviceid": "", 
    "data": {
        "startup": "stay"
    } 
 }

 

AttributeTypeOptionalDescription
startupStringNoon: the device is on when power supply is recovered.
off: the device is off when power supply is recovered.
stay: the device status keeps as the same as the state before power supply is gone

WiFi Signal Strength

URL: http://[ip]:[port]/zeroconf/signal_strength
Return value format: json
Method: HTTP post

Request body

e.g.

1
2
3
4
{ 
"deviceid": "",
"data": { }
}

Empty object, no attribute is required.

Response body

e.g.

1
2
3
4
5
6
7
{ 
"seq": 2,
"error": 0,
"data": {
"signalStrength": -67
}
}

 

AttributeTypeOptionalDescription
signalStrengthNumberNoThe WiFi signal strength currently received by the device, negative integer, dBm

    Inching

    URL: http://[ip]:[port]/zeroconf/pulse
    Return value format: json
    Method: HTTP post

    e.g.

    1
    2
    3
    4
    5
    6
    7
    { 
    "deviceid": "",
    "data": {
    "pulse": "on",
    "pulseWidth": 2000
    }
    }

     

    AttributeTypeOptionalDescription
    pulseStringNoon: activate the inching function;
    off: disable the inching function
    pulseWidthNumberYesRequired when “pulse” is on, pulse time length, positive integer, ms, only supports multiples of 500 in range of 500~3600000

      WiFi SSID and Password Setting

      URL: http://[ip]:[port]/zeroconf/wifi
      Return value format: json
      Method: HTTP post

      e.g.

      1
      2
      3
      4
      5
      6
      7
      { 
      "deviceid": "",
      "data": {
      "ssid": "eWeLink",
      "password": "WeLoveIoT"
      }
      }

       

      AttributeTypeOptionalDescription
      ssidStringNoSSID of the WiFi network to which the device will connect
      passwordStringNopassword of the WiFi network to which the device will connect

      OTA Function Unlocking

      URL: http://[ip]:[port]/zeroconf/ota_unlock
      Return value format: json
      Method: HTTP post

      e.g.

      1
      2
      3
      4
      { 
          "deviceid": "", 
          "data": { } 
       }

       

      Empty object, no attribute is required.

      The following failure codes are added to the error field of the response body:
       500: The operation failed and the device has errors. For example, the device ID or API Key error which is not authenticated by the vendor’s OTA unlock service;
       503: The operation failed and the device is not able to request the vendor’s OTA unlock service. For example, the device is not connected to WiFi, the device is not connected to the Internet, the manufacturer’s OTA unlock service is down, etc.

       

      OTA New Firmware

      URL: http://[ip]:[port]/zeroconf/ota_flash
      Return value format: json
      Method: HTTP post

      e.g.

      1
      2
      3
      4
      5
      6
      7
      { 
      "deviceid": "",
      "data": {
      "downloadUrl": "http://192.168.1.184/ota/new_rom.bin",
      "sha256sum": "3213b2c34cecbb3bb817030c7f025396b658634c0cf9c4435fc0b52ec9644667"
      }
      }

       

      AttributeTypeOptionalDescription
      downloadUrlStringNoThe download address of the new firmware, only supports the HTTP protocol, the HTTP server must support the Range request header.
      sha256sumStringNoSHA256 checksum (hash) of the new firmware, it is used to verify the integrity of the new firmware downloaded

       

      The following failure codes are added to the error field of the response body:
       403: The operation failed and the OTA function was not unlocked. The interface “3.2.6 OTA function unlocking” must be successfully called first.
       408: The operation failed and the pre-download firmware timed out. You can try to call this interface again after optimizing the network environment or increasing the network speed.
       413: The operation failed and the request body size is too large. The size of the new OTA firmware exceeds the firmware size limit allowed by the device.
       424: The operation failed and the firmware could not be downloaded. The URL address is unreachable (IP address is unreachable, HTTP protocol is unreachable, firmware does not exist, server does not support Range request header, etc.)
       471: The operation failed and the firmware integrity check failed. The SHA256 checksum of the downloaded new firmware does not match the value of the request body’s sha256sum field. Restarting the device will cause bricking issue.

      Note:

      • The maximum firmware size is 508KB.
      • The SPI flash read mode must be DOUT.

      Get Device Info

      URL: http://[ip]:[port]/zeroconf/info
      Return value format: json
      Method: HTTP post

      e.g.

      1
      2
      3
      4
      { 
      "deviceid": "",
      "data": { }
      }

      Empty object, no attribute is required.

      Response body

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      { 
      "seq": 2,
      "error": 0,
      "data": {
      "switch": "off",
      "startup": "off",
      "pulse": "off",
      "pulseWidth": 500,
      "ssid": "eWeLink",
      "otaUnlock": false,
      "fwVersion": "3.5.0",
      "deviceid": "100000140e",
      "bssid": "ec:17:2f:3d:15:e",
      "signalStrength": -25
      }
      }

       

      Note:

      • Monitor and parse the device’s DNS TXT record to get the device information in real time.

      Pin It on Pinterest