コード例 #1
0
ファイル: briza_lib.py プロジェクト: isclayton/Ridley2
    def opc(self, addr):
        try:
            # print addr
            # print "OPC_INIT"

            pca.pca_init(addr)
            pca.pca_config_pm(0, 0, 0)
            time.sleep(0.5)  # turn PM module power supplys on
            spi = spidev.SpiDev()
            spi.open(5, 1)
            spi.mode = 1
            spi.max_speed_hz = 500000
            alphasense = OPCN2(spi)
            time.sleep(0.5)
            # Turn the opc ON
            alphasense.on()
            # alphasense.on()
            # alphasense.set_fan_power(255)
            time.sleep(1)
            spi.close()
            # alphasense.on()
        except Exception, e:  # FirmwareError:
            spi.close()
            # pca.pca_config_pm(1,1,1,1)
            time.sleep(0.2)
            print "firmware error, " + str(e)
            pass
コード例 #2
0
ファイル: briza_lib.py プロジェクト: isclayton/Ridley2
 def readPPD60(self, addr):
     pca.pca_init(addr)
     pca.pca_config_pm(1, 0, 0)
     myDustSensor = upmPpd42ns.PPD42NS(20)
     data = myDustSensor.getData()
     time.sleep(0.1)
     ppd42_lpo = str(data.lowPulseOccupancy)
     ppd42_con = str(data.concentration)
     return ppd42_lpo, ppd42_con
コード例 #3
0
ファイル: briza_lib.py プロジェクト: isclayton/Ridley2
    def readSHARP(self, addr):
        pca.pca_init(addr)
        pca.pca_config_pm(1, 0, 0)
        myDustSensor = upmPpd42ns.PPD42NS(21)
        data = myDustSensor.getData()
        time.sleep(0.1)
        sharp_lpo = str(data.lowPulseOccupancy)
        sharp_con = str(data.concentration)

        return sharp_lpo, sharp_con
コード例 #4
0
ファイル: briza_v1.py プロジェクト: jdipika87/Project-Ridly
def call_pca(boardAddr):
    if boardAddr == board_addr[0]:
        pca.pca_init(0x1B)
        print "ON PCA : 0x1B"
    elif boardAddr == board_addr[1]:
        pca.pca_init(0x1D)
        print "ON PCA : 0x1D"
    elif boardAddr == board_addr[2]:
        pca.pca_init(0x1E)
        print "ON PCA : 0x1E"
    elif boardAddr == board_addr[3]:
        pca.pca_init(0x1F)
        print "ON PCA : 0x1F"
    else:
        print("please initialize the board in populate_sensor_board.py")
コード例 #5
0
ファイル: briza_service.py プロジェクト: isclayton/Ridley2
def __selftest__(boards, type):
    if "gas" in str(type):
        pass
    else:
        print "Beginning PM module test cycle"
        for i in range(len(boards)):
            if "0x18" not in str(boards[i]):
                pca.pca_init(boards[i])
                print "5V toggling on "+ str(boards[i]) + " for next 5 seconds"
                for t in range(5):
                    pca.pca_config_pm(1,0,0)
                    #Adjust sleep time to allow for different measurement methods (i.e. multimeter vs analyzer)
                    time.sleep(1)
                    pca.pca_config_pm(1,1,1)
                    time.sleep(1)
        print "PM test complete, proceeding to gas test"

    for i in range(len(boards)):
        pca.pca_init(boards[i])
        print ""
        print str("Board Address: " + str(boards[i]))
        print str("Test Config       Slot1 Counts            Slot2 Counts             Ratio       Result")
            #print str("I2C Address         Slot1 Counts        Slot2 Counts         Result")
        print str("---------------------------------------------------------------------------------------")
        testparams = {"PBias": 28565, "ZBias": 0, "NBias": -28565}

        for key in testparams.keys():
            pca.pca_init(boards[i])
            briza.sensor1(key)
            briza.sensor2(key)
            slot1_test_params = ['raw', '0','0','0','1',key]#testparams.keys()[1]]
            slot2_test_params = ['raw', '0','0','0','1',key]#testparams.keys()[1]]
            tmpdata1 = []
            tmpdata2 = []
            #for i in range(5):
            testdata = briza.read(boards[i],slot1_test_params, slot2_test_params, selftest=True)
            time.sleep(0.5)
            #tmpdata1.append(int(testdata['raw_value_slot1']))
            #tmpdata2.append(int(testdata['raw_value_slot2']))
            testval1 = float((testdata['raw_value_slot1']))#reduce(lambda x, y: x + y, tmpdata1) / len(tmpdata1)
            testval2 = float((testdata['raw_value_slot2']))#)reduce(lambda x, y: x + y, tmpdata2) / len(tmpdata2)
            if (testval1/testval2)<1.035 and (testval1/testval2)>0.82:
                resultstr = colored("Pass", "green")
            else:
                resultstr = colored("Failed", "red")
            print str(str(key)+ "            " + str(testval1) + "                 " + str(testval2)+ "                 " +str("%.5f" % (float(testval1)/float(testval2))) + "     " + str(resultstr))
コード例 #6
0
ファイル: briza_service.py プロジェクト: isclayton/Ridley2
def main(boards):
    
    slot1_parameters, slot2_parameters = briza.get_calibration()
    for board in boards:
        if any(x in str(slot1_parameters[board][5]) for x in pm_types):
            print "PM module bypass, configured as: " + str(slot1_parameters[board][5])
            #briza.opc(board)
            #briza.board_init(board, slot1_parameters[board][5],slot2_parameters[board][5])
            #briza.board_init(board, )
            #pca.pca_init(board, "OPC")
        else:  
            try:

                pca.pca_init(board)
                print "Init Sensor 1 on address: %s " % board
                briza.sensor1(slot1_parameters[board][5])
                time.sleep(0.1)
                print "Init Sensor 2 on address: %s " % board
                briza.sensor2(slot2_parameters[board][5])
               # print slot1_parameters
               ## print slot2_parameters
            except:
                raise

    while True:
        try:
            dataline = []              
            for board in boards:
                if any(x in str(slot1_parameters[board][5]) for x in pm_types):
                    #print str("PM Module / " + str(board))
                    newdata = briza.readPM(board, slot1_parameters[board][5])
                    #time.sleep(2)
                    pca.pca_config_pm(1,0,0)
                    #time.sleep(0.5)
                    if newdata.has_key("typeSensor3"):
                        newdata2 = {'concentration_slot1': newdata.get('concentration_slot3'),
                                        'concentration_slot2': newdata.get('concentration_slot3'),
                                        'typeSensor1': newdata.get('typeSensor3'),  'typeSensor2': newdata.get('typeSensor3'),
                                        'raw_value_slot1': newdata.get('raw_value_slot3'), 'raw_value_slot2': newdata.get('raw_value_slot3'),
                                        "temperature": newdata.get('temperature'), "humidity": newdata.get('humidity'),
                                        "pressure": newdata.get('pressure'), "address": newdata.get('address'), 'unit1': newdata.get('unit1'),'unit2': newdata.get('unit2')}
                        newdata.pop("concentration_slot3")
                        newdata.pop('typeSensor3')
                        newdata.pop('unit3')
                        newdata.pop('raw_value_slot3')


                        try:
                            write_serial(newdata2)
                            print "PM Data Sent"
                            #bleClient(newdata2)
                        except Exception as e:
                            print e
                            pass

                        dataline.append(newdata)
                        dataline.append(newdata2)

                    write_serial(newdata)


                    #time.sleep(0.2)

                else:
                    #print str("Gas Module / " + str(board))
                    #pca.pca_init(board)
                    newdata = briza.read(board, slot1_parameters[board], slot2_parameters[board])
                    dataline.append(newdata)
                    write_serial(newdata)
                    print "Gas Data Sent"
                    #bleData = dict(dataline)
                    #write_serial(newdata)
                #try:
                    #write_serial(newdata)
                    #bleClient(newdata)
                    #bleClient(newdata)
                    #bleClient(newdata2)
                #except Exception as e:
                #    print e
                #    pass


            briza.dbinsert(dataline)#writeToSocket(dataline)
        except AttributeError as ex:
            with open('errorlog.txt', 'a') as f:
                f.write(str(time.time()) + ',' + str(ex) + '\n')
            f.close()
        except KeyboardInterrupt:
            pca.pca_config_pm(1,1,1)
            pca.pca_config(1,1,1)
            with open('/home/root/errorlog.txt', 'a') as f:
                f.write(str(time.time()) + ',' + "Exited" + '\n')
            f.close()
            raise Exception, "exited"
        except IOError as ex:

            print ex
            with open('errorlog.txt', 'a') as f:
                f.write(str(time.time()) + ',' + str(ex) + '\n')
            f.close()
            pass
