Skip to content

Commit

Permalink
Make vacuum robot wifi settings configurable via CLI (#105)
Browse files Browse the repository at this point in the history
* make vacuum robot wifi settings configurable via CLI

* clarify README

* fix code style

* note about token extraction wrt configure_wifi
  • Loading branch information
infinitydev authored and rytilahti committed Oct 29, 2017
1 parent c481f1b commit a5da827
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,22 @@ $ mirobo home
Requesting return to home: 0
```

### Configure wifi settings (WPA2)

```
$ mirobo configure_wifi "My SSID" "My Wifi password"
Configuring wifi to SSID: My SSID
OK
```

It may take a few minutes before the robot responds to commands after it connected to the
wifi network, especially if you block its internet access.

The token does not change by configuring wifi. All subsequent commands must be sent to
the IP that the robot obtains via DHCP from your router.

*Note, that this only works on devices from which you have obtained a token beforehand and therefore rules out e.g. vacuums with firmware 3.3.9_003077 or higher.* Any ideas for extracting the token on newer devices without using the official app and extracting them from the database are appreciated!

### Setting the fanspeed

```
Expand Down
5 changes: 5 additions & 0 deletions miio/vacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ 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."""
params = {"ssid": ssid, "passwd": password, "uid": uid}
return self.send("miIO.config_router", params)[0]

def raw_command(self, cmd, params):
"""Send a raw command to the robot."""
return self.send(cmd, params)
11 changes: 11 additions & 0 deletions miio/vacuum_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,17 @@ def timezone(vac: miio.Vacuum, tz=None):
click.echo("Timezone: %s" % vac.timezone())


@cli.command()
@click.argument('ssid', required=True)
@click.argument('password', required=True)
@click.argument('uid', type=int, required=False)
@pass_dev
def configure_wifi(vac: miio.Vacuum, ssid: str, password: str, uid: int):
"""Configure the wifi settings."""
click.echo("Configuring wifi to SSID: %s" % ssid)
click.echo(vac.configure_wifi(ssid, password, uid))


@cli.command()
@click.argument('cmd', required=True)
@click.argument('parameters', required=False)
Expand Down

0 comments on commit a5da827

Please sign in to comment.