python-miio
python-miio copied to clipboard
ERR: miiocli genericmiot --ip 192.168.5.x --token xxxx status
Describe the bug ERR: miiocli genericmiot --ip 192.168.5.x --token xxxx status
Version information (please complete the following information):
- OS: [macos]
- python-miio: [miiocli, version 0.6.0.dev0]
Device information:
If the issue is specific to a device [Use miiocli device --ip <ip address> --token <token> info
]:
Model: cuco.plug.cp1
Hardware version: esp8285
Firmware version: 2.0.1_0013
Supported using: GenericMiot
Command: miiocli genericmiot --ip 192.168.5.x --token xxxx
Supported by genericmiot: True
To Reproduce Steps to reproduce the behavior: 1.miiocli genericmiot --ip 192.168.5.x --token xxxx status
Expected behavior get status of plug
Console output miiocli genericmiot --ip 192.168.5.x --token xxxx status Running command status ERROR:miio.protocol:Unable to parse json 'b'{"id":2,"result":[{"did":"switch:on","siid":2,"piid":1,"code":0,"value":false}{"did":"indicator-light:on","siid":3,"piid":1,"code":0,"value":true}]}'': Expecting ',' delimiter: line 1 column 79 (char 78) ERROR:miio.click_common:Exception: Unable to parse message payload Traceback (most recent call last): File "/Users/xia/src/Xiaomi-cloud-tokens-extractor/venv/lib/python3.12/site-packages/miio/protocol.py", line 204, in _decode return json.loads(decoded) ^^^^^^^^^^^^^^^^^^^ File "/usr/local/Cellar/[email protected]/3.12.3/Frameworks/Python.framework/Versions/3.12/lib/python3.12/json/init.py", line 346, in loads return _default_decoder.decode(s) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/Cellar/[email protected]/3.12.3/Frameworks/Python.framework/Versions/3.12/lib/python3.12/json/decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/Cellar/[email protected]/3.12.3/Frameworks/Python.framework/Versions/3.12/lib/python3.12/json/decoder.py", line 353, in raw_decode obj, end = self.scan_once(s, idx) ^^^^^^^^^^^^^^^^^^^^^^ json.decoder.JSONDecodeError: Expecting ',' delimiter: line 1 column 79 (char 78)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
Looks like the device is responding with invalid JSON (the two objects in the result list are not separated by a comma) so this is a firmware problem. #1890 had a different version and it was apparently working :-(
If you just need the data, you could use get_property_by 2 1
and get_property_by 3 1
instead of status
. There are also other commands that could be helpful, see miiocli genericmiot --help
.
Looks like the device is responding with invalid JSON (the two objects in the result list are not separated by a comma) so this is a firmware problem. #1890 had a different version and it was apparently working :-(
If you just need the data, you could use
get_property_by 2 1
andget_property_by 3 1
instead ofstatus
. There are also other commands that could be helpful, seemiiocli genericmiot --help
.
Actually, I want to control the on and off of this plug. How to send the correct command
miiocli genericmiot --ip 192.168.5.x --token xxxx actions Running command actions Toggle (switch:toggle) Access: --x Extras: {'urn': <URN urn:miot-spec-v2:action:toggle:00002811:cuco-cp1:2 parent:namespace='miot-spec-v2' type='service' name='switch' internal_id='0000780C' model='cuco-cp1' version=1 unexpected=None>, 'siid': 2, 'aiid': 1, 'miot_action': MiotAction(urn=<URN urn:miot-spec-v2:action:toggle:00002811:cuco-cp1:2 parent:namespace='miot-spec-v2' type='service' name='switch' internal_id='0000780C' model='cuco-cp1' version=1 unexpected=None>, description='Toggle', service=MiotService(siid=2, urn=<URN urn:miot-spec-v2:service:switch:0000780C:cuco-cp1:1 parent:None>, description='Switch'), aiid=1, inputs=[], outputs=[])}
That toggle action you see could be called using call switch:toggle
, but you likely want to control on/off, right?
So here's how this device shows up in the simulator (miiocli devtools miot-simulator --model cuco.plug.cp1
):
$ miiocli genericmiot --ip 127.0.0.1 --token 00000000000000000000000000000000 status
Running command status
Service Switch (switch)
Switch Status (switch:on, access: RW): False (<class 'bool'>, )
Service Indicator Light (indicator-light)
Switch Status (indicator-light:on, access: RW): True (<class 'bool'>, )
so the command to change the state would be miiocli genericmiot --ip 127.0.0.1 --token 00000000000000000000000000000000 set switch:on 1
(to turn on, change the last argument to 0 for turning off.
Alternatively, you can use the siid/piid (shown if you call settings
): miiocli genericmiot --ip 127.0.0.1 --token 00000000000000000000000000000000 set_property_by 2 1 1 bool
Hope that helps!
The program runs fine, but it cannot ON or OFF the plug don't work.
## on
miiocli genericmiot --ip 192.168.5.x --token 00000000000000000000000000000000 set switch:on 1
Running command set
[{'did': 'switch:on', 'siid': 2, 'piid': 1, 'code': 4294967291}]
## off
miiocli genericmiot --ip 192.168.5.x --token 00000000000000000000000000000000 set switch:on 0
Running command set
[{'did': 'switch:on', 'siid': 2, 'piid': 1, 'code': 4294967291}]
This work find.
## ON
miiocli genericmiot --ip 192.168.5.x --token 00000000000000000000000000000000 set_property_by 2 1 1 bool
## OFF
miiocli genericmiot --ip 192.168.5.x --token 00000000000000000000000000000000 set_property_by 2 1 0 bool
Thank you very much.
Thanks
Glad you got it working!
It's odd that the set
is not working as expected, so if you don't mind, please add --debug
to the command (miiocli --debug genericmiot ..
) and test both of those commands (set_property_by
and set
) to see how the payloads send to the device differ.
miiocli --debug genericmiot --ip 192.168.5.x --token 00000000000000000000000000000000 set switch:on 0
Running command set
DEBUG:miio.click_common:Unknown model, trying autodetection
DEBUG:miio.miioprotocol:Got a response: Container:
data = Container:
data = b'' (total 0)
value = b'' (total 0)
offset1 = 32
offset2 = 32
length = 0
header = Container:
data = b'!1\x00 \x00\x00\x00\x00\x10\t\xc19\x00\x1b\x19\xc0' (total 16)
value = Container:
length = 32
unknown = 0
device_id = unhexlify('1009c139')
ts = 1970-01-21 13:21:04+00:00
offset1 = 0
offset2 = 16
length = 16
checksum = b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff' (total 16)
DEBUG:miio.miioprotocol:Discovered 1009c139 with ts: 1970-01-21 13:21:04+00:00, token: b'ffffffffffffffffffffffffffffffff'
DEBUG:miio.miioprotocol:192.168.5.x:54321 >>: {'id': 1, 'method': 'miIO.info', 'params': []}
DEBUG:miio.miioprotocol:192.168.5.x:54321 (ts: 1970-01-21 13:21:04+00:00, id: 1) << {'id': 1,
'result': {'ap': {'bssid': '94:D9:B3:86:C5:6F',
'primary': 11,
'rssi': -52,
'ssid': 'M7'},
'fw_ver': '2.0.1_0013',
'hw_ver': 'esp8285',
'life': 1776064,
'mac': '50:EC:xx:6F:xx:xx',
'miio_times': [1776064, 34, 280, 1775750],
'miio_ver': '0.0.3',
'mmfree': 28680,
'model': 'cuco.plug.cp1',
'netif': {'gw': '192.168.5.1',
'localIp': '192.168.5.x',
'mask': '255.255.255.0'},
'token': '00000000000000000000000000000000',
'uid': 235514380,
'wifi_fw_ver': 'v3.1-36-gdfa16a9-dirty'}}
DEBUG:miio.device:Detected model cuco.plug.cp1
DEBUG:miio.miot_cloud:Unable to find schema file /Users/x/Library/Caches/python-miio/cuco.plug.cp1.json, going to fetch
DEBUG:miio.miot_cloud:Did not found non-stale /Users/x/Library/Caches/python-miio/model-to-urn.json, trying to fetch
DEBUG:micloud.miotspec:Going to download specs listing with status released
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): miot-spec.org:443
DEBUG:urllib3.connectionpool:https://miot-spec.org:443 "GET /miot-spec-v2/instances?status=released HTTP/1.1" 200 None
DEBUG:miio.miot_cloud:Written 1059710 bytes to /Users/x/Library/Caches/python-miio/model-to-urn.json
WARNING:miio.miot_cloud:2 versions found for model cuco.plug.cp1: [ReleaseInfo(model='cuco.plug.cp1', status=None, type='urn:miot-spec-v2:device:outlet:0000A002:cuco-cp1:1', version=1), ReleaseInfo(model='cuco.plug.cp1', status=None, type='urn:miot-spec-v2:device:outlet:0000A002:cuco-cp1:2', version=2)], using the newest one
DEBUG:miio.miot_cloud:Using model='cuco.plug.cp1' status=None type='urn:miot-spec-v2:device:outlet:0000A002:cuco-cp1:2' version=2
DEBUG:miio.miot_cloud:Cached schema not found for cuco.plug.cp1, going to fetch it
DEBUG:micloud.miotspec:Going to download a spec for urn:miot-spec-v2:device:outlet:0000A002:cuco-cp1:2
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): miot-spec.org:443
DEBUG:urllib3.connectionpool:https://miot-spec.org:443 "GET /miot-spec-v2/instance?type=urn:miot-spec-v2:device:outlet:0000A002:cuco-cp1:2 HTTP/1.1" 200 None
DEBUG:miio.miot_cloud:Written 1583 bytes to /Users/x/Library/Caches/python-miio/cuco.plug.cp1.json
DEBUG:miio.integrations.genericmiot.genericmiot:Initialized: description='Outlet' urn=<URN urn:miot-spec-v2:device:outlet:0000A002:cuco-cp1:2 parent:None>
DEBUG:miio.descriptorcollection:Added descriptor: ActionDescriptor(id='switch:toggle', name='Toggle', type=None, unit=None, status_attribute=None, inputs=[], access=<AccessFlags.Execute: 4>)
DEBUG:miio.descriptorcollection:Added descriptor: PropertyDescriptor(id='switch:on', name='Switch Status', type=<class 'bool'>, unit=None, status_attribute='switch_on', access=<AccessFlags.Read|Write: 3>, constraint=<PropertyConstraint.Unset: 1>)
DEBUG:miio.descriptorcollection:Added descriptor: PropertyDescriptor(id='indicator-light:on', name='Switch Status', type=<class 'bool'>, unit=None, status_attribute='indicator_light_on', access=<AccessFlags.Read|Write: 3>, constraint=<PropertyConstraint.Unset: 1>)
DEBUG:miio.integrations.genericmiot.genericmiot:Created 0 actions
DEBUG:miio.integrations.genericmiot.genericmiot:Created 0 properties
DEBUG:miio.miioprotocol:192.168.5.100:54321 >>: {'id': 2,
'method': 'set_properties',
'params': [{'did': 'switch:on', 'piid': 1, 'siid': 2, 'value': 0}]}
DEBUG:miio.miioprotocol:192.168.5.x:54321 (ts: 1970-01-21 13:21:05+00:00, id: 2) << {'id': 2,
'result': [{'code': 4294967291, 'did': 'switch:on', 'piid': 1, 'siid': 2}]}
[{'did': 'switch:on', 'siid': 2, 'piid': 1, 'code': 4294967291}]
miiocli --debug genericmiot --ip 192.168.5.x --token 00000000000000000000000000000000 set_property_by 2 1 1 bool
Running command set_property_by
DEBUG:miio.click_common:Unknown model, trying autodetection
DEBUG:miio.miioprotocol:Got a response: Container:
data = Container:
data = b'' (total 0)
value = b'' (total 0)
offset1 = 32
offset2 = 32
length = 0
header = Container:
data = b'!1\x00 \x00\x00\x00\x00\x10\t\xc19\x00\x1b\x1c\xcf' (total 16)
value = Container:
length = 32
unknown = 0
device_id = unhexlify('1009c139')
ts = 1970-01-21 13:34:07+00:00
offset1 = 0
offset2 = 16
length = 16
checksum = b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff' (total 16)
DEBUG:miio.miioprotocol:Discovered 1009c139 with ts: 1970-01-21 13:34:07+00:00, token: b'ffffffffffffffffffffffffffffffff'
DEBUG:miio.miioprotocol:192.168.5.x:54321 >>: {'id': 1, 'method': 'miIO.info', 'params': []}
DEBUG:miio.miioprotocol:192.168.5.x:54321 (ts: 1970-01-21 13:34:07+00:00, id: 1) << {'id': 1,
'result': {'ap': {'bssid': '94:D9:B3:86:C5:6F',
'primary': 11,
'rssi': -51,
'ssid': 'M7'},
'fw_ver': '2.0.1_0013',
'hw_ver': 'esp8285',
'life': 1776847,
'mac': '50:EC:50:xx:xx:xx',
'miio_times': [1776847, 34, 280, 1776533],
'miio_ver': '0.0.3',
'mmfree': 28680,
'model': 'cuco.plug.cp1',
'netif': {'gw': '192.168.5.1',
'localIp': '192.168.5.x',
'mask': '255.255.255.0'},
'token': '00000000000000000000000000000000',
'uid': 235514380,
'wifi_fw_ver': 'v3.1-36-gdfa16a9-dirty'}}
DEBUG:miio.device:Detected model cuco.plug.cp1
DEBUG:miio.miioprotocol:192.168.5.x:54321 >>: {'id': 2,
'method': 'set_properties',
'params': [{'did': 'set-2-1', 'piid': 1, 'siid': 2, 'value': True}]}
DEBUG:miio.miioprotocol:192.168.5.x:54321 (ts: 1970-01-21 13:34:07+00:00, id: 2) << {'id': 2, 'result': [{'code': 0, 'did': 'set-2-1', 'piid': 1, 'siid': 2}]}
[{'did': 'set-2-1', 'siid': 2, 'piid': 1, 'code': 0}]
Glad you got it working!
It's odd that the
set
is not working as expected, so if you don't mind, please add--debug
to the command (miiocli --debug genericmiot ..
) and test both of those commands (set_property_by
andset
) to see how the payloads send to the device differ.
please debug the log .