from __future__ import print_function from serial import Serial import struct, time, json from DbClass import sqliteClass db = sqliteClass('/home/pi/Desktop/Project/OutdoorDB.db') DEBUG = 0 CMD_MODE = 2 CMD_QUERY_DATA = 4 CMD_DEVICE_ID = 5 CMD_SLEEP = 6 CMD_FIRMWARE = 7 CMD_WORKING_PERIOD = 8 MODE_ACTIVE = 0 MODE_QUERY = 1 TRYFLAG = 0 JSON_FILE = '/var/www/html/aqi.json' byte, data = 0, "" portName = "/dev/ttyUSB0" #portName = "COM4" class PM_Reader(object): def __init__(self): try: Serial(port=portName, baudrate=9600).close() self.ser = Serial(port=portName, baudrate=9600, timeout=1) time.sleep(0.2) except: self.ser = Serial(port=portName, baudrate=9600, timeout=1)
# coding=utf-8 from DbClass import sqliteClass import json import requests import datetime import time import pandas db = sqliteClass('/home/pi/Desktop/Project/IndoorDb.db') # db = sqliteClass('IndoorDb.db') # reference value (50µg/m3) pmReference = 50 # reference value (200µg/m3) no2Reference = 200 # reference value (120µg/m3) o3Reference = 120 def readData(): dataDF = db.select('sensors_data', '*, MAX(data_date) AS collectDate', where='data_used=0', groupBy='data_sensor_name', orderBy='collectDate DESC ') return dataDF def validationData(data): if len(data) == 4: current_time = datetime.datetime.now()
from DbClass import sqliteClass import json import requests import datetime import time # db = sqliteClass('/home/pi/Desktop/Project/IndoorDb.db') db = sqliteClass('IndoorDb.db') urlRest = 'https://www.airpolito.it/restaqi-insert/' def readData(): dataDF = db.select('apqi_data', '*', 'data_sent=0', limit=20) return dataDF def sendData(data): counting = 0 cError = None for index, row in data.iterrows(): data_id = row['data_id'] apqi_value = row['apqi_value'] apqi_status = row['apqi_status'] sensor_json = row['sensor_json'] date_sensors = row['date_sensors'] jsonToSend = {} jsonToSend['aqi_status'] = apqi_status jsonToSend['aqi_value'] = apqi_value