This script gets the credentials that allows the other scripts to run. You need to know the Roomba's IP address and create the roombaIP variable. The author of dorita980 made a big deal about making sure the headers were right, but I haven't found the Roomba to be sensitive to the headers at all.
To get Roomba into the proper mode, Roomba must be in the dock. Hold down the "Home" button until Roomba plays a four note confirmation sound. Then run this script. There's no error checking, so if you get the timing wrong, you may need to execute again. If the script fails, you'll need to put Roomba back into this mode again.
- Code: Select all
import requests
import json
from base64 import b64encode
from requests.auth import HTTPBasicAuth
from requests.utils import quote
roombaIP = (indigo.variables['roombaIP'].value)
#roombaPassword = (indigo.variables['roombaPassword'].value)
#roombaBlid = (indigo.variables['roombaUsernameBlid'].value)
post_url = 'https://' + roombaIP + ':443/umi'
head = {
}
payload = {
"do": "get",
"args": ["passwd"],
"id": "1"
}
r = requests.post(post_url, json=payload, headers=head, verify=False)
broken = str(r.text)
fixed = broken.replace('"''}}','}')
data = json.loads(fixed)
pwd = str(data['ok']['passwd'])
indigo.server.log('Password: ' + pwd)
passEncode = b64encode('user:'+ pwd)
head = {
'Authorization': 'Basic ' + passEncode
}
payload = {
"do": "get",
"args": ["sys"],
"id": "1"
}
r = requests.post(post_url, json=payload, headers=head, verify=False)
broken = str(r.text)
fixed = broken.replace('"''}','')
data = json.loads(fixed)
blid = ''
for element in data['ok']['blid']:
blidA = hex(element)
blidB = blidA.replace('0x','')
blidC = blidB.upper()
blid += str(blidC)
indigo.server.log('Blid: ' + blid)
#indigo.variable.updateValue('roombaPassword', value=str(pwd))
#indigo.variable.updateValue('roombaUsernameBlid', value=str(blid))