sem6000/example.py

38 lines
1.2 KiB
Python
Raw Normal View History

2020-01-16 18:48:26 +01:00
#!/usr/bin/env python3
2018-08-11 00:32:33 +02:00
import time
2019-02-27 22:01:46 +01:00
from sem6000 import SEMSocket
2020-01-16 14:50:48 +01:00
import bluepy
2019-02-27 22:01:46 +01:00
2020-01-16 14:50:48 +01:00
socket = None
2018-08-11 00:32:33 +02:00
while True:
time.sleep(1)
2019-02-27 22:01:46 +01:00
try:
2020-01-16 14:50:48 +01:00
if socket == None:
print("Connecting...")
# auto_reconnect_timeout enabled auto reconnect if sending a command fails. Valid values:
# None (default): everything that fails throws NotConnectedException's
# -1: infinite retries
# integer: seconds before exception is thrown
socket = SEMSocket('f0:c7:7f:0d:e7:17')
2020-01-16 14:50:48 +01:00
print("Connected.")
#socket.login("1337")
#socket.changePassword("1234")
#socket.login("1234")
2019-02-27 22:01:46 +01:00
socket.getStatus()
socket.setStatus(True)
print("=== {} ({}) ===".format(socket.mac_address, "on" if socket.powered else "off"))
2020-01-19 17:46:55 +01:00
print("\t{}V {}A → {}W@{}Hz (PF: {})".format(socket.voltage, socket.current, socket.power, socket.frequency, socket.power_factor))
2020-01-19 17:48:02 +01:00
except (SEMSocket.NotConnectedException, bluepy.btle.BTLEDisconnectError, BrokenPipeError):
2020-01-16 14:50:48 +01:00
print("Restarting...")
if socket != None:
socket.disconnect()
socket = None