Exemplo n.º 1
0
 def test_mode(self):
     mockbus = setup_mockbus(initial_read={0x76: calibration_read()})
     bme = bme280.Bme280()
     self.assertEqual(bme.get_mode(), bme280.MODE_SLEEP)
     bme.set_mode(bme280.MODE_FORCED)
     self.assertEqual(bme.get_mode(), bme280.MODE_FORCED)
     self.assertMatchSnapshot(mockbus._log)
Exemplo n.º 2
0
 def test_data(self):
     mockbus = setup_mockbus(
         initial_read={0x76: calibration_read() + [0x00] * 8})
     bme = bme280.Bme280()
     bme.set_mode(bme280.MODE_FORCED)
     t, p, h = bme.get_data()
     # self.assertEqual(t, 0x00)
     self.assertMatchSnapshot(mockbus._log)
Exemplo n.º 3
0
 def test_status(self):
     mockbus = setup_mockbus(
         initial_read={0x76: calibration_read() + [0x08, 0x00, 0x01, 0x00]})
     bme = bme280.Bme280()
     self.assertTrue(bme.is_status_measuring())
     self.assertFalse(bme.is_status_measuring())
     self.assertTrue(bme.is_status_image_register_updating())
     self.assertFalse(bme.is_status_image_register_updating())
     self.assertMatchSnapshot(mockbus._log)
Exemplo n.º 4
0
 def test_config(self):
     mockbus = setup_mockbus(initial_read={0x76: calibration_read()})
     bme = bme280.Bme280()
     self.assertEqual(bme.get_tstandy(), bme280.TSTANDBY_1000)
     bme.set_tstandy(bme280.TSTANDBY_20)
     self.assertEqual(bme.get_tstandy(), bme280.TSTANDBY_20)
     self.assertEqual(bme.get_filter(), bme280.FILTER_OFF)
     bme.set_filter(bme280.FILTER_16)
     self.assertEqual(bme.get_filter(), bme280.FILTER_16)
     self.assertMatchSnapshot(mockbus._log)
Exemplo n.º 5
0
    def __init__(self, t_offset, p_offset, h_offset):

        print("IOThermostat: Starting Sensors module..")
        self.T_OFFSET = t_offset
        self.P_OFFSET = p_offset
        self.H_OFFSET = h_offset

        self.sensor = bme280.Bme280()
        self.sensor.set_mode(bme280.MODE_NORMAL)

        print("IOThermostat: Sensors module active.")
Exemplo n.º 6
0
def get_data_for_gsheet():
    """get_data_for_gsheet method:
        reads data from bme280 and prepares a dictionary for writing to gsheet
    """
    bme = bme280.Bme280()
    bme.set_mode(bme280.MODE_FORCED)
    temperature, pressure, humidity = bme.get_data()
    pressure = pressure / 100.
    time = datetime_string()
    values = [[time, temperature, pressure, humidity]]
    body = {'values': values}
    return body
Exemplo n.º 7
0
 def test_oversampling(self):
     mockbus = setup_mockbus(initial_read={0x76: calibration_read()})
     bme = bme280.Bme280()
     self.assertEqual(bme.get_humidity_oversampling(), bme280.HO_1)
     bme.set_humidity_oversampling(bme280.HO_16)
     self.assertEqual(bme.get_humidity_oversampling(), bme280.HO_16)
     self.assertEqual(bme.get_temperature_oversampling(), bme280.TO_1)
     bme.set_temperature_oversampling(bme280.TO_16)
     self.assertEqual(bme.get_temperature_oversampling(), bme280.TO_16)
     self.assertEqual(bme.get_pressure_oversampling(), bme280.PO_1)
     bme.set_pressure_oversampling(bme280.PO_16)
     self.assertEqual(bme.get_pressure_oversampling(), bme280.PO_16)
     self.assertMatchSnapshot(mockbus._log)
Exemplo n.º 8
0
def talker():
    pub = rospy.Publisher('/mavros/sensor', String, queue_size=10)
    rospy.init_node('talker', anonymous=True)
    rate = rospy.Rate(10)  # 10hz
    while not rospy.is_shutdown():
        bme = bme280.Bme280()
        bme.set_mode(bme280.MODE_FORCED)
        t, p, h = bme.get_data()
        hello_str = str(t).replace(".", ",") + ";" + str(p).replace(
            ".", ",") + ";" + str(h).replace(".", ",")
        rospy.loginfo(hello_str)
        pub.publish(hello_str)
        rate.sleep()
