1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
import matplotlib.pyplot as plt
#import pywemo
from matplotlib import style
from datetime import datetime
import logging
from logging.handlers import RotatingFileHandler
import os
def my_mkdir(dir_name):
if not os.path.isdir(dir_name):
os.makedirs(dir_name)
log_date = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
log_file = 'logfile_' + log_date + '.txt'
if not (os.path.exists('output')):
my_mkdir('output')
# file logger and console initialisation
logger = logging.getLogger()
logger.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s,%(message)s')
my_path = os.getcwd() + os.sep + 'output' + os.sep + log_file
file_handler = RotatingFileHandler(my_path, 'a', 10000000, 1)
file_handler.setLevel(logging.DEBUG)
file_handler.setFormatter(formatter)
logger.addHandler(file_handler)
stream_handler = logging.StreamHandler()
stream_handler.setLevel(logging.DEBUG)
logger.addHandler(stream_handler)
style.use('fivethirtyeight')
#plt.axis([0, 10, 0, 1000])
plt.autoscale(enable=True, axis='both')
wemo_ip_address = "192.168.1.34"
wemourl = 'http://%s:%i/setup.xml' % (wemo_ip_address, 49153)
for i in range(10):
#wemo_device = pywemo.discovery.device_from_description(wemourl, None)
#plug_pwr = (round(wemo_device.current_power / 1000))
plug_pwr = 20
logger.info(str(plug_pwr))
plt.plot(i, plug_pwr, marker='o', color='red')
plt.pause(0.1)
plt.show() |
Partager