1.注册设备

简要描述

-本api适用于序列号开头为W71/W72的设备,appid和appsecret请到wdev.wmj.com.cn 填写手机号登录获取。

请求URL

  • https://wdev.wmj.com.cn/deviceApi/register

请求方式

  • POST

请求格式

  • json

参数

{
	"app_id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
	"app_secret": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
	"device_sn": "W71XXXXXXXX"
}
参数名必选类型说明
app_idstring用户app_id
app_secretstring用户app_secret
device_snstring设备序列号
返回示例
{
	"code": 0,
	"msg": "注册成功"
}
{
	"code": 1005,
	"msg": "设备已注册"
}
返回参数说明
参数名类型说明
codeint错误码 0成功其他异常
msgint描述
备注
  • 更多返回错误代码请看使用须知的错误代码描述

2.开电/关电/重启/进入配网

请求说明

请求地址:https://wdev.wmj.com.cn/deviceApi/send

请求协议:POST

请求格式:application/json

请求示例:

{
	"app_id":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
	"app_secret":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
	"device_sn": "W71xxxxxxxx",
	"type":1,
	"data": {
		"cmd_type":"turnon",
		"info":{}
	}
}
参数类型说明
app_idString接口参数:app_id
app_secretString接口参数:app_secret
device_snString接口参数:设备序列号
typeInteger接口参数:请求类型,固定为1
dataObject接口参数:透传数据,发送到目标device_sn
data.cmd_typeString业务参数:操作命令
turnon:开断路器
turnoff:关断路器
restart:重启断路器
wifi_config:wifi版进入配网模式
data.infoObject业务参数:命令信息

回复:

{
	"data": {
		"device_sn": "W71xxxxxxxx",
		"msg_id": 54,
		"type": 1,
		"cmd_type": "turnon",
		"info": {
			"code": 0,
			"msg": ""
		}
	}
}
参数类型说明
dataObject接口参数:透传数据,目标device_sn的回复
data.cmd_typeString业务参数:断路器回复,请求命令之后加_ack
data.infoObject业务参数:命令信息
data.info.codeInteger错误码:0:没有错误 其他:错误
info.info.msgString错误信息

3.查询设备信息(功率、电流、电压等相关信息)

请求说明

请求地址:https://wdev.wmj.com.cn/deviceApi/send

请求协议:POST

请求格式:application/json

请求示例:

{
	"app_id":"xxx",
	"app_secret":"xxx",
	"device_sn": "W71xxxxxxxx",
	"type":1,
	"data": {
		"cmd_type":"getdevinfo",
		"info":{}
	}
}
参数类型说明
app_idString接口参数:app_id
app_secretString接口参数:app_secret
device_snString接口参数:设备序列号
typeInteger接口参数:请求类型,固定为1
dataObject接口参数:透传数据,发送到目标device_sn
data.cmd_typeString业务参数:操作命令
getdevinfo:查询设备信息

 

回复:

{
	"code": 0,
	"data": {
		"device_sn": "W7XXXXXX",
		"cmd_type": "getdevinfo",
		"info": {
			"balance": 1,
			"code": 0,
			"electric_current": 0,
			"heartbeat": 1,
			"iccid": "898604D6102271545432",
			"imei": "864269069753586",
			"leakage_current": 30,
			"msg": "",
			"overcurrent": 40,
			"overheat": 80,
			"overvoltage": 275,
			"power": 0,
			"prepay": false,
			"rssi": -70,
			"switch_state": 0,
			"temperature": 14,
			"total_electricity": 0,
			"undervoltage": 160,
			"version": "1.0.4",
			"voltage": 0
		}
	}
}
参数类型说明
dataObject接口参数:透传数据,目标device_sn的回复
data.cmd_typeString业务参数:断路器回复
data.infoObjectinfo
data.info.statusInteger1:成功 0:失败
为1时下面的数据可用
data.info.iccidStringiccid
data.info.imeiStringimei
data.info.rssiIntegerrssi
data.info.heartbeatInteger业务参数:断路器工作状态
1: 正常
0:异常
data.info.switch_stateInteger断路器状态
1:打开
0:断开
data.info.electric_currentDouble当前电流(单位:A)
data.info.powerDouble当前功率(单位:W)
data.info.total_electricityDouble总用电量(单位:kw*h)
data.info.voltageDouble当前电压(单位:V)
data.info.prepayBoolean电量计费功能是否开启
data.info.balanceDouble电量余额,(单位:kW*h),
data.info.temperatureDouble当前设备温度
data.info.leakage_currentInteger漏电阈值,漏电超过阈值断电 (单位:mA)
data.info.overcurrentInteger过流阈值,电流超过阈值断电 (单位:A)
data.info.overheatInteger过热阈值,温度超过阈值断电 (单位:°C)
data.info.overvoltageInteger过压阈值,电压超过阈值断电(单位:V)
data.info.undervoltageInteger低压阈值,电压低于阈值断电 (单位:V)
data.info.codeInteger错误码:0:没有错误 其他:错误
data.info.msgString错误信息

4.延时关电 delayturnoff(71.0.33及以上版本支持)

-- 在关电状态下,调用本接口通电,延时X秒后断电
请求地址:https://wdev.wmj.com.cn/deviceApi/send

请求协议:POST

请求格式:application/json

请求示例:

{
	"app_id":"xxx",
	"app_secret":"xxx",
	"device_sn": "W7********",
	"type":1,
	"data": {
        "cmd_type": "delayturnoff",
        "info":{
			"delaytime": 15,  //15秒
        }
	}
}
参数类型说明
app_idString接口参数:app_id
app_secretString接口参数:app_secret
device_snString接口参数:设备序列号
typeInteger接口参数:请求类型,固定为1
dataObject接口参数:透传数据,发送到目标device_sn
data.cmd_typeString业务参数:开电后延时断电命令
delayturnoff:设置参数
data.info.delaytimeInteger延时时间 (单位:秒) 不建议超过900秒

回复:

{
  "type": 1,
  "device_sn": "W713BB43E04",
  "info": {
    "code": 0,
    "msg": "Auto turnoff after 15 seconds"
  },
  "msg_id": 208,
  "cmd_type": "delayturnoff"
}

5.延时开电 delayturnon(71.0.33及以上版本支持)

-- 在开电状态下,调用本接口断电,延时X秒后开电
请求地址:https://wdev.wmj.com.cn/deviceApi/send

请求协议:POST

请求格式:application/json

请求示例:

{
	"app_id":"xxx",
	"app_secret":"xxx",
	"device_sn": "W7********",
	"type":1,
	"data": {
        "cmd_type": "delayturnon",
        "info":{
			"delaytime": 15,  //15秒
        }
	}
}
参数类型说明
app_idString接口参数:app_id
app_secretString接口参数:app_secret
device_snString接口参数:设备序列号
typeInteger接口参数:请求类型,固定为1
dataObject接口参数:透传数据,发送到目标device_sn
data.cmd_typeString业务参数:开电后延时断电命令
delayturnon:设置参数
data.info.delaytimeInteger延时时间 (单位:秒) 不建议超过900秒

回复:

{
  "type": 1,
  "device_sn": "W71XXXXXXXX",
  "info": {
    "code": 0,
    "msg": "Auto turnon after 15 seconds"
  },
  "msg_id": 208,
  "cmd_type": "delayturnon"
}

6.断路器设置

请求地址:https://wdev.wmj.com.cn/deviceApi/send

请求协议:POST

请求格式:application/json

请求示例:

{
	"app_id":"xxx",
	"app_secret":"xxx",
	"device_sn": "W7********",
	"type":1,
	"data": {
        "cmd_type": "setting",
        "info":{
			"leakage_current": 30,  //--漏电阈值 单位 mA  超过阈值拉闸
			"overcurrent": 40,      //--过流阈值 单位 A   超过阈值拉闸
			"overheat": 80,         //--过热阈值 单位 °C  超过阈值拉闸
			"overvoltage": 275,     //--过压阈值 单位 V   超过阈值拉闸
			"undervoltage": 160,    //--欠压阈值 单位 V   低于阈值拉闸
        }
	}
}
参数类型说明
app_idString接口参数:app_id
app_secretString接口参数:app_secret
device_snString接口参数:设备序列号
typeInteger接口参数:请求类型,固定为1
dataObject接口参数:透传数据,发送到目标device_sn
data.cmd_typeString业务参数:操作命令
setting:设置参数
data.info.leakage_currentInteger漏电阈值,漏电超过阈值断电 (单位:mA)
data.info.overcurrentInteger过流阈值,电流超过阈值断电 (单位:A)
data.info.overheatInteger过热阈值,温度超过阈值断电 (单位:°C)
data.info.overvoltageInteger过压阈值,电压超过阈值断电(单位:V)
data.info.undervoltageInteger低压阈值,电压低于阈值断电 (单位:V)

