Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make vacuum robot wifi settings configurable via CLI #105

Merged
merged 4 commits into from
Oct 29, 2017

Conversation

infinitydev
Copy link
Contributor

These changes allow you to configure the wifi of the Xiaomi vacuum cleaner without needing the Mi Home smartphone app.

It is now effectively possible to use python-miio with the robot in your home wifi network without a Xiaomi account and their app.

Reference:
https://github.com/OpenMiHome/mihome-binary-protocol/blob/master/doc/PROTOCOL.md#payloads

The document mentions that the 'id' field must be a Unix timestamp. This seems to be nonsense. Works perfectly fine with the sequential id. I assumed that it might be used to set the clock of the rebot, but it is not. (It uses NTP.)

I am not sure what the 'uid' field is. Probably the Xiaomi account id that allows them to connect your robot to your account. This should be pretty useless if you don't set the robot up with their app. Hence, I made it an optional parameter.

@click.argument('uid', type=int, required=False)
@pass_dev
def configure_wifi(vac: miio.Vacuum, ssid: str,
password: str, uid: int):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continuation line under-indented for visual indent

miio/vacuum.py Outdated
@@ -202,6 +202,10 @@ def set_timezone(self, new_zone):
"""Set the timezone."""
return self.send("set_timezone", [new_zone])[0] == 'ok'

def configure_wifi(self, ssid, password, uid=0):
"""Configure the wifi settings."""
return self.send("miIO.config_router", { "ssid": ssid, "passwd": password, "uid": uid })[0]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whitespace after '{'
line too long (99 > 79 characters)
whitespace before '}'

@click.argument('uid', type=int, required=False)
@pass_dev
def configure_wifi(vac: miio.Vacuum, ssid: str,
password: str, uid: int):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continuation line under-indented for visual indent

miio/vacuum.py Outdated
@@ -202,6 +202,10 @@ def set_timezone(self, new_zone):
"""Set the timezone."""
return self.send("set_timezone", [new_zone])[0] == 'ok'

def configure_wifi(self, ssid, password, uid=0):
"""Configure the wifi settings."""
return self.send("miIO.config_router", { "ssid": ssid, "passwd": password, "uid": uid })[0]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whitespace after '{'
line too long (99 > 79 characters)
whitespace before '}'

@infinitydev infinitydev changed the title make vacuum robot wifi settings configurable via CLI Make vacuum robot wifi settings configurable via CLI Oct 28, 2017
@coveralls
Copy link

coveralls commented Oct 28, 2017

Coverage Status

Coverage decreased (-0.1%) to 39.379% when pulling cacf862 on infinitydev:master into e9d55e3 on rytilahti:master.

@marcelrv
Copy link

Did your vacuum indeed function proper.
I have users that indicated in the latest fw you need time info

miIO.config_router{“tz”:“Europe/Brussels”,“gmt_offset”:0,“ssid”:“WInternal”,“passwd”:“xxx”}

Also, would be good to understand if you can disconnect the Xiaomi cloud (meaning the vacuum no longer needs internet)

@infinitydev
Copy link
Contributor Author

infinitydev commented Oct 29, 2017

Yes, my vaccum works properly. I never got it to work with the original app. Hence, my robot is running on stock firmware. So, I cannot test on recent firmware unless there is a way to upload a new one without the app.

I have completely blocked the robot's internet access in my router to prevent it from talking home. I think that is why it takes a couple of minutes before it responds to commands on the configured wifi network.

After connecting my laptop to the robots default wifi, changing wifi settings through this patch and waiting a couple of minutes, I can control the robot with miio and an alternative smartphone app within my LAN.

Edit: It also takes a few minutes before it responds after it has been completely powered off with internet access blocked.

@rytilahti
Copy link
Owner

They probably added the timezone setting for the config_router at the same time they introduced the ability to change it with set_timezone (as before that all the schedules run on time in China.

What remains unclear to me what will be used a a token when config_router is used, could you elaborate (and add that also to README)?

@infinitydev could you fix those issues as reported by hound?

@coveralls
Copy link

coveralls commented Oct 29, 2017

Coverage Status

Coverage decreased (-0.1%) to 39.363% when pulling 5b6bf6d on infinitydev:master into e9d55e3 on rytilahti:master.

@infinitydev
Copy link
Contributor Author

The token does not change when configuring wifi. I added a paragraph to the README for clarification.

The workflow for configuring my stock robot boiled down to:

  1. Connect to robot's default wifi network
  2. Obtain token
    mirobo discover --handshake 1
  3. Configure wifi
    mirobo --ip=192.168.8.1 --token=<my_token> configure_wifi "SSID" "password"
  4. Wait some minutes
  5. Check connection
    mirobo --ip=<LAN_IP_of_robot> --token=<my_token>

@rytilahti
Copy link
Owner

Ok, thanks! I read at some point that the newer firmware releases will disable obtaining the token with a handshake, leaving this method usable only for earlier versions. I adjusted the README to inform potential users about this caveat.

@coveralls
Copy link

coveralls commented Oct 29, 2017

Coverage Status

Coverage decreased (-0.2%) to 39.253% when pulling 4a5b16f on infinitydev:master into e9d55e3 on rytilahti:master.

@rytilahti
Copy link
Owner

I'll merge this now, and add the ability to define a timezone in another PR. Thanks for the PR! 👍

@rytilahti rytilahti merged commit a5da827 into rytilahti:master Oct 29, 2017
rytilahti added a commit that referenced this pull request Oct 29, 2017
This will allow passing the timezone to vacuums running
newer firmware versions, as mentioned in PR #105
rytilahti added a commit that referenced this pull request Oct 30, 2017
This will allow passing the timezone to vacuums running
newer firmware versions, as mentioned in PR #105
rytilahti added a commit that referenced this pull request Nov 1, 2017
* Add the ability to define a timezone for configure_wifi

This will allow passing the timezone to vacuums running
newer firmware versions, as mentioned in PR #105

* add pytz to requirements
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants