From cacf862dab9bebf79e9db51ee54f3539c3ccd62b Mon Sep 17 00:00:00 2001 From: infinitydev Date: Sun, 29 Oct 2017 01:14:18 +0200 Subject: [PATCH 1/4] make vacuum robot wifi settings configurable via CLI --- README.md | 11 +++++++++++ miio/vacuum.py | 4 ++++ miio/vacuum_cli.py | 12 ++++++++++++ 3 files changed, 27 insertions(+) diff --git a/README.md b/README.md index 7597f43a8..728f18d48 100644 --- a/README.md +++ b/README.md @@ -211,6 +211,17 @@ $ 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. + ### Setting the fanspeed ``` diff --git a/miio/vacuum.py b/miio/vacuum.py index bd6843596..530aa16e9 100644 --- a/miio/vacuum.py +++ b/miio/vacuum.py @@ -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] + def raw_command(self, cmd, params): """Send a raw command to the robot.""" return self.send(cmd, params) diff --git a/miio/vacuum_cli.py b/miio/vacuum_cli.py index e623e1f4f..ba2d792f7 100644 --- a/miio/vacuum_cli.py +++ b/miio/vacuum_cli.py @@ -417,6 +417,18 @@ 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) From cafa8abdf387f597990965b9e89a36c0101f214d Mon Sep 17 00:00:00 2001 From: infinitydev Date: Sun, 29 Oct 2017 16:02:33 +0100 Subject: [PATCH 2/4] clarify README --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 728f18d48..04669647c 100644 --- a/README.md +++ b/README.md @@ -222,6 +222,9 @@ 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. + ### Setting the fanspeed ``` From 5b6bf6d64108836cf15db0b3c833dcdfdf2f2b23 Mon Sep 17 00:00:00 2001 From: infinitydev Date: Sun, 29 Oct 2017 16:02:53 +0100 Subject: [PATCH 3/4] fix code style --- miio/vacuum.py | 3 ++- miio/vacuum_cli.py | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/miio/vacuum.py b/miio/vacuum.py index 530aa16e9..8abafd9ef 100644 --- a/miio/vacuum.py +++ b/miio/vacuum.py @@ -204,7 +204,8 @@ def set_timezone(self, new_zone): 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] + 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.""" diff --git a/miio/vacuum_cli.py b/miio/vacuum_cli.py index ba2d792f7..d73515192 100644 --- a/miio/vacuum_cli.py +++ b/miio/vacuum_cli.py @@ -422,8 +422,7 @@ def timezone(vac: miio.Vacuum, tz=None): @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): +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)) From 4a5b16feae34932eb77147d7dfc1dcf4e073e521 Mon Sep 17 00:00:00 2001 From: Teemu R Date: Sun, 29 Oct 2017 16:28:41 +0100 Subject: [PATCH 4/4] note about token extraction wrt configure_wifi --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 04669647c..a9bdfa5d0 100644 --- a/README.md +++ b/README.md @@ -225,6 +225,8 @@ 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 ```