From 8325e98c10232dacca6c1e2a8044b1a24ab34cf4 Mon Sep 17 00:00:00 2001 From: Bjørn Mork Date: Sat, 11 May 2019 16:26:52 +0200 Subject: WiP: wifi scanning is working MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Bjørn Mork --- dcs8000lh-configure.py | 55 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/dcs8000lh-configure.py b/dcs8000lh-configure.py index 58dd478..f57e4db 100755 --- a/dcs8000lh-configure.py +++ b/dcs8000lh-configure.py @@ -6,31 +6,31 @@ import base64 from bluepy.btle import Peripheral class BleCam(object): - def __init__(self, address, pincode, command=None): + def __init__(self, address, pincode): self.pincode = pincode - self.command = command self.periph = Peripheral(address) self.ipcamservice() self.name = self.periph.getCharacteristics(uuid=0x2a00)[0].read().decode() # wellknown name characteristic self.dumpchars() - self.experiment() + self.unlock() def ipcamservice(self): try: print("getting IPCam service") - self.service = self.periph.getServiceByUUID(0xD001) + self.service = self.periph.getServiceByUUID(0xd001) except BTLEEException: print("no IPCam service found for %s" % periph.address) def dumpchars(self): handles = self.service.getCharacteristics() + print("%s supports these characteristics:" % self.name) for h in handles: print("%s - Handle=%#06x (%s)" % (h.uuid, h.getHandle(), h.propertiesToString())) - def experiment(self): + + def unlock(self): auth = self.service.getCharacteristics(0xa001)[0] - tmp = auth.read().decode().split(";", 10) - for t in tmp: + for t in auth.read().decode().split(";", 10): if t.startswith("C="): self.challenge=t.split("=",2)[1] hashit = self.name + self.pincode + self.challenge @@ -39,21 +39,42 @@ class BleCam(object): auth.write("M=0;K=".encode() + self.key, True) except: print("write failed") - print("ip config is %s" % self.service.getCharacteristics(0xa104)[0].read()) - if self.command != None: - run = "P=" + self.pincode + ";N=" + self.pincode + "&&(" + self.command + ")&" - try: - self.service.getCharacteristics(0xa201)[0].write(run.encode(), True) - except: - print("write failed") + + def get_ipconfig(self): + return self.service.getCharacteristics(0xa104)[0].read() + + def wifi_scan(self): + scan = self.service.getCharacteristics(0xa100)[0] + p = -1 + n = 0 + result = "" + while p < n: + t = scan.read().decode().split(";", 3) + result = result + t[2] + if not t[0].startswith("N=") or not t[1].startswith("P="): + return + n = int(t[0].split("=",2)[1]) + p = int(t[1].split("=",2)[1]) + print("read page %d of %d" % (p, n)) + return result.split("&", 50) + + def run_command(self, command): + run = "P=" + self.pincode + ";N=" + self.pincode + "&&(" + command + ")&" + try: + self.service.getCharacteristics(0xa201)[0].write(run.encode(), True) + except: + print("failed") if __name__ == '__main__': if len(sys.argv) < 3: print("Usage: {} ".format(sys.argv[0])) sys.exit(1) + + cam = BleCam(sys.argv[1], sys.argv[2]) + print("ip config is: %s" % cam.get_ipconfig()) + for network in cam.wifi_scan(): + print(network) if len(sys.argv) > 3: - BleCam(sys.argv[1], sys.argv[2], sys.argv[3]) - else: - BleCam(sys.argv[1], sys.argv[2]) + cam.run_command(sys.argv[3]) print("Done.") -- cgit v1.2.3