示例#1
0
    def comp_P(adc_pres):
        global flo
        pressure = 0.0

        v1 = (flo / 2.0) - 64000.0
        v2 = (((v1 / 4.0) * (v1 / 4.0)) / 2048) * dP[5]
        v2 = v2 + ((v1 * dP[4]) * 2.0)
        v2 = (v2 / 4.0) + (dP[3] * 65536.0)
        v1 = (((dP[2] * (((v1 / 4.0) * (v1 / 4.0)) / 8192)) / 8) +
              ((dP[1] * v1) / 2.0)) / 262144
        v1 = ((32768 + v1) * dP[0]) / 32768

        if v1 == 0:
            return 0
        pressure = ((1048576 - adc_pres) - (v2 / 4096)) * 3125
        if pressure < 0x80000000:
            pressure = (pressure * 2.0) / v1
        else:
            pressure = (pressure / v1) * 2
        v1 = (dP[8] * (((pressure / 8.0) * (pressure / 8.0)) / 8192.0)) / 4096
        v2 = ((pressure / 4.0) * dP[7]) / 8192.0
        pressure = pressure + ((v1 + v2 + dP[6]) / 16.0)
        pressure = pressure / 100  #converts to hPa

        # Save to db
        newReading = RecentPressureModel(None, None, pressure)
        logging.info("Reading pressure sensor with value: " + str(pressure))
        newReading.post()
示例#2
0
def mockRun():
	while True:
		try:
			# Mock data creation
			value = random.uniform(0,100)
			newReading = RecentPressureModel(None,None,value)

			# Insert
			logging.info("Generating mock data for pressure sensor with value: "+str(value))
			newReading.post()

			time.sleep(5)
		except BaseException as e:
			logging.exception(e)