コード例 #1
0
def pressdetect(anypress):
    global bme280data
    global presscount
    pressreleasejudge = 0
    try:
        pressdata = BME280.bme280_read()
        prevpress = pressdata[1]
        time.sleep(1)
        pressdata = BME280.bme280_read()
        latestpress = pressdata[1]
        #print(presscount)
        deltP = latestpress - prevpress
        if 0.0 in bme280data:
            print("BME280rror!")
            pressreleasejudge = 2
            presscount = 0
        elif deltP > anypress:
            presscount += 1
            if presscount > 4:
                pressreleasejudge = 1
                print("pressreleasejudge")
        else:
            presscount = 0
        #print(str(latestpress) + "	:	" + str(prevpress))
    except:
        print(traceback.format_exc())
        presscount = 0
        pressreleasejudge = 2
    return pressreleasejudge, presscount
コード例 #2
0
    def __init__(self, i2c=None):
        """
        Initialize the enviromental sensor
        """
        self.i2c = i2c

        if self.i2c:
            self.addresses = self.i2c.scan()

            log.info('I2C addresses [{}]', self.addresses)

            self.bme280 = None
            if bme280.BME280_I2CADDR1 in self.addresses:
                log.info(
                    'Initialize Temperature, Humidity and Barometric sensor on {}',
                    bme280.BME280_I2CADDR1)
                self.bme280 = bme280.BME280(address=bme280.BME280_I2CADDR1,
                                            i2c=i2c)  # default address 0x76s

            if bme280.BME280_IC2ADDR2 in self.addresses:
                log.info(
                    'Initialize Temperature, Humidity and Barometric sensor on {}',
                    bme280.BME280_IC2ADDR2)
                self.bme280 = bme280.BME280(address=bme280.BME280_IC2ADDR2,
                                            i2c=i2c)  # default address 0x77
コード例 #3
0
def setup():
	global phaseChk
	pi.write(22,1)
	pi.write(24,1)
	BME280.bme2280_setup()
	BME280_calib_param()
	TSL2561.tsl2561_setup()
	GPS.openGPS()

	with open(phaseLog, 'a') as f:
		pass
コード例 #4
0
def setup():
    pi.set_mode(22, pigpio.OUTPUT)
    pi.write(22, 0)  #IM920
    pi.write(17, 0)  #outcasing
    time.sleep(1)
    BME280.bme280_setup()
    BME280.bme280_calib_param()
    #	BMX055.bmx055_setup()
    GPS.openGPS()
    with open('log/releaseLog.txt', 'a') as f:
        pass
    with open('log/landingLog.txt', 'a') as f2:
        pass
    with open('log/runningLog.txt', 'a') as f3:
        pass
コード例 #5
0
def Pressdetect(anypress):
	global bme280data
	global Pcount
	presslandjudge = 0
	try:
		pressdata = BME280.bme280_read()
		Prevpress = pressdata[1]
		Latestpress = pressdata[1]
		deltP = abs(Latestpress - Prevpress)
		print(str(Latestpress)+"    :    "+str(Prevpress))
		if 0.0 in bme280data:
			print("BME280error!")
			presslandjudge = 2
			Pcount = 0
			print(Pcount)
		elif deltP < anypress:
			Pcount += 1
			print(Pcount)
			if Pcount > 4:
				presslandudge = 1
				print("presslandjudge")
		else:
			Pcount = 0
			print(Pcount)
	except:
		print(traceack.format_exc())
		Pcount = 0
		presslandjudge = 2
		print(Pcount)
	return Pcount, presslandjudge
コード例 #6
0
def transmit_measurements(delay=5):
    global sta_if
    client = mqttrobust.MQTTClient(client_id=client_id,
                                   user="******",
                                   password="******",
                                   server=server_ip)

    i2c = machine.I2C(scl=machine.Pin(22), sda=machine.Pin(21), freq=10000)
    bme = BME280.BME280(i2c=i2c)

    while sta_if.isconnected():
        try:
            msg = ujson.dumps({
                "temperature": bme.temperature,
                "humidity": bme.humidity,
                "air_pressure": bme.pressure
            })
            print(msg)
            try:
                client.connect()
                client.publish(topic="sensors/" + str(device_id) +
                               "/measurements",
                               msg=msg)
                client.disconnect()
            except OSError:
                print("Connecting to MQTT server failed.")
            sleep(delay)
        except mqttsimple.MQTTException:
            break
            print("Machine broke")
コード例 #7
0
 def __init__(self, addr=0x76):  # Set the address
     try:
         self.sensor_bme280 = BME280.BME280(address=addr)
     except:
         # pass
         raise IOError("Sensor not connected")
     return
コード例 #8
0
    def do_GET(self):
        '''
        handle the HTTP GET request
        '''
        # first time through get create the controller
        if self.__device is None:
            self.__device = BME280.BME280()

        # Send response status code
        self.send_response(200)

        # Send headers
        self.send_header('Content-type', 'application/json')
        self.end_headers()

        result = []
        sample = {}
        sample['type'] = self.__device.get_chip_type()
        sample['id'] = self.__device.get_uid()
        temperature,pressure,humidity = \
            self.__device.retrieve_temperature_pressure_humidity()
        sample['temp_C'] = temperature
        sample['rel_hum'] = humidity
        sample['pressure'] = pressure
        sample['when'] = \
            datetime.datetime.now(datetime.timezone.utc).isoformat()
        result.append(sample)

        # Write content as utf-8 data
        self.wfile.write(bytes(json.dumps(result, indent=1), "utf8"))
        return
コード例 #9
0
ファイル: Land.py プロジェクト: cansat2019kimuralab/Detection
def pressdetect(presslandThd):
    try:
        global Pcount
        global bme280Data
        presslandjudge = 0
        secondlatestPRESS = bme280Data[1]
        bme280Data = BME280.bme280_read()  #更新
        latestPRESS = bme280Data[1]
        deltP = abs(latestPRESS - secondlatestPRESS)
        if bme280Data == [0.0, 0.0, 0.0, 0.0]:
            print("BMEerror!")
            presslandjudge = 2
            Pcount = 0
        elif 0.0 in bme280Data:
            print("BMEerror!")
            presslandjudge = 2
            Pcount = 0
        elif deltP < presslandThd:
            Pcount += 1
            if Pcount > 4:
                presslandjudge = 1
                #print("preslandjudge")
        else:
            Pcount = 0
            presslandjudge = 0
        #print(str(latestPRESS)+"	:	"+"delt	"+str(deltP))
        #print("Pcount	"+str(Pcount))
    except:
        print(traceback.format_exc())
        Pcount = 0
        presslandjudge = 2
    finally:
        return presslandjudge, Pcount
コード例 #10
0
def readBME280(CONFIG):
    import gc
    gc.collect()

    from machine import Pin, I2C
    gc.collect()

    # Configure i2c
    i2c = I2C(scl=Pin(CONFIG['SCL_PIN']),
              sda=Pin(CONFIG['SDA_PIN']),
              freq=10000)

    try:
        import BME280
        gc.collect()
        bme = BME280.BME280(i2c=i2c)
    except:
        print("ERROR: BME280")
        temperature = -255  # Temperature in celcius
        humidity = -255  # Humidity in % relative humidity
        pressure = -255  # Pressure in Pa
    else:
        [temperature, pressure, humidity] = bme.read_compensated_data()
        temperature /= 100  # Temperature in Celcius
        pressure /= 25600  # Pressure in hPa
        humidity /= 1024  # Humidity in %

    return [temperature, humidity, pressure]
コード例 #11
0
def check_sensors(mqtt):
    global i2c, sensor_data

    bme = BME280.BME280(i2c=i2c)
    css = CCS811.CCS811(i2c=i2c, addr=90)

    while True:

        data = {} 
        data['temp'] = round(bme.temperature, 1)
        data['hum'] = round(bme.humidity, 1)
        data['pres'] = round(bme.pressure, 1)


        if css.data_ready():
            css.put_envdata(humidity=data['hum'],temp=data['temp'])
            data['eCO2'] = css.eCO2
            data['tVOC'] = css.tVOC


        for key in data:
            topic = key
            msg = data[key]
            mqtt.publish(mqtt.pub_topic + topic, str(msg) )


        sensor_data = data


        time.sleep(SENSORS_SLEEP)
コード例 #12
0
 def __init__(self):
     self.i2c = I2C(scl=Pin(5), sda=Pin(4), freq=400000)  #i2c settings
     self.display = sh1106.SH1106_I2C(
         128, 64, self.i2c, Pin(16),
         0x3c)  #Load the driver and set it to "display"
     self.bme = BME280.BME280(i2c=self.i2c)  #sensor function
     self.pump = PWM(Pin(14), freq=0,
                     duty=0)  #create PWM objekt and configure pump forward
     #self.pump_reverse = PWM(Pin(12), freq=0, duty=0) #create PWM objekt and configure pump backwards
     #self.button = Pin(0, Pin.IN, Pin.PULL_UP) #initialize button
     self.adc = ads1x15.ADS1115(
         self.i2c, self.addr, self.gain
     )  #create analog-digtial converter object to read analog humidity sensor
     self.time_start = time.ticks_ms() / 1000  #Sekunden
     self.autosetinterval = time.ticks_ms() / 1000 + 25200  #counter
     self.time_current = 0
     self.time_start = 0
     self.reset = 0
     self.epoche = 0
     self.water_storage = 1.2
     self.water_use = 0
     self.water_status = True
     self.button = Pin(0, Pin.IN, Pin.PULL_UP)
     self.button.irq(trigger=Pin.IRQ_FALLING, handler=self.handle_interrupt)
     self.soil_dry = 20000  #CSensor >20000 /Annahme Test offen
     self.soil_ok = 15000  #CSensor 15000 bis 10000 /Annahme Test offen
     self.soil_humid = 10000  #CSensor 250 - bis 10000 /Annahme Test offen
     #self.soil_humidity = None
     self.activateAndClearDisplay()
コード例 #13
0
def Pressdetect(anypress):
    global bme280data
    global Pcount
    global pressdata
    presslandjudge = 0
    try:
        #print(pressdata)
        Prevpress = pressdata[1]
        #print("Prev=", Prevpress)
        time.sleep(1)
        pressdata = BME280.bme280_read()
        Latestpress = pressdata[1]
        #print("Latest=", str(Latestpress))
        deltP = abs(Latestpress - Prevpress)
        #print(str(Latestpress)+"    :    "+str(Prevpress))
        if 0.0 in bme280data:
            print("BME280error!")
            presslandjudge = 2
            Pcount = 0
            #print(Pcount)
        elif deltP < anypress:
            Pcount += 1
            #print(Pcount)
            if Pcount > 4:
                presslandjudge = 1
                print("presslandjudge")
        else:
            Pcount = 0
            #print(Pcount)
    except:
        print(traceback.format_exc())
        Pcount = 0
        presslandjudge = 2
        #print(Pcount)
    return Pcount, presslandjudge
コード例 #14
0
def read_sensor():
  # tuple to hold results from sensor
  temppresshumd = ()
  try:
# the BME280 is connected using i2c
    # ESP32 - Pin assignment
    #i2c = I2C(scl=Pin(22), sda=Pin(21), freq=10000)
# ESP8266 - Pin assignment
    i2c = I2C(scl=Pin(5), sda=Pin(4), freq=10000)
# temperature results in celsius
    bme = BME280.BME280(i2c=i2c)
    #temp = bme.temperature
    hum = bme.humidity
    pres = bme.pressure
    
  # uncomment for temperature in Fahrenheit
    temp = (bme.read_temperature()/100) * (9/5) + 32
    temp = str(round(temp, 2)) + 'F'
    
    temppresshumd[0] = temp
    temppresshumd[1] = hum
    temppresshumd[2] = pres

    print(temppresshumd)
    
  except Exception as oe:
    print('BME280 Exception {}'.format(oe))   
   
  return temppresshumd 
コード例 #15
0
def setup():
    global phaseChk
    pi.set_mode(17, pigpio.OUTPUT)
    pi.set_mode(22, pigpio.OUTPUT)
    pi.write(22, 1)
    pi.write(17, 0)
    time.sleep(1)
    BME280.bme280_setup()
    BME280.bme280_calib_param()
    BMX055.bmx055_setup()
    GPS.openGPS()

    with open(phaseLog, 'a') as f:
        pass

    phaseChk = int(Other.phaseCheck(phaseLog))
コード例 #16
0
	def ReadBME280(self):
		try:
			p=0.0
			temp = None
			i = 0
			sensor = BME280()
			while ( p==0.0 and i < 10):
				i = i+1
				temp = sensor.read_temperature()
				p = sensor.read_pressure()
				#p = pascals / 100
				humidity = sensor.read_humidity()
				#globalvars.meteo_data.hum_out = humidity
				if (self.cfg.sensor_type not in self.implementedStations):
					globalvars.meteo_data.hum_out = humidity
				else:
					globalvars.meteo_data.hum_in = humidity
				
				#p,temp = self.bmp085.readPressureTemperature()
				if p == 0.0 :
					time.sleep(0.5)
					
			if ( p != None )  :  
				abs_pressure = float(p / 100.0) 
				globalvars.meteo_data.abs_pressure =  abs_pressure
				
				
				if ( self.cfg.sensor_type in self.implementedStations):
					if ( self.cfg.sensor_temp_in == "Default"):
						globalvars.meteo_data.temp_in = temp
				else:
					if ( self.cfg.sensor_temp_out == "Default"):
						globalvars.meteo_data.temp_out = temp

				if ( self.cfg.sensor_temp_out == "BMP085"):
						globalvars.meteo_data.temp_out = temp	
				if ( self.cfg.sensor_temp_in == "BMP085"):
						globalvars.meteo_data.temp_in = temp	
				
				log("BME280 - Temperature: %.1f C Pressure:    %.1f humidity %.0f" % (temp, abs_pressure,humidity) )
				
			else:
				globalvars.meteo_data.abs_pressure = None
				
				if ( self.cfg.sensor_type in self.implementedStations):
					globalvars.meteo_data.temp_in = None
				else:
					globalvars.meteo_data.temp_out = None		
				return
			


		except:
			globalvars.meteo_data.abs_pressure = None
			if ( self.cfg.sensor_type in self.implementedStations):
				globalvars.meteo_data.temp_in = None
			else:
				globalvars.meteo_data.temp_out = None
			log("ERROR reading BMP280 sensor")
コード例 #17
0
ファイル: main.py プロジェクト: semen-trofimov/micropython
def show_data(request):
    i2c = I2C(scl=Pin(22), sda=Pin(21), freq=10000)
    bme = BME280.BME280(i2c=i2c)
    temp = bme.temperature
    hum = bme.humidity
    pres = bme.pressure
    data = {temp, hum, pres}
    server.send(data=json.dumps(data))
コード例 #18
0
def sensor_humidity():
    temperature, pressure, humidity = BME280.readAllSensors()

    post_data = [{"value": humidity, "unit_id": 3}]
    data = json.dumps(post_data)
    resp = Response(data, status=200, mimetype='application/json')

    return resp
コード例 #19
0
def setup():
        global phaseChk
        print("setup start")
        pi.set_mode(22,pigpio.OUTPUT)
        pi.write(22,1)  #IM920  Turn On
        pi.write(24,0)  #meltPin off
        time.sleep(1)
        TSL2561.tsl2561_setup()
        BME280.bme280_setup()
        BME280.bme280_calib_param()
#       BMX055.bmx055_setup()
#       GPS.openGPS()
        with open(phaseLog, 'a') as f:
                pass

#       phaseChk = int(Other.phaseCheck(phaseLog))
        print(phaseChk)
コード例 #20
0
def testBME280():
    i2c = machine.I2C(sda=machine.Pin(21),
                      scl=machine.Pin(22))  # configuramos el acceso al bus i2c
    i2c.scan(
    )  # Comprobamos que se detecta el dispositivo en la direccion 0x76 (118)
    bme = BME280.BME280(i2c=i2c, address=118)
    print('Temp: ' + str(bme.temperature) + ' Pres: ' + str(bme.pressure) +
          ' Hum: ' + str(bme.humidity))
コード例 #21
0
def takePhoto():
	global photoName
	global gpsData
	photo = ""
	photo = Capture.Capture(photopath)
	gpsData = GPS.readGPS()
	if not(photo == "Null"):
		photoName = photo
	Other.saveLog(captureLog, time.time() - t_start, gpsData, BME280.bme280_read(), photoName)
コード例 #22
0
def setup():
    global phaseChk
    pi.set_mode(17, pigpio.OUTPUT)
    pi.set_mode(22, pigpio.OUTPUT)
    pi.write(22, 1)  #IM920	Turn On
    pi.write(17, 0)  #Outcasing Turn Off
    time.sleep(1)
    BME280.bme280_setup()
    BME280.bme280_calib_param()
    BMX055.bmx055_setup()
    GPS.openGPS()

    with open(phaseLog, 'a') as f:
        pass

    #if it is End to End Test, then
    phaseChk = int(Other.phaseCheck(phaseLog))
    #if it is debug
    phaseChk = 8
コード例 #23
0
def getSensor():
    # ESP8266 - Pin assignment
    i2c = I2C(scl=Pin(5), sda=Pin(4), freq=10000)

    bme = BME280.BME280(i2c=i2c)
    return {
        'temperature': bme.temperature,
        'humidity': bme.humidity,
        'pressure': bme.pressure
    }
コード例 #24
0
def initSensor():
    i2c = machine.I2C(sda=machine.Pin(5), scl=machine.Pin(4))
    i2cDevices = i2c.scan()
    if len(i2cDevices) > 0:
        bme = BME280.BME280(i2c=i2c, address=118)
        print(bme.temperature)
        return bme
    else:
        print('No BME280 device found')
        return None