コード例 #7
0
ファイル: briza_lib.py プロジェクト: isclayton/Ridley2
    def read(self, board, slot1, slot2, selftest=False):
        pca.pca_init(board)
        # pm_types = ["OPC", "PPD42", "PPD60", "SHARP"]
        # else:
        # print "Reading Sensors on "+str(board)+", where Slot1: "+str(slot1)+" / Slot2: "+str(slot2)
        temperature, humidity, pressure = self.met_sensors()

        # time.sleep(0.1)
        ads.get_ads_config0(0x60)
        # time.sleep(0.2)

        s1vals = self.__conf_gas1__(board)

        val1 = float(s1vals[0])
        # time.sleep(0.2)
        ads.get_ads_config0(0x70)
        s2vals = self.__conf_gas2__(board)
        # time.sleep(0.2)
        val2 = float(s2vals[0])
        testval1 = s1vals[2]
        testval2 = s2vals[2]
        type1, type2 = str(slot1[5]), str(slot2[5])
        sensitivity1, sensitivity2 = str(slot1[4]), str(slot2[4])
        baseline1, baseline2 = str(slot1[3]), str(slot2[3])

        # if temperature <= 25:
        #    zero1, zero2 = str(list(slot1[2])[0]), str(list(slot2[2])[0])
        #    span1, span2 = str(list(slot1[1])[0]), str(list(slot2[1])[0])
        # else:
        zero1, zero2 = (
            str(slot1[2]),
            str(slot2[2]),
        )  # str(list(slot1[2])[2]), str(list(slot2[2])[2])# str(slot1[2]), str(slot2[2])
        span1, span2 = (
            str(slot1[1]),
            str(slot2[1]),
        )  # str(list(slot1[1])[2]), str(list(slot2[1])[2])#str(slot1[1]), str(slot2[1])
        print zero1, zero2, span1, span2
        unit1, unit2 = str(slot1[0]), str(slot2[0])
        con1 = self.__calculate_concentration__(
            temperature, val1, sensitivity1, baseline1, zero1, span1, type1.lower().strip("-")
        )
        con2 = self.__calculate_concentration__(
            temperature, val2, sensitivity2, baseline2, zero2, span2, type2.lower().strip("-")
        )
        print str("Raw: " + str(type1) + ":" + str(val1) + ", " + "Raw " + str(type2) + ":" + str(val2))

        dataline = {
            "temperature": temperature,
            "humidity": humidity,
            "pressure": pressure,
            "address": board,
            "typeSensor1": str(str(type1)),
            "raw_value_slot1": val1,
            "concentration_slot1": str(con1),
            "unit1": str(unit1),
            "typeSensor2": str(str(type2)),
            "raw_value_slot2": val2,
            "unit2": str(unit2),
            "concentration_slot2": str(con2),
        }
        testdataline = {
            "temperature": temperature,
            "humidity": humidity,
            "pressure": pressure,
            "address": board,
            "typeSensor1": str(str(type1)),
            "raw_value_slot1": testval1,
            "concentration_slot1": str(testval1),
            "unit1": str(unit1),
            "typeSensor2": str(str(type2)),
            "raw_value_slot2": testval2,
            "unit2": str(unit2),
            "concentration_slot2": str(testval2),
        }
        if selftest:
            return testdataline
        else:
            return dataline