NickWaterton / Roomba980-Python

Python program and library to control iRobot Roomba 980 Vacuum Cleaner
MIT License
385 stars 108 forks source link

Connection issue #5

Open vassilisv opened 7 years ago

vassilisv commented 7 years ago

I have been using rest980 and dorita980 with no issues. I wanted to switch to a Python based solution and I am having an issues with connecting to my 980.

The getpassword.py script worked fine and a config.ini created with the correct blid, password and ip options. When executing roomba.py (with no command line params) I get the following error. As I mentioned I am able to connect fine with rest980 and the blid and password are correct. I am using Python 2.7.12 (tried with Python3 but got a different error) and my 980 is running firmware v2.2.9-1.

CV or numpy module not found, falling back to PIL [I 2017-07-01 13:14:50,674] [I 2017-07-01 13:14:50,674] Program Started [I 2017-07-01 13:14:50,674] [I 2017-07-01 13:14:50,675] Paho MQTT Version: 1.1 [I 2017-07-01 13:14:50,675] to Exit [I 2017-07-01 13:14:50,675] Roomba 980 MQTT data Interface [I 2017-07-01 13:14:50,676] reading info from config file ./config.ini [I 2017-07-01 13:14:50,677] Creating Roomba object 10.0.1.143 [I 2017-07-01 13:14:50,677] CONTINUOUS connection [I 2017-07-01 13:14:50,678] connecting Roomba 10.0.1.143 [I 2017-07-01 13:14:50,678] Posting DECODED data WARNING: PIL version is 3.1.2, this is not the latest! you can get bad memory leaks with old versions of PIL run: 'pip install --upgrade pillow' to fix this [I 2017-07-01 13:14:50,678] MAP: Maps Enabled [I 2017-07-01 13:14:50,679] MAP: openening existing line image [W 2017-07-01 13:14:50,684] MAP: line image problem: [Errno 2] No such file or directory: u'.//Dustylines.png': created new image [I 2017-07-01 13:14:50,684] MAP: openening existing problems image [W 2017-07-01 13:14:50,689] MAP: problems image problem: [Errno 2] No such file or directory: u'.//Dustyproblems.png': created new image [I 2017-07-01 13:14:50,689] MAP: openening existing map no text image [W 2017-07-01 13:14:50,690] MAP: map no text image problem: [Errno 2] No such file or directory: u'.//Dustymap_notext.png': set to None [I 2017-07-01 13:14:50,694] MAP: home_pos: (400,750) [I 2017-07-01 13:14:50,747] MAP: Initialisation complete [I 2017-07-01 13:14:50,747] Connecting Dusty [I 2017-07-01 13:14:52,834] Roomba Data: {} [I 2017-07-01 13:14:52,951] Roomba Connected Dusty [E 2017-07-01 13:14:52,952] Roomba Connected with result code 1 [E 2017-07-01 13:14:52,953] Please make sure your blid and password are correct Dusty [I 2017-07-01 13:14:57,840] Roomba Data: {}

NickWaterton commented 7 years ago

Vassilisv,

The "Connected Result code 1" is from paho-mqtt and means:

0 - success, connection accepted 1 - connection refused, bad protocol 2 - refused, client-id error 3 - refused, service unavailable 4 - refused, bad username or password 5 - refused, not authorized

The error you are getting is when the program tries to connect to the Roomba via mqtt, it gets the return code "connection refused, bad protocol" - which should mean the connection was attempted with the incorrect mqtt protocol (there are two, V 3.1 and V 3.1.1). It can also mean that the mqtt server is already connected (but I trap this in the program, so you should get a different error).

I am using the default protocol (which is 3.1.1), but I notice your mqtt library version is reporting as "1.1". This seems to be an old version of library (the latest is 1.3) - so maybe the default in v1.1 is 3.1. I am using v1.2.3. Also your version of PIL is old as well (and will cause memory leak problems if you don't update it!).

You don't say what operating system you are running on, but I would try upgrading your version of paho-mqtt, either by pip install --upgrade paho-mqtt - to V1.3, or by pip install --upgrade paho-mqtt=1.2.3 as I know 1.2.3 version works, and there are breaking changes in v1.3 that may be a problem (I can't get v1.3 to work on my system as they have "limited support" for python 2.7 now).

If you upgrade to v1.3, make sure you have the latest github version of Roomba980-Python as there are minor changes to work around the breaking changes in paho-mqtt V1.3.

So:

One other thing to note, as I mentioned, you can only have one connection at a time to the Roomba mqtt server (Roomba has set this up this way), so you can't connect to it, if you have the app open (or something else connected). Once Roomba.py is running (and connected), you can open the app, and it will connect via the cloud (as the server is already connected). So make sure the app is disconnected before trying Roomba.py, or use the periodic connection option (which will connect when the Roomba mqtt server is free).

Let me know if this helps.

NickWaterton commented 7 years ago

Vassilisv,

Ha! Found this in the paho-mqtt changelog:

v1.1 - 2015-01-30

So you can see paho-mqtt v1.1 default connection is mqtt protocol V3.1, not 3.1.1 as is needed. This is probably the problem.

I have just pushed a new commit which explicitly defines the required mqtt protocol version.

I would still recommend updating PIL, and paho-mqtt to v1.2.3 though. I have the same Roomba firmware version as you (and it works fine).

vassilisv commented 7 years ago

Hi Nick, yes you are correct that fixed it. Had some dependencies from other Python scripts I am using that required an older version of paho-mqtt. Was able to get it to work on virtualenv with Python2.7 running on Ubuntu 16.04.2 and the module versions you suggested.

Thanks for taking the time to respond!

NickWaterton commented 7 years ago

You're welcome.

It also exposed some bugs in my software (to do with library versions), so I think I have fixed that now. I just set up a VM running Ubuntu 16.04, python 2.7.12 paho-mqtt 1.3 PIL 4 etc, and it all works (for now...).

Download roomba.py 1.1.1 for the latest changes.