コード例 #25
0
 def __init__(self, offset=0.0, gain=1.0):
     # I2C
     self.si1132 = SI1132.SI1132(self.Device)
     self.bme280 = BME280.BME280(self.Device, 0x03, 0x02, 0x02, 0x02)
     #Thread
     self.Continue = 1
     #corregions
     self.Offset = float(offset)
     self.Gain = float(gain)
     Thread.__init__(self)
コード例 #26
0
def transmitPhoto():
    global t_start
    photoName = Capture.Capture(photopath)
    Other.saveLog(captureLog,
                  time.time() - t_start, GPS.readGPS(), BME280.bme280_read(),
                  photoName)
    print("Send Photo")
    sendPhoto.sendPhoto(photoName)
    print("Send Photo Finished")
    Other.saveLog(sendPhotoLog,
                  time.time() - t_start, GPS.readGPS(), photoName)
コード例 #27
0
def initBME280():
    global bme
    try:
        #i2c = machine.I2C(sda = machine.Pin(21),scl = machine.Pin(22)) # configuramos el acceso al bus i2c
        i2c = machine.I2C(
            sda=machine.Pin(config.pin_SDA), scl=machine.Pin(
                config.pin_SDL))  # configuramos el acceso al bus i2c
        # myLog(i2c.scan()) # Comprobamos que se detecta el dispositivo en la direccion 0x76 (118)
        bme = BME280.BME280(i2c=i2c, address=config.BME280_ADDRESS)
        myLog('BME280 found @ ' + str(config.BME280_ADDRESS), saveToFile=True)
    except Exception as e:
        myLog('BME280 not found: ' + str(e), saveToFile=True)
        bme = None
コード例 #28
0
def measure(res = [0, 0, 0, 0, 0, '']):
    try:
        res[3] = adc_read(lvlpin)
        res[4] = adc_read(lvlspin)
        res[5] = 'Low power.' if res[3] < LVL_LOWPWR else ''
        i2c = machine.SoftI2C(scl=machine.Pin(I2CSCL_PIN), sda=machine.Pin(I2CSDA_PIN), freq=I2C_FREQ)
        bme = BME280.BME280(i2c=i2c)
        res = (bme.temperature, bme.humidity, bme.pressure, res[3], res[4], res[5])
        print("Measuring: %s" % str(res))
    except Exception as e:
        res[5]= res[5] + " Measuring Error."
        print("Measurin Error: %s" % str(e))
    return res
コード例 #29
0
def setup():
	global phaseChk
	global startPosStatus
	pi.set_mode(17,pigpio.OUTPUT)
	pi.set_mode(22,pigpio.OUTPUT)
	pi.write(22,1)					#IM920	Turn On
	IM920.Strt("2")					#distance mode
	pi.write(17,0)					#Outcasing Turn Off
	time.sleep(1)
	BME280.bme280_setup()
	BME280.bme280_calib_param()
	BMX055.bmx055_setup()
	TSL2561.tsl2561_setup()
	GPS.openGPS()

	with open(phaseLog, 'a') as f:
		pass

	#if it is End to End Test, then
	try:
		phaseChk = int(Other.phaseCheck(phaseLog))
	except:
		phaseChk = 0
	#if it is debug
	#phaseChk = 8

	if phaseChk == 0:
		Other.saveLog(positionLog, "Goal", gLat, gLon, "\t")
		startPosStatus = 1
	else:
		Other.saveLog(positionLog, "\t")
		if(Other.positionCheck(positionLog) == [0.0, 0.0]):
			print("Not Logged Start Position")
			startPosStatus = 1
		else:
			rsLat, rsLon = Other.positionCheck(positionLog)
			print(rsLat, rsLon)
			startPosStatus = 0
コード例 #30
0
ファイル: sensors.py プロジェクト: alexbzg/lenfer-device-back
 def read(self):
     "reads sensors data and stores in into controller data field"
     humid, temp = None, None
     try:
         import BME280
         bme = BME280.BME280(i2c=self._i2c)
         temp = round((bme.read_temperature() / 100), 1)
         humid = int(bme.read_humidity() // 1024)
     except Exception as exc:
         pass
         #LOG.exc(exc, 'BME280 error')
     finally:
         self._controller.data[self._sensors_ids[0]] = temp
         self._controller.data[self._sensors_ids[1]] = humid