def __init__(self, db_file="realaqi.db"): Thread.__init__(self) # assign GPIO pins that control mux selector pins # (If you're using a GPIO) # Set Mux pin self.mux = [easyGpio(24), easyGpio(25), easyGpio(26), easyGpio(27)] for sel in self.mux: sel.pinOUT() # initialize ADC library to read ADC value(s) self.A0 = ADC(0) self.A1 = ADC(1) #Set sensor's output data self.sensor_output = { "type": "real", "timestamp": 0., "so2": 0., "co": 0., "no2": 0., "o3": 0., "pm25": 0., "temp": 0. } # Make Sensors aqi data form self.sensor_aqi = { "type": "aqi", "timestamp": 0., "so2aqi": 0., "coaqi": 0., "no2aqi": 0., "o3aqi": 0., "pm25aqi": 0., "totalaqi": 0. } self.sensor_output_lock = Lock() self.db_file = db_file try: self.db_conn = sqlite3.connect(self.db_file, check_same_thread=False) self.db_cur = self.db_conn.cursor() except Exception as e: print "ERROR (sensor.py) : {}".format(repr(e)) self.__del__() #execute query to create table using IF NOT EXISTS keywords self.db_cur.execute( "CREATE TABLE IF NOT EXISTS history (type TEXT, timestamp INT, so2 REAL, co REAL, no2 REAL, o3 REAL, pm25 REAL, temp REAL)" ) self.db_conn.commit() self.db_cur.execute( "CREATE TABLE IF NOT EXISTS aqi (type TEXT, timestamp INT, so2aqi REAL, coaqi REAL, no2aqi REAL, o3aqi REAL, pm25aqi REAL, totalaqi REAL)" ) self.db_conn.commit()
def __init__(self, db_file="blue.db"): Thread.__init__(self) # assign GPIO pins that control mux selector pins # (if you're using a GPIO) self.mux = [ easyGpio(24), easyGpio(25), easyGpio(26), easyGpio(27) ] for sel in self.mux: sel.pinOUT() # initialize ADC library to read ADC value(s) self.A0 = ADC(0) # alphasense, PM 2.5 self.A1 = ADC(1) # temperature sensor # json format output self.sensor_output = { "date": 0., "temp": 0., "no2": 0., "no2_1h_aqi": 0., "o3": 0., "o3_1h_aqi": 0., "o3_8h_aqi": 0., "co": 0., "co_8h_aqi": 0., "so2": 0., "so2_1h_aqi": 0., "so2_24h_aqi": 0., "pm25": 0., "pm25_aqi": 0. } self.sensor_output_lock = Lock() self.db_file = db_file try: self.db_conn = sqlite3.connect(self.db_file) self.db_cur = self.db_conn.cursor() except Exception as e: print "ERROR (sensor.py): {}".format(repr(e)) self.__del__() self.db_cur.execute("select datetime('now')") # delete all data on the table '''self.db_cur.execute("DROP TABLE history") self.db_conn.commit()''' # execute query to create table using IF NOT EXISTS keywords self.db_cur.execute("CREATE TABLE IF NOT EXISTS history (time INT PRIMARY KEY NOT NULL, temp REAL, no2 REAL, o3 REAL, co REAL, so2 REAL, pm25 REAL)") self.db_conn.commit()
def __init__(self, db_file): Thread.__init__(self) ############# A D C self.A0 = ADC(0) self.A1 = ADC(1) ############# M U X self.mux = [easyGpio(24), easyGpio(25), easyGpio(26), easyGpio(27)] ############# S Q L i t e self.sensor_output = { "temp": 0., "NO2": 0., "O3": 0., "CO": 0., "SO2": 0., "date": 0, "PM25": 0. } ############# SENSOR CALI TABLE INIT self.WE_NO2 = 0 self.WE_O3 = 0 self.WE_CO = 0 self.WE_SO2 = 0 self.AE_NO2 = 0 self.AE_O3 = 0 self.AE_CO = 0 self.AE_SO2 = 0 self.SE_NO2 = 0. self.SE_O3 = 0. self.SE_CO = 0. self.SE_SO2 = 0. ############# RESET SENSOR_NUM self.sensor_num = 0 self.mac = "" self.sensor_output_lock = Lock() self.db_file = db_file self.send_status = 1 try: self.db_conn = sqlite3.connect(self.db_file) self.db_cur = self.db_conn.cursor() except Exception as e: print "ERROR (sensor.py): {}".format(repr(e)) self.__del__() # execute query to create table using IF NOT EXISTS keywords self.db_cur.execute( "CREATE TABLE IF NOT EXISTS history (date INT PRIMARY KEY NOT NULL, TEMP REAL, NO2 REAL, O3 REAL, CO REAL, SO2 REAL, PM25 REAL)" ) self.db_conn.commit()
from neo import easyGpio from time import sleep flash = easyGpio(21) flash.pinOUT() while True: flash.on() sleep(1) flash.off() sleep(1) flash.on() sleep(2) flash.off() sleep(1)
from neo_adc import ADC from bluetooth import * import json from collections import OrderedDict from time import sleep from neo import easyGpio A0 = ADC(0) mux = [ easyGpio(24), easyGpio(25), easyGpio(26), easyGpio(27) ] for sel in mux: sel.pinOUT() def set_mux_channel(ch): bits = "{0:04b}".format(ch) for i in range(0, 4): bit = int(bits[i]) sel = mux[i] sel.on() if bit else sel.off() server_sock = BluetoothSocket(RFCOMM) server_sock.bind(("", PORT_ANY)) server_sock.listen(1) port = server_sock.getsockname()[1]
from neo import easyGpio from time import sleep pin = easyGpio(2) # Pin 2 with LED readpin = easyGpio(3) # Pin 3 with switch pin.pinOUT() # Make pin output readpin.pinIN() # Make pin in while True: pin.on() # Turn pin on sleep(1) # wait one second pin.off() # Turn pin off print "pin 3 state %d" % readpin.get() # Get current pin state sleep(1)