def main(): print ('Starting logging of Plugwise Stick...') s = Stick(port = port_stick) circles = [] [circles.append(Circle(mac,s)) for mac in mac_circles] x = 0 while True: x += 1 readings = {} for circle in circles: try: power = circle.get_power_usage() except Exception: power = -1.0 readings[circle.mac] = power epoch = time.time() datenow = time.strftime('%Y-%m-%dT%H:%M:%S+01:00') print x, epoch, datenow, '=========================================================' pp.pprint(readings) log_str = buildLogString(readings, datenow) with open(filepath, 'a') as myFile: myFile.write(log_str) postToEmoncms(readings, epoch) postToLocalDB(readings, datenow) sleep(timeout)
def read_plugs(port): l = open(logfile, 'a') PS = Stick(port) try: PS = Stick(port) add_to_blacklist = [] db_update = [] db_device = [] except serial.SerialException as e: l.write(human_time + "\t Serial exception " + str(e)+"\n") except OSError as er: raise Exception(human_time + " Port " + port + " does not exist") except Exception: import traceback l.write(human_time + "\t Couldn`t open serial port, Exception: " + traceback.format_exc()+"\n") for i in circles['circle_mac']: smart_plug = Circle(i, PS) try: if is_blacklisted(script_start, i): db_entry.append("-1") else: a = smart_plug.get_power_usage() db_entry.append(a) db_update.append(a) db_device.append(i) except ValueError: db_entry.append("-2") l.write(human_time + " : "+str(smart_plugs[i])+" = "+ str(i) + ": Wrong value exception thrown, can`t read the power\n") except TimeoutException: db_entry.append("-3") l.write(human_time + " : "+str(smart_plugs[i]) +" = "+ str(i) + ": Timeout / Added to banlist for " + str(blacklist_duration)+" seconds \n") add_to_blacklist.append(i) if add_to_blacklist: blacklist(add_to_blacklist) if db_update: update_db_device_table(db_device, db_update) l.close()
class PlugwiseOperator(): def __init__(self, port,mac): stick = Stick(port) self.socket = Circle(mac, stick) self.socketActive = True self.socketUsage = 0 def setStatus(self,status): if status == "true": self.socket.switch_on() else: self.socket.switch_off() def getStatus(self): if self.socketActive: try: pwUsage = round(self.socket.get_power_usage(), 2) except: print "socket not active" pwUsage = 0 self.socketActive = False pwIsOn = "OFF" if pwUsage > 0.1: pwIsOn = "ON" self.socketUsage = pwUsage else: pwUsage = self.socketUsage return pwIsOn def getData(self): if self.socketActive: try: pwUsage = round(self.socket.get_power_usage(), 2) except: print "socket not active" pwUsage = 0 self.socketActive = False else: pwUsage = 0 pwIsOn = "OFF" if pwUsage > 0.1: pwIsOn = "ON" self.socketUsage = pwUsage else: pwUsage = self.socketUsage return pwUsage
""" Created on Sat Jun 22 13:16:58 2019 Script Name:lamp.py Script parse data from outputlamp.txt to execute the steps of the lampplanner. """ # Open the file with read only permit #Import all the necessary packages from plugwise import Stick from plugwise import Circle import pymysql import pandas as pd import time s = Stick(port="/dev/ttyUSB0") c1, c2 = Circle("000D6F0005692784", s), Circle("000D6F000416E6F4", s) host = "mydbinstance.c1arr1firswu.us-east-2.rds.amazonaws.com" port = 3306 dbname = "smartGardenDB" user = "******" password = "******" conn = pymysql.connect(host, user=user, port=port, passwd=password, db=dbname, autocommit=True) f = open('outputlamp.txt', "r+")
# Import MQTT client modules import paho.mqtt.client as mqtt # Import Plugwise modules for both stick and circle from plugwise import Stick from plugwise import Circle # MAC ID for both the Circles mac1 = "000D6F0004B1E1D6" mac2 = "000D6F0003562BE1" # Plugwise Stick port plugwise_stick = Stick(port="/dev/ttyUSB0") # Binding each circle to the stick plugwise_Circle_1 = Circle(mac1, plugwise_stick) # for heater plugwise_Circle_2 = Circle(mac2, plugwise_stick) # lamp # turning off the devices conected to circles by default plugwise_Circle_1.switch_off() plugwise_Circle_2.switch_off() # Configure thingsboard host and Access_token THINGSBOARD_HOST = '141.58.216.26' ACCESS_TOKEN = 'DHT-48Data' # Home Sensor Data captured and uploaded interval in seconds. INTERVAL=10 # Setting the Time Stamp for initial reading, later values are appended by INTERVAL next_reading = time.time()
import PlantIdentificationTest import paho.mqtt.client as mqtt from time import sleep import pymysql import pandas as pd import matplotlib.pyplot as plt import matplotlib.animation as animation from plugwise import Stick from plugwise import Circle import constants import telebot import continuemsg import datetime s = Stick(port="/dev/ttyUSB0") c1, c2 = Circle("000D6F0005692784", s), Circle("000D6F000416E6F4", s) options = ZWaveOption("/dev/ttyACM0", config_path='/home/pi/openzwave/openzwave/config', user_path=".") options.set_console_output(False) options.lock() network = ZWaveNetwork(options, log=None) network.start() #Database details moisturecontentold = list() host = "mydbinstance.c1arr1firswu.us-east-2.rds.amazonaws.com" port = 3306 dbname = "smartGardenDB" user = "******" password = "******"
def __init__(self, port,mac): stick = Stick(port) self.socket = Circle(mac, stick) self.socketActive = True self.socketUsage = 0