diff --git a/davisAPI/PyWeather-master/.gitignore b/davisAPI/PyWeather/.gitignore similarity index 100% rename from davisAPI/PyWeather-master/.gitignore rename to davisAPI/PyWeather/.gitignore diff --git a/davisAPI/PyWeather-master/CHANGELOG.txt b/davisAPI/PyWeather/CHANGELOG.txt similarity index 100% rename from davisAPI/PyWeather-master/CHANGELOG.txt rename to davisAPI/PyWeather/CHANGELOG.txt diff --git a/davisAPI/PyWeather-master/COPYING.txt b/davisAPI/PyWeather/COPYING.txt similarity index 100% rename from davisAPI/PyWeather-master/COPYING.txt rename to davisAPI/PyWeather/COPYING.txt diff --git a/davisAPI/PyWeather-master/INSTALL.txt b/davisAPI/PyWeather/INSTALL.txt similarity index 100% rename from davisAPI/PyWeather-master/INSTALL.txt rename to davisAPI/PyWeather/INSTALL.txt diff --git a/davisAPI/PyWeather-master/MANIFEST.in b/davisAPI/PyWeather/MANIFEST.in similarity index 100% rename from davisAPI/PyWeather-master/MANIFEST.in rename to davisAPI/PyWeather/MANIFEST.in diff --git a/davisAPI/PyWeather-master/Makefile b/davisAPI/PyWeather/Makefile similarity index 100% rename from davisAPI/PyWeather-master/Makefile rename to davisAPI/PyWeather/Makefile diff --git a/davisAPI/PyWeather-master/README.md b/davisAPI/PyWeather/README.md similarity index 100% rename from davisAPI/PyWeather-master/README.md rename to davisAPI/PyWeather/README.md diff --git a/davisAPI/PyWeather-master/scripts/weatherpub.conf.example b/davisAPI/PyWeather/scripts/weatherpub.conf.example similarity index 100% rename from davisAPI/PyWeather-master/scripts/weatherpub.conf.example rename to davisAPI/PyWeather/scripts/weatherpub.conf.example diff --git a/davisAPI/PyWeather-master/scripts/weatherpub.py b/davisAPI/PyWeather/scripts/weatherpub.py similarity index 100% rename from davisAPI/PyWeather-master/scripts/weatherpub.py rename to davisAPI/PyWeather/scripts/weatherpub.py diff --git a/davisAPI/PyWeather-master/setup.py b/davisAPI/PyWeather/setup.py similarity index 100% rename from davisAPI/PyWeather-master/setup.py rename to davisAPI/PyWeather/setup.py diff --git a/davisAPI/PyWeather-master/weather/__init__.py b/davisAPI/PyWeather/weather/__init__.py similarity index 100% rename from davisAPI/PyWeather-master/weather/__init__.py rename to davisAPI/PyWeather/weather/__init__.py diff --git a/davisAPI/PyWeather-master/weather/services/__init__.py b/davisAPI/PyWeather/weather/services/__init__.py similarity index 100% rename from davisAPI/PyWeather-master/weather/services/__init__.py rename to davisAPI/PyWeather/weather/services/__init__.py diff --git a/davisAPI/PyWeather-master/weather/services/_base.py b/davisAPI/PyWeather/weather/services/_base.py similarity index 100% rename from davisAPI/PyWeather-master/weather/services/_base.py rename to davisAPI/PyWeather/weather/services/_base.py diff --git a/davisAPI/PyWeather-master/weather/services/file.py b/davisAPI/PyWeather/weather/services/file.py similarity index 100% rename from davisAPI/PyWeather-master/weather/services/file.py rename to davisAPI/PyWeather/weather/services/file.py diff --git a/davisAPI/PyWeather-master/weather/services/pws.py b/davisAPI/PyWeather/weather/services/pws.py similarity index 100% rename from davisAPI/PyWeather-master/weather/services/pws.py rename to davisAPI/PyWeather/weather/services/pws.py diff --git a/davisAPI/PyWeather-master/weather/services/tests/__init__.py b/davisAPI/PyWeather/weather/services/tests/__init__.py similarity index 100% rename from davisAPI/PyWeather-master/weather/services/tests/__init__.py rename to davisAPI/PyWeather/weather/services/tests/__init__.py diff --git a/davisAPI/PyWeather-master/weather/services/tests/test_file.py b/davisAPI/PyWeather/weather/services/tests/test_file.py similarity index 100% rename from davisAPI/PyWeather-master/weather/services/tests/test_file.py rename to davisAPI/PyWeather/weather/services/tests/test_file.py diff --git a/davisAPI/PyWeather-master/weather/services/wunderground.py b/davisAPI/PyWeather/weather/services/wunderground.py similarity index 100% rename from davisAPI/PyWeather-master/weather/services/wunderground.py rename to davisAPI/PyWeather/weather/services/wunderground.py diff --git a/davisAPI/PyWeather-master/weather/stations/__init__.py b/davisAPI/PyWeather/weather/stations/__init__.py similarity index 100% rename from davisAPI/PyWeather-master/weather/stations/__init__.py rename to davisAPI/PyWeather/weather/stations/__init__.py diff --git a/davisAPI/PyWeather-master/weather/stations/_struct.py b/davisAPI/PyWeather/weather/stations/_struct.py similarity index 100% rename from davisAPI/PyWeather-master/weather/stations/_struct.py rename to davisAPI/PyWeather/weather/stations/_struct.py diff --git a/davisAPI/PyWeather-master/weather/stations/davis.py b/davisAPI/PyWeather/weather/stations/davis.py similarity index 100% rename from davisAPI/PyWeather-master/weather/stations/davis.py rename to davisAPI/PyWeather/weather/stations/davis.py diff --git a/davisAPI/PyWeather-master/weather/stations/netatmo.py b/davisAPI/PyWeather/weather/stations/netatmo.py similarity index 100% rename from davisAPI/PyWeather-master/weather/stations/netatmo.py rename to davisAPI/PyWeather/weather/stations/netatmo.py diff --git a/davisAPI/PyWeather-master/weather/stations/station.py b/davisAPI/PyWeather/weather/stations/station.py similarity index 100% rename from davisAPI/PyWeather-master/weather/stations/station.py rename to davisAPI/PyWeather/weather/stations/station.py diff --git a/davisAPI/PyWeather-master/weather/stations/tests/__init__.py b/davisAPI/PyWeather/weather/stations/tests/__init__.py similarity index 100% rename from davisAPI/PyWeather-master/weather/stations/tests/__init__.py rename to davisAPI/PyWeather/weather/stations/tests/__init__.py diff --git a/davisAPI/PyWeather-master/weather/stations/tests/test_davis.py b/davisAPI/PyWeather/weather/stations/tests/test_davis.py similarity index 100% rename from davisAPI/PyWeather-master/weather/stations/tests/test_davis.py rename to davisAPI/PyWeather/weather/stations/tests/test_davis.py diff --git a/davisAPI/PyWeather-master/weather/stations/tests/test_station.py b/davisAPI/PyWeather/weather/stations/tests/test_station.py similarity index 100% rename from davisAPI/PyWeather-master/weather/stations/tests/test_station.py rename to davisAPI/PyWeather/weather/stations/tests/test_station.py diff --git a/davisAPI/PyWeather-master/weather/stations/validate.py b/davisAPI/PyWeather/weather/stations/validate.py similarity index 100% rename from davisAPI/PyWeather-master/weather/stations/validate.py rename to davisAPI/PyWeather/weather/stations/validate.py diff --git a/davisAPI/PyWeather-master/weather/units/__init__.py b/davisAPI/PyWeather/weather/units/__init__.py similarity index 100% rename from davisAPI/PyWeather-master/weather/units/__init__.py rename to davisAPI/PyWeather/weather/units/__init__.py diff --git a/davisAPI/PyWeather-master/weather/units/astro.py b/davisAPI/PyWeather/weather/units/astro.py similarity index 100% rename from davisAPI/PyWeather-master/weather/units/astro.py rename to davisAPI/PyWeather/weather/units/astro.py diff --git a/davisAPI/PyWeather-master/weather/units/precip.py b/davisAPI/PyWeather/weather/units/precip.py similarity index 100% rename from davisAPI/PyWeather-master/weather/units/precip.py rename to davisAPI/PyWeather/weather/units/precip.py diff --git a/davisAPI/PyWeather-master/weather/units/pressure.py b/davisAPI/PyWeather/weather/units/pressure.py similarity index 100% rename from davisAPI/PyWeather-master/weather/units/pressure.py rename to davisAPI/PyWeather/weather/units/pressure.py diff --git a/davisAPI/PyWeather-master/weather/units/temp.py b/davisAPI/PyWeather/weather/units/temp.py similarity index 100% rename from davisAPI/PyWeather-master/weather/units/temp.py rename to davisAPI/PyWeather/weather/units/temp.py diff --git a/davisAPI/PyWeather-master/weather/units/tests/__init__.py b/davisAPI/PyWeather/weather/units/tests/__init__.py similarity index 100% rename from davisAPI/PyWeather-master/weather/units/tests/__init__.py rename to davisAPI/PyWeather/weather/units/tests/__init__.py diff --git a/davisAPI/PyWeather-master/weather/units/tests/test_pressure.py b/davisAPI/PyWeather/weather/units/tests/test_pressure.py similarity index 100% rename from davisAPI/PyWeather-master/weather/units/tests/test_pressure.py rename to davisAPI/PyWeather/weather/units/tests/test_pressure.py diff --git a/davisAPI/PyWeather-master/weather/units/tests/test_temp.py b/davisAPI/PyWeather/weather/units/tests/test_temp.py similarity index 100% rename from davisAPI/PyWeather-master/weather/units/tests/test_temp.py rename to davisAPI/PyWeather/weather/units/tests/test_temp.py diff --git a/davisAPI/PyWeather-master/weather/units/tests/test_wind.py b/davisAPI/PyWeather/weather/units/tests/test_wind.py similarity index 100% rename from davisAPI/PyWeather-master/weather/units/tests/test_wind.py rename to davisAPI/PyWeather/weather/units/tests/test_wind.py diff --git a/davisAPI/PyWeather-master/weather/units/wind.py b/davisAPI/PyWeather/weather/units/wind.py similarity index 100% rename from davisAPI/PyWeather-master/weather/units/wind.py rename to davisAPI/PyWeather/weather/units/wind.py diff --git a/davisAPI/davisAPI.py b/davisAPI/davisAPI.py index c294ff9..f0e6601 100644 --- a/davisAPI/davisAPI.py +++ b/davisAPI/davisAPI.py @@ -1,13 +1,10 @@ -from influxdb_client import InfluxDBClient, Point -from influxdb_client.client.write_api import SYNCHRONOUS -from weather.stations.davis import VantagePro -import gc -from pprint import pprint -import time +from PyWeather.weather.stations.davis import VantagePro import logging +import mariadb import serial.tools.list_ports -import os -import sys +import gc +import time +from pprint import pprint logging.basicConfig(filename="Stations.log", @@ -17,61 +14,66 @@ logger = logging.getLogger('davis_api') logger.setLevel(logging.DEBUG) - def write_data(device, station, send=True): try: - device.parse() + #device.parse() data = device.fields - points = [] + print(data) + if len(data) < 1: + return + else: + print(data) fields = ['BarTrend', 'CRC', 'DateStamp', 'DewPoint', 'HeatIndex', 'ETDay', 'HeatIndex', 'HumIn', 'HumOut', 'Pressure', 'RainDay', 'RainMonth', 'RainRate', 'RainStorm', 'RainYear', 'SunRise', 'SunSet', 'TempIn', 'TempOut', 'WindDir', 'WindSpeed', 'WindSpeed10Min'] + if send: - for field in fields: - points.append(Point(station).field(field, data[field])) - write_api.write(bucket=bucket, record=points) + placeholders = ', '.join(['%s'] * len(fields)) + field_names = ', '.join(fields) + sql = f"INSERT INTO weather_data ({field_names}) VALUES ({placeholders})" + values = [data[field] for field in fields] + cursor.execute(sql, values) + conn.commit() else: pprint(data) - # tables = query_api.query(f'from(bucket:"{bucket}") |> range(start: -1h)') + del data - del points del fields gc.collect() except Exception as e: logger.error(str(e)) raise e - -# убрать + try: - token = "2CEePET3ss2khtjsdGrJap8mVzHhR2dRwuyK3NuFBvDgGtOMSi6Jstsrp2o-OANzD8fxB73PsTyIbqgbnokoXQ==" - bucket = 'wind' - org = "UlSTU" - url = "http://influxdb.athene.tech/" - client = InfluxDBClient(url=url, token=token, org=org) - write_api = client.write_api(write_options=SYNCHRONOUS) - query_api = client.query_api() -except Exception as e: - logger.error('DB_ERR:' + str(e)) + 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 - + try: ports = serial.tools.list_ports.comports() available_ports = {} + for port in ports: -# print(port) if port.serial_number == '0001': - available_ports['/dev/'+port.name] = port.vid - # COM = 'COM8' # '/dev/ttyUSB0' - # COM1 = '/dev/ttyUSB1' - # available_ports = {'/dev/ttyUSB0':'st1'} + available_ports[port.name] = port.vid + devices = [VantagePro(port) for port in available_ports.keys()] - # print(available_ports) + print(available_ports) while True: for i in range(len(devices)): - write_data(devices[i], 'st' + str(available_ports[list(available_ports.keys())[i]]), True) - time.sleep(15) # лучше 60 + print(devices[i].fields) + #write_data(devices[i], 'st' + str(available_ports[list(available_ports.keys())[i]]), True) + time.sleep(1) except Exception as e: - logger.error('Device_error' + str(e)) + logger.error('Device_error: ' + str(e)) raise e diff --git a/davisAPI/get_ports.py b/davisAPI/get_ports.py index c09a052..8e630d6 100644 --- a/davisAPI/get_ports.py +++ b/davisAPI/get_ports.py @@ -8,7 +8,7 @@ for port, desc, hwid in sorted(ports): available_ports = {} for port in ports: print(port.serial_number) - available_ports['/dev/' + port.name] = port.vid + available_ports[port.name] = port.vid devices = [port for port in available_ports.keys()] print(devices) print(ports[1].manufacturer) diff --git a/davisAPI/runner.py b/davisAPI/runner.py index fc30e2b..7b10b72 100644 --- a/davisAPI/runner.py +++ b/davisAPI/runner.py @@ -4,6 +4,6 @@ import sys #filename = sys.argv[1] filename = "davisAPI.py" while True: - print('Start'+filename) - p = Popen("python davisAPI\\" + filename, shell=True) + print('Start '+filename) + p = Popen("python ./" + filename, shell=True) p.wait()