예제 #1
0
def sensor2_conf():
    pca.pca_config(0,1,0)
    dc.s2_avg_data()
    rawData = ads.get_readData()
#    print "rawData sensor 2 = %ld" %rawData
    logfile.write("\n\tSensor2  = ")
    logfile.write(str(rawData))
예제 #2
0
def conf_sensor1():
#    print("sensor 1:")
    pca.pca_config(1,0,0)
    dc.s1_avg_data()
    sensor1Data = ads.get_readData()
    s1_avg = dc.get_s1Avg()
    pca.pca_config(1,1,1)
예제 #3
0
def conf_sensor2():
#    print("sensor 2:")
    pca.pca_config(0,1,0)
    dc.s2_avg_data()
    sensor2Data = ads.get_readData()
    s2_avg = dc.get_s2Avg()
    pca.pca_config(1,1,1)
예제 #4
0
 def sensor2(self, slot2_type):
     self.sensor_init(slot2_type)
     print "Sensor2: " + slot2_type
     pca.pca_config(0, 1, 0)
     lmp.lmp_init()
     ads.spi_init()
     pca.pca_config(1, 1, 1)
예제 #5
0
def sensor2(s2):
    #s.init(s2)
    pca.pca_config(0,1,0)
    print "sensor in sensor2 func %s" %s2
    s.init(s2)
    lmp.lmp_init()
    ads.spi_init()
    pca.pca_config(1,1,1)
예제 #6
0
def sensor1(s1):
    #s.init(s1)
    pca.pca_config(1,0,0)
    print "sensor in sensor1 func %s" %s1
    s.init(s1)
    lmp.lmp_init()
    ads.spi_init()
    pca.pca_config(1, 1, 1)	
예제 #7
0
def on():
    pca.pca_config(0,0,0)
    ''' turns ON the OPC (fan and laser) '''
    b1 = spi.writebytes([0x03])          # send the command byte
    sleep(9e-3)                             # sleep for 9 ms
    b2, b3 = spi.writebytes([0x00, 0x01])   # send bytes
    ##pca.pca_config(1,1,1)
    return True if b1 == 0xF3 and b2 == 0x03 else False
예제 #8
0
def conf_sensor2():
#    print("sensor 2:")
    pca.pca_config(0,1,0)
    s2_avg = dc.s2_avg_data()
    sensor2Data = ads.get_readData()
    #dc.get_s2Avg()
    pca.pca_config(1,1,1)
    #print s2_avg    
    val2 = s2_avg
    return val2
예제 #9
0
def conf_sensor1():
#    print("sensor 1:")
    pca.pca_config(1,0,0)
    s1_avg = dc.s1_avg_data()
    sensor1Data = ads.get_readData()
    #dc.get_s1Avg()
    pca.pca_config(1,1,1)
    #print s1_avg
    val1 =  s1_avg   
    return val1
예제 #10
0
 def __conf_gas2__(self, board):
     # print("conf_sensor 2:")
     pca.pca_config(0, 1, 0)
     # time.sleep(0.1)
     s2_avg = dc.s2_avg_data(board)
     # val2 = ads.readADS_Data(board)#
     # dc.get_s2Avg()
     pca.pca_config(1, 1, 1)
     # print s2_avg
     # time.sleep(0.1)
     val2 = s2_avg
     # print val2
     return val2
예제 #11
0
 def __conf_gas1__(self, board):
     # print("conf_sensor 1:")
     # if module_type
     pca.pca_config(1, 0, 0)
     # time.sleep(0.1)
     s1_avg = dc.s1_avg_data(board)
     # val1 = ads.readADS_Data(board)#readData()
     # dc.get_s1Avg()
     pca.pca_config(1, 1, 1)
     # time.sleep(0.1)
     # print s1_avg
     val1 = s1_avg
     return val1
예제 #12
0
def sensor2():
    s.init(s2)
    pca.pca_config(0,1,0)
    #print("SENSOR2  : %s", s2)
    lmp.lmp_init()
    ads.spi_init()   
예제 #13
0
def sensor1():
    s.init(s1)
    pca.pca_config(1,0,0)
    lmp.lmp_init()
    ads.spi_init()   
예제 #14
0
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
예제 #15
0
def sensor2(s2):
    s.init(s2)
    pca.pca_config(0,1,0)
    lmp.lmp_init()
    ads.spi_init()
    pca.pca_config(1,1,1)
예제 #16
0
def sensor1(s1):
    pca.pca_config(1,0,0)
    s.init(s1)
    lmp.lmp_init()
    ads.spi_init()
    pca.pca_config(1,1,1)