Exemplo n.º 9
0
    def __init__(self):
        self.bme280 = bme280.Bme280(1)

        self.tt_in = 0
        self.setback = 0
        self.forecast_day = 0
        self.latest_weather = None
        self.stemp = False
        self.spressure = 0
        self.shumidity = 0
        self.blinker = True
        self.displayed_time_last_refresh = 0
        self.blinker_last_refresh = 0
        self.run = True
        self.toggledisplay = True
        self.refetch = True
        self.htrstatus = HeaterState.OFF

        # Defaults
        self.setpoint = 20  # in celsius
        self.sensortimeout = 300
        self.heartbeatinterval = 30
        self.temp_tolerance = 1.8
        self.refreshrate = 0.1  # in seconds
        self.target_temp = self.setpoint

        # 0 Heater status
        # 1 Time
        # 2 Setpoint
        # 3 Sensor data
        # 4 Weather data
        self.drawlist = [True, True, True, True, True]

        self.configfile = None

        self.serial = None
        self.lhs = [None, None, None]
Exemplo n.º 10
0
    # 1ヶ月のデータログ
    if month == next_month:
        print "LOG DATA SAVE during Month("+str(year)+"_"+str(month)+"_date_log.csv)"
        dld.to_csv("./"+str(year)+"_"+str(month)+"_date_log.csv", index=False)
        gyo_d = 0
        dld = initialize_dld()
        next_month += 1
        if next_month == 13:
            next_month = 1
        """
    # 1分毎のデータログ
    if sec == 10:
        # 水温の取得
        wtemp = DS18B20.main()
        # 室温、湿度、気圧の取得
        temp, humid, press = bme.Bme280(0x76, 1).get_data()
        # 臭気の取得
        gas = gas_detect(PIN_BASE, SPI_CH)
        if 60 > gas:
            gas_state = "良好"
        elif 150 > gas >= 60:
            gas_state = "そろそろ水換え"
        else:
            gas_state = "要水換え"

        # 基準値
        GOOD = 60
        BAD = 150
        # 良好
        if GOOD >= gas:
            GPIO.output(GPIO_list[0], GPIO.HIGH)
Exemplo n.º 11
0
        
        ISOstring = ISO10368Lib.containerString(Startcool, tempContainer, StartPeakshaving, Testcounter, manual, ControlManual)
        #else:

        if (Testcounter == 47 and dag == 4):
            print("Demoen er s**t")
            time.sleep(1)
            sys.exit()

        ourCounter = 0
        if(tempEnable == 1):
            print("test")

        

        bme76 = bme280.Bme280(i2c_bus=1,sensor_address=0x76)
        bme76.set_mode(bme280.MODE_FORCED)
        t1, p1, h1 = bme76.get_data()

        bme77 = bme280.Bme280(i2c_bus=1,sensor_address=0x77)
        bme77.set_mode(bme280.MODE_FORCED)
        t2, p2, h2 = bme77.get_data()
        #print(round(t1,2))
        #print(round(t2,2))
        
        clientOwn.publish("/container"+RCDid+"/tempInside", round(t1,2), qos=0, retain=False)
        clientOwn.publish("/container"+RCDid+"/tempOutside", round(t2-20,2), qos=0, retain=False)
        clientOwn.publish("/container"+RCDid+"/bitString", ISOstring, qos=0, retain=False)

        
        clientOwn.publish("/container"+RCDid+"/effektTotal", Effekttotal, qos=0, retain=False)
Exemplo n.º 12
0
 def test_reset(self):
     mockbus = setup_mockbus(initial_read={0x76: calibration_read()})
     bme = bme280.Bme280()
     bme.reset()
     self.assertMatchSnapshot(mockbus._log)
Exemplo n.º 13
0
 def test_chip_id(self):
     mockbus = setup_mockbus(
         initial_read={0x76: calibration_read() + [0x23]})
     bme = bme280.Bme280()
     self.assertEqual(bme.get_chip_id(), 0x23)
     self.assertMatchSnapshot(mockbus._log)
Exemplo n.º 14
0
 def test_setup(self):
     mockbus = setup_mockbus(initial_read={0x76: calibration_read()})
     bme = bme280.Bme280()
     MOCKED_SMBUS_MODULE.SMBus.assert_called_with(1)
     self.assertIsNotNone(bme)
     self.assertMatchSnapshot(mockbus._log)
Exemplo n.º 15
0
#!/usr/bin/env python
# -*- coding: UTF-8 -*-

import bme280

if __name__ == '__main__':
    bme = bme280.Bme280()
    bme.set_mode(bme280.MODE_FORCED)
    t, p, h = bme.get_data()
    print "Temperature: %f °C" % t
    print "Pressure: %f P" % p
    print "Humidity: %f %%" % h