Roomba Plugin?

Posted on
Sun Nov 16, 2014 8:15 pm
miked0809 offline
Posts: 8
Joined: May 16, 2014

Re: Roomba Plugin?

Thanks for the response. I was able to fix the plugin using the solution found here:

http://stackoverflow.com/questions/2407 ... th-problem

For those that want to fix it locally until a proper update to the plugin is published, I made the following modifications to plugin.py in the RooWIFI plugin.

Code: Select all
...
import urllib2
import base64
...

class Plugin(indigo.PluginBase):


Code: Select all

   #### Mike (start)
   username = "none"
   password = "none"

   def getUrlRequest(self,theUrl,device):
      # construct the URL request
      request = theUrl
      if device.pluginProps.has_key("useAuthentication") and device.pluginProps["useAuthentication"]:
         request = urllib2.Request(theUrl)
         base64string = base64.encodestring('%s:%s' % (self.username, self.password)).replace('\n', '')
         request.add_header("Authorization", "Basic %s" % base64string)
      return request
   #### Mike (end)

   def deviceStartComm(self, device):
      ....

         if device.pluginProps.has_key("useAuthentication") and device.pluginProps["useAuthentication"]:

            #### Mike (start)
            self.username = device.pluginProps["username"]
            self.password = device.pluginProps["password"]
            self.debugLog("username=" + self.username + ", password=<pwd>")
            #self.passman.add_password(None, u"http://" + device.pluginProps["address"], device.pluginProps["username"], device.pluginProps["password"])
            self.passman.add_password(None, u"http://" + device.pluginProps["address"], self.username, self.password)
            #### Mike (end)

         self.sensorUpdateFromRequest(device)


Code: Select all

   def sendRequest(self, device, urlAction):
      ....
         try:
            #### Mike (start)
            #f = urllib2.urlopen(theUrl)
            f = urllib2.urlopen(self.getUrlRequest(theUrl,device))
            #### Mike (end)
            requestOK = True
         ....


Code: Select all
def sensorUpdate(self,device,fromRequest):
      ...
            ## Mike (start)
            #f = urllib2.urlopen(theUrl)
            f = urllib2.urlopen(self.getUrlRequest(theUrl,device))
            ## Mike (end)

            ...
Last edited by miked0809 on Wed Nov 19, 2014 9:42 am, edited 1 time in total.

Posted on
Tue Nov 18, 2014 6:50 am
iblis offline
Posts: 75
Joined: Sep 16, 2014

Re: Roomba Plugin?

Thanks for this quick fix miked0809.

I did however find two issue with your code. For me to make it work I needed to add import base64 at the beginning of plugin.py and add urllib2 to f = urlopen(self.getUrlRequest(theUrl,device)) like this f = urllib2.urlopen(self.getUrlRequest(theUrl,device))

Best regards,
Andreas

Posted on
Wed Nov 19, 2014 9:43 am
miked0809 offline
Posts: 8
Joined: May 16, 2014

Re: Roomba Plugin?

Hi Andreas,

Thanks for pointing that out, I have edited my previous post to reflect those corrections.

Mike

Posted on
Mon Feb 09, 2015 9:38 am
ELWOOD offline
Posts: 225
Joined: Feb 11, 2007
Location: Ramsey, NJ

Re: Roomba Plugin?

Maybe she should be using indigo and the roomba plugin to set a sleep schedule and disable the roomba

http://www.telegraph.co.uk/news/worldnews/asia/southkorea/11399713/Robot-vacuum-cleaner-attacks-South-Korea-housewifes-hair.html


Elwood
Attachments
Robot-vacuum-clean_3192372b.jpg
Robot-vacuum-clean_3192372b.jpg (89.89 KiB) Viewed 2478 times

Posted on
Sun Jun 14, 2015 10:56 pm
PottedPorkProduct offline
User avatar
Posts: 13
Joined: Jun 29, 2014
Location: San Diego, CA, USA

Re: Roomba Plugin?

The Basic Auth errors are due to this bug: http://bugs.python.org/issue9639

miked0809's solution is one way to fix it, however the better way is to "Monkey Patch" the urllib2 library. Detailed here: http://bugs.python.org/msg122895

On my system, I opened "/Library/Application Support/Perceptive Automation/Indigo 6/Plugins/RooWIFI.IndigoPlugin/Contents/Server Plugin/plugin.py" and added the following code starting at line 22 between "from xml.etree import ...." and "class Plugin(IndigoPlugin)..."

Code: Select all
from xml.etree import ElementTree as ET

# MonkeyPatch URLLIB2 bug in Python 2.6.6
# http://bugs.python.org/msg122895
if sys.version_info[:2] == (2, 6) and sys.version_info[2] >= 6:
    def fixed_http_error_401(self, req, fp, code, msg, headers):
        url = req.get_full_url()
        response = self.http_error_auth_reqed('www-authenticate',
                                          url, req, headers)
        self.retried = 0
        return response

    urllib2.HTTPBasicAuthHandler.http_error_401 = fixed_http_error_401
# End MonkeyPatch

class Plugin(indigo.PluginBase):


Indigo Devs - you all might consider adding that blurb to the initialization routines of the Indigo Plugin host. Otherwise, any plugin using urllib2 on Yosemite is going to have this problem. I've already had to fix a couple of my own plugins.

Who is online

Users browsing this forum: No registered users and 40 guests