def pick_value(line, value, first_sensor, count, xl_data): write_bool = True splited = line.strip().split(';') if "adc_temperature" in line or "at" in line: temperature = float(splited[-1]) / 100 line = new_line(splited, temperature) value['temp'] = value['temp'] + temperature elif "Chemsense" in line: if "ID" in line: value['id'] = splited[-1] else: chem_reading = float(splited[-1]) value[splited[-2]] = [chem_reading, line] write_bool = False elif "pressure" in line: pressure = float(splited[-1]) / 100 line = new_line(splited, pressure) elif "HTU21D" in line and "temperature" in line: temperature = float(splited[-1]) line = new_line(splited, temperature) elif "PR103J2" in line: pre_temperature = float(splited[-1]) if pre_temperature > 1255: temperature = round(getRT(pre_temperature), 2) else: temperature = pre_temperature line = new_line(splited, temperature) elif "LPS25H" in line: temperature = float(splited[-1]) / 100 line = new_line(splited, temperature) elif "SHT25" in line: if "temperature" in line: temperature = float(splited[-1]) / 100 line = new_line(splited, temperature) elif "humidity" in line: humidity = float(splited[-1]) / 100 line = new_line(splited, humidity) elif "HIH4030" in line: humidity = float(splited[-1]) * 5 / 1024 humidity = humidity * 30.68 + 0.958 line = new_line(splited, humidity) elif "intensity" in line: line = intensity_conv(line) return line, value, write_bool
def read_data(nodeNAME): data_dict = {} for i in range(len(nodeNAME)): ################################ Raw data from beehive1 ## including time data_dict[nodeNAME[i]] = {} ### temperature data_dict[nodeNAME[i]]["tmp112"] = [] data_dict[nodeNAME[i]]["bmp180"] = [] data_dict[nodeNAME[i]]["tsys01"] = [] data_dict[nodeNAME[i]]["pr103j2"] = [] data_dict[nodeNAME[i]]["tmp421"] = [] data_dict[nodeNAME[i]]["hih6130"] = [] data_dict[nodeNAME[i]]["htu21d"] = [] data_dict[nodeNAME[i]]["lps25h"] = [] data_dict[nodeNAME[i]]["sht25"] = [] data_dict[nodeNAME[i]]["co_adc_tmp"] = [] data_dict[nodeNAME[i]]["co_lmp_tmp"] = [] data_dict[nodeNAME[i]]["so2_adc_tmp"] = [] data_dict[nodeNAME[i]]["o3_tmp"] = [] data_dict[nodeNAME[i]]["irr_tmp"] = [] ### pressure data_dict[nodeNAME[i]]["pressbmp180"] = [] data_dict[nodeNAME[i]]["presslps25h"] = [] ### humidity data_dict[nodeNAME[i]]["huhih4030"] = [] data_dict[nodeNAME[i]]["huhih6130"] = [] data_dict[nodeNAME[i]]["huhtu21d"] = [] data_dict[nodeNAME[i]]["husht25"] = [] ### light data_dict[nodeNAME[i]]["apds"] = [] data_dict[nodeNAME[i]]["ml8511"] = [] data_dict[nodeNAME[i]]["mlx"] = [] data_dict[nodeNAME[i]]["tsl260"] = [] data_dict[nodeNAME[i]]["tsl250as"] = [] data_dict[nodeNAME[i]]["tsl250ls"] = [] data_dict[nodeNAME[i]]["rawapds"] = [] data_dict[nodeNAME[i]]["rawml8511"] = [] data_dict[nodeNAME[i]]["rawmlx"] = [] data_dict[nodeNAME[i]]["rawtsl260"] = [] data_dict[nodeNAME[i]]["rawtsl250as"] = [] data_dict[nodeNAME[i]]["rawtsl250ls"] = [] data_dict[nodeNAME[i]]["SIR"] = [] data_dict[nodeNAME[i]]["SUV"] = [] data_dict[nodeNAME[i]]["SVL"] = [] ### sound level sensor data_dict[nodeNAME[i]]["spv"] = [] ### magnetic field data_dict[nodeNAME[i]]["magx"] = [] data_dict[nodeNAME[i]]["magy"] = [] data_dict[nodeNAME[i]]["magz"] = [] data_dict[nodeNAME[i]]["magrms"] = [] ### accelerometer data_dict[nodeNAME[i]]["accx"] = [] data_dict[nodeNAME[i]]["accy"] = [] data_dict[nodeNAME[i]]["accz"] = [] ### chemical sensor data_dict[nodeNAME[i]]["irr"] = [] data_dict[nodeNAME[i]]["iaq"] = [] data_dict[nodeNAME[i]]["no2"] = [] data_dict[nodeNAME[i]]["so2"] = [] data_dict[nodeNAME[i]]["h2s"] = [] data_dict[nodeNAME[i]]["o3"] = [] data_dict[nodeNAME[i]]["co"] = [] ### time data_dict[nodeNAME[i]]["time"] = [] time = 0 inputcsv = './sensor_data_set_' + nodeNAME[i] + '.csv' with open(inputcsv) as f: for line in f: newtime = line.strip().split(';')[1] if time != newtime: time = newtime datetime_object = datetime.strptime( time, "%Y_%m_%d_%H:%M:%S") convtime = datetime_object data_dict[nodeNAME[i]]["time"].append(convtime) if "temperature" in line: if "TMP112" in line: temperature = float(line.strip().split(';')[-1]) data_dict[nodeNAME[i]]["tmp112"].append(temperature) elif "BMP180" in line: temperature = float(line.strip().split(';')[-1]) data_dict[nodeNAME[i]]["bmp180"].append(temperature) elif "TSYS01" in line: temperature = float(line.strip().split(';')[-1]) data_dict[nodeNAME[i]]["tsys01"].append(temperature) elif "PR103J2" in line: pre_temperature = float(line.strip().split(';')[-1]) temperature = round(getRT(pre_temperature), 2) data_dict[nodeNAME[i]]["pr103j2"].append(temperature) elif "TMP421" in line: temperature = float(line.strip().split(';')[-1]) data_dict[nodeNAME[i]]["tmp421"].append(temperature) elif "HIH6130" in line: temperature = float(line.strip().split(';')[-1]) data_dict[nodeNAME[i]]["hih6130"].append(temperature) elif "HTU21D" in line: temperature = float(line.strip().split(';')[-1]) data_dict[nodeNAME[i]]["htu21d"].append(temperature) elif "LPS25H" in line: temperature = float(line.strip().split(';')[-1]) / 100 data_dict[nodeNAME[i]]["lps25h"].append(temperature) elif "SHT25" in line: temperature = float(line.strip().split(';')[-1]) / 100 data_dict[nodeNAME[i]]["sht25"].append(temperature) elif "pressure" in line: if "BMP180" in line: pressure = float(line.strip().split(';')[-1]) / 100 data_dict[nodeNAME[i]]["pressbmp180"].append(pressure) elif "LPS25H" in line: pressure = float(line.strip().split(';')[-1]) / 100 data_dict[nodeNAME[i]]["presslps25h"].append(pressure) elif "humidity" in line: if "HIH6130" in line: humidity = float(line.strip().split(';')[-1]) data_dict[nodeNAME[i]]["huhih6130"].append(humidity) elif "SHT25" in line: pressure = float(line.strip().split(';')[-1]) / 100 data_dict[nodeNAME[i]]["husht25"].append(pressure) elif "HTU21D" in line: humidity = float(line.strip().split(';')[-1]) data_dict[nodeNAME[i]]["huhtu21d"].append(humidity) elif "HIH4030" in line: humidity = float( line.strip().split(';')[-1]) * 5 / 1023 - 0.85 humidity = humidity * 100 / 3 data_dict[nodeNAME[i]]["huhih4030"].append(humidity) elif "intensity" in line: if "APDS-9006-020" in line: intensity = float(line.strip().split(';')[-1]) data_dict[nodeNAME[i]]["rawapds"].append(intensity) irrad = (intensity / 0.001944) / 405.1 # 405.1 unit: mA/lux data_dict[nodeNAME[i]]["apds"].append(irrad) elif "ML8511" in line: intensity = float(line.strip().split(';')[-1]) data_dict[nodeNAME[i]]["rawml8511"].append(intensity) intensity = intensity * 0.0000625 * 2.50 irrad = (intensity - 1) * 14.9916 / 0.12 # - 18.71 if 2.5 <= irrad <= 3.0: irrad = irrad - 0.3 elif 3.0 <= irrad <= 4.0: irrad = irrad - 0.6 elif 4.0 <= irrad <= 4.2: irrad = irrad - 0.4 elif 4.5 < irrad: irrad = irrad + 0.25 data_dict[nodeNAME[i]]["ml8511"].append(irrad) elif "MLX75305" in line: intensity = float(line.strip().split(';')[-1]) data_dict[nodeNAME[i]]["rawmlx"].append(intensity) irrad = ( intensity * 0.0000625 * 2.50 - 0.09234 ) / 0.007 #with gain 1, the factor is 7mA/(uW/cm^2) data_dict[nodeNAME[i]]["mlx"].append(irrad) elif "TSL260RD" in line: intensity = float(line.strip().split(';')[-1]) data_dict[nodeNAME[i]]["rawtsl260"].append(intensity) irrad = (intensity * 0.0000625 * 2.50 - 0.006250) / 0.058 data_dict[nodeNAME[i]]["tsl260"].append(irrad) elif "TSL250RD-AS" in line: intensity = float(line.strip().split(';')[-1]) data_dict[nodeNAME[i]]["rawtsl250as"].append(intensity) irrad = intensity * 0.0000625 * 2.5 / 0.064 data_dict[nodeNAME[i]]["tsl250as"].append(irrad) elif "TSL250RD-LS" in line: intensity = float(line.strip().split(';')[-1]) data_dict[nodeNAME[i]]["rawtsl250ls"].append(intensity) irrad = (intensity * 0.0000625 * 2.5 - 0.005781) / 0.064 data_dict[nodeNAME[i]]["tsl250ls"].append(irrad) # elif "Chemsense" in line: # if "mac" in line: # continue # elif "at" in line: # data_name = line.strip().split(';')[-2] # temperature = float(line.strip().split(';')[-1])/100 # data_dict[nodeNAME[i]][data_name].append(temperature) # elif "so2" in line: ## at sensor name should be match with other name with tmp!!! # ppm = conv(float(line.strip().split(';')[-1])/100 # data_dic[nodeNAME[i]]["so2"].append(ppm) # elif "CO LMP Temp" in line: # temperature = float(line.strip().split(';')[-1])/100 # data_dict[nodeNAME[i]]["co_lmp_tmp"].append(temperature) # elif "CO ADC Temp" in line: # temperature = float(line.strip().split(';')[-1])/100 # data_dict[nodeNAME[i]]["co_adc_tmp"].append(temperature) # elif "SO2/H2S Temp" in line: # temperature = float(line.strip().split(';')[-1])/100 # data_dict[nodeNAME[i]]["so2_adc_tmp"].append(temperature) # elif "O3/NO2 Temp" in line: # temperature = float(line.strip().split(';')[-1])/100 # data_dict[nodeNAME[i]]["o3_tmp"].append(temperature) # elif "IAQ/IRR Temp" in line: # temperature = float(line.strip().split(';')[-1])/100 # data_dict[nodeNAME[i]]["irr_tmp"].append(temperature) return data_dict
def _convert_PR(self, sensor_data): PR_data = getRT(int(sensor_data)) return str(PR_data)
def parse_sensor (sensor_id,sensor_data): #"Board MAC" "Board MAC" if sensor_id == '0': # print "Sensor:", sensor_id,sensor_list[int(sensor_id)],'@ ', data = '' for i in range(len(sensor_data)): data = data + str(format3(sensor_data[i])) # print dataa = pass #firmware version elif sensor_id == "253": hw_sw_version = firmware_version(sensor_data[0:2]) hw_ver = (hw_sw_version / 1000) / 10. fw_ver = (hw_sw_version - hw_ver * 10000) / 100. build_time = build_info_time(sensor_data[2:6]) build_git = '{0:02x}'.format(format1(sensor_data[6:8])) print "Sensor:", sensor_id, "Firmware_version", '@ ', print hw_ver, fw_ver, build_time, build_git #alpha histo elif sensor_id == '40': print "Sensor:", sensor_id, sensor_list[int(sensor_id)], '@ ' alphasense_histo(sensor_data) #alpha firmware elif sensor_id == '41': print "Sensor:", sensor_id, sensor_list[int(sensor_id)], '@ ', print ord(sensor_data[0]), ord(sensor_data[1]) #alpha configuration elif sensor_id == '42': print "Sensor:", sensor_id, sensor_list[int(sensor_id)], '@ ' alpha_config = sensor_data elif sensor_id == '43': alpha_config.extend(sensor_data) elif sensor_id == '44': alpha_config.extend(sensor_data) elif sensor_id == '45': alpha_config.extend(sensor_data) print alpha_config #"TMP112" "TMP112" elif sensor_id == '1': print "Sensor:", sensor_id,sensor_list[int(sensor_id)],'@ ', print format6(sensor_data) #"HTU21D" "HTU21D" elif sensor_id == '2': HTU21D_temp = format6(sensor_data[0:0+__lenFmt6]) HTU21D_humid = format6(sensor_data[0+__lenFmt6:0+__lenFmt6+__lenFmt6]) HTU21D_compensate_humid = HTU21D_humid - (25 - HTU21D_temp) * 0.15 print "Sensor:", sensor_id,sensor_list[int(sensor_id)],'@ ', print "{:2.2f}".format(HTU21D_temp), "{:2.2f}".format(HTU21D_compensate_humid) # print format6(sensor_data[0:0+__lenFmt6]), format6(sensor_data[0+__lenFmt6:0+__lenFmt6+__lenFmt6]) #"GP2Y1010AU0F": REMOVED, NOT IN ANY VERSION # elif sensor_id == '3': # print "Sensor:", sensor_id,sensor_list[int(sensor_id)],'@ ', # print format6(sensor_data[0:0+__lenFmt6]), format5(sensor_data[0+__lenFmt6:0+__lenFmt6+__lenFmt5]) #"HIH4030": how does the date format changed? "GP2Y1010AU0F" has been chaned elif sensor_id == '3': HIH4030_val = format1(sensor_data) HIH4030_voltage = (HIH4030_val * 5.00) / 1023.00 # extended exposure to > 90% RH causes a reversible shift of 3% RH HIH4030_humidity = (HIH4030_voltage - 0.85) * 100.00 / 3.00 # PUT DARK LEVEL VOLTAGE 0.85 FOR NOW print "Sensor:", sensor_id,sensor_list[int(sensor_id)],'@ ', print "{:2.2f}".format(HIH4030_humidity) #"BMP180" "BMP180" elif sensor_id == '4': print "Sensor:", sensor_id,sensor_list[int(sensor_id)],'@ ', print format6(sensor_data[0:0+__lenFmt6]), format5(sensor_data[0+__lenFmt6:0+__lenFmt6+__lenFmt5]) #"PR103J2" "PR103J2" elif sensor_id == '5': PR103J2_val = format1(sensor_data) try: temperature_PR = getRT(PR103J2_val) except Exception, e: print "ERROR", str(e) pass print "Sensor:", sensor_id,sensor_list[int(sensor_id)],'@ ', print "{:2.2f}".format(temperature_PR)
def parse_sensor(sensor_id, sensor_data): #"Board MAC" "Board MAC" if sensor_id == '0': print "Sensor:", sensor_id, sensor_list[int(sensor_id)], '@ ', data = '' for i in range(len(sensor_data)): data = data + str(format3(sensor_data[i])) print data #firmware version elif sensor_id == "253": hw_sw_version = firmware_version(sensor_data[0:2]) hw_ver = (hw_sw_version / 1000) / 10. fw_ver = (hw_sw_version - hw_ver * 10000) / 100. build_time = build_info_time(sensor_data[2:6]) build_git = '{0:02x}'.format(format1(sensor_data[6:8])) print "Sensor:", sensor_id, "Firmware_version", '@ ', print hw_ver, fw_ver, build_time, build_git elif sensor_id == "252": tip_count = format1(sensor_data) rain_inches = float(tip_count) * 0.01 print "Sensor:", sensor_id, "Rain_Gauger", ' @', print rain_inches elif sensor_id == "251": dielectric = format6(sensor_data[0:2]) conductivity = format6(sensor_data[2:4]) temperature = format6(sensor_data[4:6]) volumetric_water_content = 4.3 * math.pow(10, -6) * math.pow( dielectric, 3) - 5.5 * math.pow(10, -4) * math.pow( dielectric, 2) + 2.92 * math.pow( 10, -2) * dielectric - 5.3 * math.pow(10, -2) vwc = '{:2.4f}'.format(volumetric_water_content) print "Sensor:", sensor_id, "Decagon", ' @', print vwc, dielectric, conductivity, temperature #alpha histo elif sensor_id == '40': print "Sensor:", sensor_id, sensor_list[int(sensor_id)], '@ ' alphasense_histo(sensor_data) #alpha firmware elif sensor_id == '41': print "Sensor:", sensor_id, sensor_list[int(sensor_id)], '@ ', print ord(sensor_data[0]), ord(sensor_data[1]) #alpha configuration elif sensor_id == '42': print "Sensor:", sensor_id, sensor_list[int(sensor_id)], '@ ' alpha_config = sensor_data elif sensor_id == '43': alpha_config.extend(sensor_data) elif sensor_id == '44': alpha_config.extend(sensor_data) elif sensor_id == '45': alpha_config.extend(sensor_data) print alpha_config #"TMP112" "TMP112" elif sensor_id == '1': print "Sensor:", sensor_id, sensor_list[int(sensor_id)], '@ ', print format6(sensor_data) #"HTU21D" "HTU21D" elif sensor_id == '2': HTU21D_temp = format6(sensor_data[0:0 + __lenFmt6]) HTU21D_humid = format6(sensor_data[0 + __lenFmt6:0 + __lenFmt6 + __lenFmt6]) HTU21D_compensate_humid = HTU21D_humid - (25 - HTU21D_temp) * 0.15 print "Sensor:", sensor_id, sensor_list[int(sensor_id)], '@ ', print "{:2.2f}".format(HTU21D_temp), "{:2.2f}".format( HTU21D_compensate_humid) # print format6(sensor_data[0:0+__lenFmt6]), format6(sensor_data[0+__lenFmt6:0+__lenFmt6+__lenFmt6]) #"GP2Y1010AU0F": REMOVED, NOT IN ANY VERSION # elif sensor_id == '3': # print "Sensor:", sensor_id,sensor_list[int(sensor_id)],'@ ', # print format6(sensor_data[0:0+__lenFmt6]), format5(sensor_data[0+__lenFmt6:0+__lenFmt6+__lenFmt5]) #"HIH4030": how does the date format changed? "GP2Y1010AU0F" has been chaned elif sensor_id == '3': HIH4030_val = format1(sensor_data) HIH4030_voltage = ( HIH4030_val * 5.0 ) / 1023.00 # extended exposure to > 90% RH causes a reversible shift of 3% RH HIH4030_humidity = ( HIH4030_voltage - 0.85) * 100.00 / 3.00 # PUT DARK LEVEL VOLTAGE 0.85 FOR NOW print "Sensor:", sensor_id, sensor_list[int(sensor_id)], '@ ', print "{:2.2f}".format(HIH4030_humidity) #"BMP180" "BMP180" elif sensor_id == '4': print "Sensor:", sensor_id, sensor_list[int(sensor_id)], '@ ', print format6(sensor_data[0:0 + __lenFmt6]), format5( sensor_data[0 + __lenFmt6:0 + __lenFmt6 + __lenFmt5]) #"PR103J2" "PR103J2" elif sensor_id == '5': PR103J2_val = format1(sensor_data) try: temperature_PR = getRT(PR103J2_val) except Exception, e: print "ERROR", str(e) pass print "Sensor:", sensor_id, sensor_list[int(sensor_id)], '@ ', print "{:2.2f}".format(temperature_PR)
def pick_value(line, value, first_sensor, count, xl_data): write_bool = True splited = line.strip().split(';') if "adc_temperature" in line: temperature = float(splited[-1])/100 key = splited[-2] + '_scaled' line = new_line(splited, temperature, key) if "LMP_Temp" not in line: value['temp'] = value['temp'] + temperature elif "Chemsense" in line: if "ID" in line: value['id'] = splited[-1] elif "at" in line: temperature = float(splited[-1]) value['temp'] = value['temp'] + temperature else: chem_reading = float(splited[-1]) value[splited[-2]] = [chem_reading, line] write_bool = False elif "pressure" in line: pressure = float(splited[-1]) key = splited[-2] + '_hPa' if pressure > 10000: pressure = pressure/100 line = new_line(splited, pressure, key) elif "PR103J2" in line: pre_temperature = float(splited[-1]) if pre_temperature > 100: temperature = round(getRT(pre_temperature), 2) key = splited[-2] + '_degree_c' line = new_line(splited, temperature, key) else: temperature = pre_temperature elif "LPS25H" in line: if "temperature" in line: temperature = float(splited[-1]) key = splited[-2] + '_degree_c' if abs(temperature) > 100: temperature = temperature / 100 line = new_line(splited, temperature, key) elif ("BMP180" or "HIH6130" or "HTU21D" or "TMP112" or "TMP421" or "TSYS01") in line: if "temperature" in line: temperature = float(splited[-1]) key = splited[-2] + '_deg_c' line = new_line(splited, temperature, key) elif "humidity" in line: temperature = float(splited[-1]) key = splited[-2] + '_RH' line = new_line(splited, temperature, key) elif "SHT25" in line: if "temperature" in line: temperature = float(splited[-1]) key = splited[-2] + '_degree_c' if abs(temperature) > 100: temperature = temperature / 100 line = new_line(splited, temperature, key) elif "humidity" in line: humidity = float(splited[-1]) key = splited[-2] + '_RH' if humidity > 100: humidity = humidity / 100 line = new_line(splited, humidity, key) elif "HIH4030" in line: humidity = float(splited[-1]) if humidity > 100: humidity = float(splited[-1]) * 5 / 1024 humidity = humidity * 30.68 + 0.95 key = splited[-2] + '_RH' line = new_line(splited, humidity, key) elif "intensity" in line: line = intensity_conv(line) return line, value, write_bool