54 lines
1.5 KiB
Python
54 lines
1.5 KiB
Python
import logging
|
|
import time
|
|
|
|
import mariadb
|
|
import serial.tools.list_ports
|
|
|
|
from PyWeather.weather.stations.davis import VantagePro
|
|
|
|
logging.basicConfig(filename="Stations.log",
|
|
format='%(asctime)s %(message)s',
|
|
filemode='a')
|
|
logger = logging.getLogger('davis_api')
|
|
logger.setLevel(logging.DEBUG)
|
|
|
|
console_handler = logging.StreamHandler()
|
|
console_handler.setLevel(logging.DEBUG)
|
|
console_handler.setFormatter(logging.Formatter('%(asctime)s %(message)s'))
|
|
logger.addHandler(console_handler)
|
|
|
|
try:
|
|
conn = mariadb.connect(
|
|
user="wind",
|
|
password="wind",
|
|
host="193.124.203.110",
|
|
port=3306,
|
|
database="wind_towers"
|
|
)
|
|
cursor = conn.cursor()
|
|
except mariadb.Error as e:
|
|
logger.error('DB_ERR: ' + str(e))
|
|
raise e
|
|
while True:
|
|
try:
|
|
ports = serial.tools.list_ports.comports()
|
|
available_ports = {}
|
|
|
|
for port in ports:
|
|
if port.serial_number == '0001':
|
|
available_ports[port.name] = port.vid
|
|
|
|
devices = [VantagePro(port) for port in available_ports.keys()]
|
|
while True:
|
|
for i in range(1):
|
|
if len(devices) != 0:
|
|
logger.info(devices)
|
|
else:
|
|
raise Exception('Can`t connect to device')
|
|
time.sleep(60)
|
|
except Exception as e:
|
|
logger.error('Device_error' + str(e))
|
|
time.sleep(60)
|
|
|
|
# todo переписать под influx, для линухи приколы сделать
|