I am currently investigating the same python script for my switchmate (I have one of the older versions).
I was able to scan for it, but I have not been able to get an auth key from it at all.
Every time I run
sudo python3 switchmate.py e8:08:05:7b:03:cb auth
I get
Traceback (most recent call last):
File "switchmate.py", line 161, in <module>
device.writeCharacteristic(AUTH_NOTIFY_HANDLE, NOTIFY_VALUE, True)
File "/usr/local/lib/python3.5/dist-packages/bluepy/btle.py", line 459, in writeCharacteristic
return self._getResp('wr')
File "/usr/local/lib/python3.5/dist-packages/bluepy/btle.py", line 334, in _getResp
resp = self._waitResp(wantType + ['ntfy', 'ind'], timeout)
File "/usr/local/lib/python3.5/dist-packages/bluepy/btle.py", line 296, in _waitResp
raise BTLEException(BTLEException.COMM_ERROR, "Error from Bluetooth stack (%s)" % errcode)
bluepy.btle.BTLEException: Error from Bluetooth stack (comerr)
I have tried sending the switch signal with no auth key, I have tried both keys for SWITCHMATE_SERVICE
(23d1bcea5f782315deef121223150000 and abd0f555eb40e7b2ac49ddeb83d32ba2)
As well as different values for AUTH_NOTIFY_HANDLE and AUTH_HANDLE.
I get the above stacktrace almost every time, though very rarely I will get
File "switchmate.py", line 167, in <module>
device.waitForNotifications(1.0)
File "/usr/local/lib/python3.5/dist-packages/bluepy/btle.py", line 473, in waitForNotifications
resp = self._getResp(['ntfy','ind'], timeout)
File "/usr/local/lib/python3.5/dist-packages/bluepy/btle.py", line 334, in _getResp
resp = self._waitResp(wantType + ['ntfy', 'ind'], timeout)
File "/usr/local/lib/python3.5/dist-packages/bluepy/btle.py", line 290, in _waitResp
raise BTLEException(BTLEException.DISCONNECTED, "Device disconnected")
bluepy.btle.BTLEException: Device disconnected
or
Traceback (most recent call last):
File "switchmate.py", line 147, in <module>
device = Peripheral(arguments[1], ADDR_TYPE_RANDOM)
File "/usr/local/lib/python3.5/dist-packages/bluepy/btle.py", line 318, in __init__
self.connect(deviceAddr, addrType, iface)
File "/usr/local/lib/python3.5/dist-packages/bluepy/btle.py", line 367, in connect
"Failed to connect to peripheral %s, addr type: %s" % (addr, addrType))
bluepy.btle.BTLEException: Failed to connect to peripheral e8:08:05:7b:03:cb, addr type: random
The weird part though, is that the switch will toggle itself about 30-45 seconds after the stacktrace for Error from bluetooth stack (commerr) is thrown…
I know you said you have one of the newer models that doesn’t seem to need authentication, but do you have any insight that might help support older models as well?
Edit: I have dug into btle.py:298 to see what is happening when the error occurred. I printed out the responses and I saw that the old switchmate responded with stat twice, first with a state of tryconn, then conn, and then a response of err with a code comerr. After the stacktrace a response with state of disc (disconnected) comes back.
I’m not sure why there is a communication error, the devices are right next to each other, and clearly data is going back and forth.
Stacktrace with response printed: