forked from sqozz/sem6000
Compare commits
1 commit
master
...
remove_rec
Author | SHA1 | Date | |
---|---|---|---|
sqozz | 0d399fe61c |
17
sem6000.py
17
sem6000.py
|
@ -4,7 +4,6 @@ import uuid
|
||||||
|
|
||||||
class SEMSocket():
|
class SEMSocket():
|
||||||
password = "0000"
|
password = "0000"
|
||||||
auto_reconnect_timeout = None
|
|
||||||
powered = False
|
powered = False
|
||||||
voltage = 0
|
voltage = 0
|
||||||
current = 0
|
current = 0
|
||||||
|
@ -17,9 +16,8 @@ class SEMSocket():
|
||||||
_notify_char = None
|
_notify_char = None
|
||||||
_btle_device = None
|
_btle_device = None
|
||||||
|
|
||||||
def __init__(self, mac, auto_reconnect_timeout = None):
|
def __init__(self, mac):
|
||||||
self.mac_address = mac
|
self.mac_address = mac
|
||||||
self.auto_reconnect_timeout = auto_reconnect_timeout
|
|
||||||
self._btle_device = btle.Peripheral(None ,addrType=btle.ADDR_TYPE_PUBLIC,iface=0)
|
self._btle_device = btle.Peripheral(None ,addrType=btle.ADDR_TYPE_PUBLIC,iface=0)
|
||||||
try:
|
try:
|
||||||
self.reconnect()
|
self.reconnect()
|
||||||
|
@ -80,18 +78,9 @@ class SEMSocket():
|
||||||
except:
|
except:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def __reconnect(self):
|
def reconnect(self):
|
||||||
self.disconnect()
|
self.disconnect()
|
||||||
self.connect()
|
self.connect()
|
||||||
|
|
||||||
def reconnect(self, timeout = None):
|
|
||||||
if timeout == None:
|
|
||||||
self.__reconnect()
|
|
||||||
else:
|
|
||||||
reconnect_start = time.time()
|
|
||||||
while abs(reconnect_start - time.time()) < timeout or timeout == -1:
|
|
||||||
self.__reconnect()
|
|
||||||
|
|
||||||
if not self.connected:
|
if not self.connected:
|
||||||
raise self.NotConnectedException
|
raise self.NotConnectedException
|
||||||
|
|
||||||
|
@ -182,7 +171,7 @@ class SEMSocket():
|
||||||
|
|
||||||
def send(self):
|
def send(self):
|
||||||
if not self.__btle_device.connected:
|
if not self.__btle_device.connected:
|
||||||
self.__btle_device.reconnect(self.__btle_device.auto_reconnect_timeout)
|
self.__btle_device.reconnect()
|
||||||
|
|
||||||
self.__btle_device._write_char.write(self.__data, True)
|
self.__btle_device._write_char.write(self.__data, True)
|
||||||
self.__btle_device._btle_device.waitForNotifications(5)
|
self.__btle_device._btle_device.waitForNotifications(5)
|
||||||
|
|
Loading…
Reference in a new issue