回复:

{
	"code": 0,
	"data": {
		"device_sn": "W71XXXXXXXX",
		"cmd_type": "setting",
		"info": {
			"code": 0,
			"msg": ""
		}
	}
}

7.设置过流高低压超限报警并跳闸

请求地址:https://wdev.wmj.com.cn/deviceApi/send

请求协议:POST

请求格式:application/json

请求示例:

{
	"app_id": "{{wmjv2appid}}",
	"app_secret": "{{wmjv2appsecret}}",
	"device_sn": "W713XXXXXXX",
	"type":1,
	"data": {
        "cmd_type": "uart_cmd",
        "info":{
			//若指标 >63A,>250V,<150V,发送警告并跳闸
			"hex_cmd": "55AA00060014120000100101003F030100FA040100960800001E32"
        }
	}
}

回复:

{
	"code": 0,
	"data": {
		"device_sn": "W713XXXXXXX",
		"msg_id": 68,
		"type": 1,
		"cmd": "",
		"app_id": "",
		"cmd_type": "uart_cmd",
		"info": {
			"code": 0,
			"hex_ack": "55AA030700101100000C0300000D0400001E05000050BD",
			"msg": ""
		}
	}
}

8.设置过流高低压超限报警不跳闸

请求地址:https://wdev.wmj.com.cn/deviceApi/send

⚠️ 警告: 开启后保护功能失效

请求协议:POST

请求格式:application/json

请求示例:

{
	"app_id": "{{wmjv2appid}}",
	"app_secret": "{{wmjv2appsecret}}",
	"device_sn": "W71FXXXXXXX",
	"type":1,
	"data": {
        "cmd_type": "uart_cmd",
        "info":{
			//>63A,>250V,<150V,30kWh余额,发送警告不跳闸
			"hex_cmd": "55AA00060014120000100100003F030000FA040000960800001E38"
        }
	}
}

回复:

{
	"code": 0,
	"data": {
		"device_sn": "W71XXXXXXXX",
		"msg_id": 68,
		"type": 1,
		"cmd": "",
		"app_id": "",
		"cmd_type": "uart_cmd",
		"info": {
			"code": 0,
			"hex_ack": "55AA03070014120000100100003F030000FA040000960800001E3C",
			"msg": ""
		}
	}
}

9.设置超负载漏电高温报警并跳闸

请求地址:https://wdev.wmj.com.cn/deviceApi/send

请求协议:POST

请求格式:application/json

请求示例:

{
	"app_id": "{{wmjv2appid}}",
	"app_secret": "{{wmjv2appsecret}}",
	"device_sn": "W71XXXXXXXX",
	"type":1,
	"data": {
        "cmd_type": "uart_cmd",
        "info":{
			//设置负载>13kW漏电>30mA温度>80度,任一条件超过限制跳闸。
			"hex_cmd": "55AA000600101100000C0301000D0401001E05010050BC"
        }
	}
}

回复:

{
	"code": 0,
	"data": {
		"device_sn": "W71XXXXXXXX",
		"msg_id": 68,
		"type": 1,
		"cmd": "",
		"app_id": "",
		"cmd_type": "uart_cmd",
		"info": {
			"code": 0,
			"hex_ack": "55AA030700101100000C0301000D0401001E05010050C0",
			"msg": ""
		}
	}
}

10.设置超负载漏电高温报警不跳闸

请求地址:https://wdev.wmj.com.cn/deviceApi/send

⚠️ 警告: 开启后保护功能失效

请求协议:POST

请求格式:application/json

请求示例:

{
	"app_id": "{{wmjv2appid}}",
	"app_secret": "{{wmjv2appsecret}}",
	"device_sn": "W71XXXXXXXX",
	"type":1,
	"data": {
        "cmd_type": "uart_cmd",
        "info":{
			//设置负载13kW漏电30mA温限80度,超过限制不跳闸。
			"hex_cmd": "55AA000600101100000C0300000D0400001E05000050B9"
        }
	}
}

回复:

{
	"code": 0,
	"data": {
		"device_sn": "W71XXXXXXXX",
		"msg_id": 68,
		"type": 1,
		"cmd": "",
		"app_id": "",
		"cmd_type": "uart_cmd",
		"info": {
			"code": 0,
			"hex_ack": "55AA030700101100000C030000060400001E05000050B6",
			"msg": ""
		}
	}
}

11.设置是否保持停电前状态

请求示例:

{
	"app_id": "{{wmjv2appid}}",
	"app_secret": "{{wmjv2appsecret}}",
	"device_sn": "W71E61B4D34",
	"type":1,
	"data": {
        "cmd_type": "set_retainstate",
        "info":{
			//设置停电后来电是否保存之前状态,1为保留,0为来电后保持关闭状态
			"retainstate": 1
        }
	}
}

回复:

{
	"code": 0,
	"data": {
		"device_sn": "W71E61B4D34",
		"msg_id": 74,
		"type": 1,
		"cmd": "",
		"app_id": "",
		"cmd_type": "set_retainstate",
		"info": {
			"code": 0,
			"msg": ""
		}
	}
}

12.回调数据格式

设备上线:

{"device_sn":"W71EXXXXXXX","msg_id":"0","type":"0","cmd":"OnLine","app_id":"","cmd_type":"OnLine","info":{"ipaddress":"183.227.122.127","time":"1725825684"}}

设备离线:

{"device_sn":"W71EXXXXXXX","msg_id":"0","type":"0","cmd":"OffLine","app_id":"","cmd_type":"OffLine","info":{"time":"1725825680"}}

上线报送设备信息回调:

{"device_sn":"W71EXXXXXXX","msg_id":"0","type":"2","cmd":"dev_reg","app_id":"","cmd_type":"dev_reg","info":{"hw_ver":"1.0.0","iccid":"GUOLAO_DEVICE\/4C10D52B4F7C","imei":"84FCE61B4314","model":"W71","project":"W71","rssi":"-45","sw_ver":"71.1.47","username":"W71E61B4314"}}

关电回调:

{"device_sn":"W71EXXXXXXX","msg_id":"0","type":"2","cmd":"notify","app_id":"","cmd_type":"notify","info":{"data":"55AA03070005100100010020","notify_type":"on-off","state":"0"}}

开电回调:

{"device_sn":"W71EXXXXXXX","msg_id":"0","type":"2","cmd":"notify","app_id":"","cmd_type":"notify","info":{"data":"55AA03070005100100010121","notify_type":"on-off","state":"1"}}

超负载跳闸回调:

{"device_sn":"W71EXXXXXXX","msg_id":"0","type":"2","cmd":"notify","app_id":"","cmd_type":"notify","info":{"alarm_detail":"overload","bitmap":"55","code":"1","msg":"","notify_type":"alarm"}}

高温跳闸回调:

{"device_sn":"W71EXXXXXXX","msg_id":"0","type":"2","cmd":"notify","app_id":"","cmd_type":"notify","info":{"alarm_detail":"overheat","bitmap":"55","code":"3","msg":"","notify_type":"alarm"}}

过流跳闸回调:

{"device_sn":"W71EXXXXXXX","msg_id":"0","type":"2","cmd":"notify","app_id":"","cmd_type":"notify","info":{"alarm_detail":"overcurrent","bitmap":"55AA0307","code":"4","msg":"","notify_type":"alarm"}}

低电压跳闸回调:

{"device_sn":"W71EXXXXXXX","msg_id":"0","type":"2","cmd":"notify","app_id":"","cmd_type":"notify","info":{"alarm_detail":"undervoltage","bitmap":"0800","code":"6","msg":"","notify_type":"alarm"}}

高电压跳闸回调:

{"device_sn":"W71EXXXXXXX","msg_id":"0","type":"2","cmd":"notify","app_id":"","cmd_type":"notify","info":{"alarm_detail":"overvoltage","bitmap":"0800","code":"6","msg":"","notify_type":"alarm"}}

 

13.案例代码(PHP)

//发送json请求函数
function PostJson($url, $data = NULL,$headers="")
{

    $curl = curl_init();
    $header =array(
        'Content-Type: application/json; charset=utf-8',
        'Content-Length:' . strlen(json_encode($data)),
        'Cache-Control: no-cache',
        'Pragma: no-cache'
    );
    if($headers){
        $header[]=$headers;
    }

    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    if (!$data) {
        return 'data is null';
    }
    if (is_array($data)) {
        $data = json_encode($data);
    }

    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    curl_setopt($curl, CURLOPT_TIMEOUT, 60); // 设置超时限制防止死循环
    curl_setopt($curl, CURLOPT_HEADER, 0);
    curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $res = curl_exec($curl);
    $errorno = curl_errno($curl);
    if ($errorno) {
        return $errorno;
    }
    curl_close($curl);
    return json_decode($res,true);

}
//组装发送请求,带上appid,appsecret
 function Request($path, $data = [])
{
        $data["app_id"] = "208ac48ff968ab0dc675008d0ded46d1";
        $data["app_secret"] =  "ad45d97d283c518e15b4bda75c887dec";
        $res = PostJson("https://wdev.wmj.com.cn/deviceApi/".$path, $data);
        return $res;
}
//注册绑定
function regdev($device_sn)
{
        $res = Request("register", ["device_sn" => $device_sn]);
        if ($res["code"] != 0 && $res["code"] != 1005) {
            return ["err" => $res["msg"]];
        }

        return $res;
}
//获取在线状态
function getonline($device_sn)
{
    $res = Request("getOnLine", ["device_sn" => $device_sn]);
    if ($res["code"] != 0) {
        return 0;
    }
    return $res["data"]["on_line"];
}
//删除绑定
function deldev($device_sn)
{
    $res = Request("logout", ["device_sn" => $device_sn]);
    if ($res["code"] != 0 && $res["code"] != 1005) {
        return ["err" => $res["msg"]];
    }
    return $res;
}
//开电
function poweron($device_sn)
{
        $res = Request("send", [
            "device_sn" => $device_sn,
            "data" => [
                "cmd_type" => "turnon",
            ]
        ]);
        if ($res["code"] != 0) {
            return ["err" => $res["msg"]];
        }
        if ($res["data"]["info"]["code"] != 0) {
            return ["err" =>"开电失败".$res["data"]["info"]["msg"]];
        }

        return ["err" => null,"data"=>$res["data"]];
}
//关电
function poweroff($device_sn)
{
    $res = Request("send", [
        "device_sn" => $device_sn,
        "data" => [
            "cmd_type" => "turnoff",
        ]
    ]);
    if ($res["code"] != 0) {
        return ["err" => $res["msg"]];
    }
    if ($res["data"]["info"]["code"] != 0) {
        return ["err" =>"关电失败".$res["data"]["info"]["msg"]];
    }
    return ["err" => null,"data"=>$res["data"]];
}
//查询功率、电压、电流
function getpowerinfo($device_sn)
{
    $res = Request("send", [
        "device_sn" => $device_sn,
        "data" => [
            "cmd_type" => "getdevinfo",
        ]
    ]);
    if ($res["code"] != 0) {
        return ["err" => $res["msg"]];
    }
    if ($res["data"]["info"]["code"] != 0) {
        return ["err" =>"获取失败".$res["data"]["info"]["msg"]];
    }
    return ["err" => null,"data"=>$res["data"]];
}
//注册
echo json_encode(regdev("W71F9783DC8"),JSON_UNESCAPED_UNICODE);
//开电
echo json_encode(poweron("W71F9783DC8"),JSON_UNESCAPED_UNICODE);
//关电
echo json_encode(poweroff("W71F9783DC8"),JSON_UNESCAPED_UNICODE);
//查询功率、电压、电流等信息
echo json_encode(getpowerinfo("W71F9783DC8"),JSON_UNESCAPED_UNICODE);

作者:极客师傅  创建时间:2025-03-09 00:28
最后编辑:极客师傅  更新时间:2025-04-27 12:41