コード例 #1
0
 def test_get_refresh_time(self):
     mockbus = setup_mockbus()  # pylint: disable=unused-variable
     veml = veml6070.Veml6070(rset=veml6070.RSET_240K)
     self.assertEqual(veml.get_refresh_time(), 0.1)
     veml.set_integration_time(veml6070.INTEGRATIONTIME_1_2T)
     self.assertEqual(veml.get_refresh_time(), 0.05)
     veml2 = veml6070.Veml6070(rset=veml6070.RSET_270K)
     self.assertEqual(veml2.get_refresh_time(), 0.1125)
     veml3 = veml6070.Veml6070(rset=veml6070.RSET_600K)
     veml3.set_integration_time(veml6070.INTEGRATIONTIME_2T)
     self.assertEqual(veml3.get_refresh_time(), 0.5)
     veml4 = veml6070.Veml6070(rset=480000)
     self.assertEqual(veml4.get_refresh_time(), 0.2)
コード例 #2
0
 def test_integration_time(self):
     mockbus = setup_mockbus()
     veml = veml6070.Veml6070(integration_time=veml6070.INTEGRATIONTIME_1_2T)
     self.assertEqual(veml.get_integration_time(), veml6070.INTEGRATIONTIME_1_2T)
     veml.set_integration_time(veml6070.INTEGRATIONTIME_4T)
     self.assertEqual(veml.get_integration_time(), veml6070.INTEGRATIONTIME_4T)
     self.assertMatchSnapshot(mockbus._log)
コード例 #3
0
 def test_uva_light_intensity_raw(self):
     mockbus = setup_mockbus(initial_read={
         0x38+1: [0x12],
         0x38+0: [0x34]
     })
     veml = veml6070.Veml6070()
     self.assertEqual(veml.get_uva_light_intensity_raw(), 0x1234)
     self.assertMatchSnapshot(mockbus._log)
コード例 #4
0
 def test_uva_light_intensity(self):
     mockbus = setup_mockbus(initial_read={
         0x38+1: [0x01, 0x01],
         0x38+0: [0x06, 0x06]
     })
     veml = veml6070.Veml6070()
     self.assertEqual(veml.get_uva_light_intensity(), 0x0106 * 0.05625 / 1)
     veml.set_integration_time(veml6070.INTEGRATIONTIME_4T)
     self.assertEqual(veml.get_uva_light_intensity(), 0x0106 * 0.05625 / 4)
     self.assertMatchSnapshot(mockbus._log)
コード例 #5
0
 def test_get_estimated_risk_level(self):
     mockbus = setup_mockbus(initial_read={
         0x38 + 1: [0x01, 0x04],
         0x38 + 0: [0x06, 0x01]
     })  # pylint: disable=unused-variable
     veml = veml6070.Veml6070()
     intensity = veml.get_uva_light_intensity()
     self.assertEqual(veml.get_estimated_risk_level(intensity), "low")
     intensity = veml.get_uva_light_intensity()
     self.assertEqual(veml.get_estimated_risk_level(intensity), "moderate")
コード例 #6
0
def loop():

    while True:
        veml = veml6070.Veml6070()
        uv_raw = veml.get_uva_light_intensity_raw()
        uv = veml.get_uva_light_intensity()
        print("UVA Light value : %f W/(m*m) from raw value %d" % (uv, uv_raw))

        temperature, pressure, humidity = bme280.readBME280All()

        print("Temperature : ", temperature, "C")
        print("Pressure : ", pressure, "hPa")
        print("Humidity : ", humidity, "%")

        (light_ch0, light_ch1) = tsl2561.readValues()
        print("Full Spectrum(IR + Visible) :%d lux" % light_ch0)
        print("Infrared Value :%d lux" % light_ch1)
        print("Visible Value :%d lux" % (light_ch0 - light_ch1))
        sendMessage(temperature)
        time.sleep(10)
コード例 #7
0
#!/usr/bin/env python
from datetime import datetime
import veml6070
import paho.mqtt.client as mqtt

ALL_INTEGRATION_TIMES = [
    veml6070.INTEGRATIONTIME_1_2T, veml6070.INTEGRATIONTIME_1T,
    veml6070.INTEGRATIONTIME_2T, veml6070.INTEGRATIONTIME_4T
]

mqtt_client = mqtt.Client()
mqtt_client.connect("fluent-bit", 1883, 60)

veml = veml6070.Veml6070()
while True:
    for i in ALL_INTEGRATION_TIMES:
        veml.set_integration_time(i)
        uv_raw = veml.get_uva_light_intensity_raw()
        uv = veml.get_uva_light_intensity()

        tim = '"timestamp":"' + datetime.now().strftime(
            '%Y-%m-%d %H:%M:%S.%f') + '"'
        time_setting = '"' + "Time_setting" + '"' + ":" + '"' + str(
            uv_raw) + '"'
        uv = '"' + "UV[W/(m*m)]" + '"' + ":" + '"' + str(round(uv, 5)) + '"'
        mylist = [tim, time_setting, uv]
        mystr = '{' + ','.join(map(str, mylist)) + '}'
        print(mystr)
        mqtt_client.publish("{}/{}".format("/demo", 'person_count'), mystr)

mqtt_client.disconnect()
コード例 #8
0
 def test_disable(self):
     mockbus = setup_mockbus()
     veml = veml6070.Veml6070()
     veml.disable()
     self.assertMatchSnapshot(mockbus._log)
コード例 #9
0
 def test_setup(self):
     mockbus = setup_mockbus()
     veml = veml6070.Veml6070()
     MOCKED_SMBUS_MODULE.SMBus.assert_called_with(1)
     self.assertIsNotNone(veml)
     self.assertMatchSnapshot(mockbus._log)
コード例 #10
0
def main_loop():
    client = init_mqtt_client()
    bme = BME280(p_mode=BME280_OSAMPLE_8, t_mode=BME280_OSAMPLE_2, h_mode=BME280_OSAMPLE_1, filter=BME280_FILTER_16)
    veml = veml6070.Veml6070()
    veml.set_integration_time(veml6070.INTEGRATIONTIME_1T)

    # gpx file
    gpx, gpx_segment = new_gpx_file()

    data_list = []
    particles_mean = []

    start_time = datetime.datetime.now()
    data_published_time = datetime.datetime.now()

    i = 0

    fname = '/home/pi/meteo/tracks/raw_data' + datetime.datetime.now().strftime('-%m%d-%H%M')
    data_file = init_data_file(filename=fname)

    while True:
        i += 1

        get_sensor_data(sensor=bme, veml=veml)
        smooth_data(particles_mean)
        data_list.append(data)

        # Publish sensor data to MQTT server
        publish_sensor_data(client=client, sensor_data=data)
        print data
        write_to_csv(data_file)
        # Push data file to server @krasi
        call(["scp", "-P 2020", fname, "[email protected]:/home/chavdar/Programs/meteo-data/"])

        if not gps.gps_signal_lost:
            for gps_dat in gps.gps_dat_list:
                data.update(gps_dat)

                write_to_csv(data_file)

                # Push data file to server @krasi
                call(["scp", "-P 2020", fname, "[email protected]:/home/chavdar/Programs/meteo-data/"])

                # Publish on MQTT server
                update_interval = speed_based_interval(speed=gps_dat["speed"])

                # Post to external tracker
                data_published_time = post_external(data, data_published_time, update_interval)
                publish_gps_data(client=client, gps_data=gps_dat, point_number=i)

                # Create points in GPX file:
                point = gpxpy.gpx.GPXTrackPoint(data["latitude"],
                                                data["longitude"],
                                                elevation=data["altitude"],
                                                time=datetime.datetime.now())
                point.extensions = dict(data)
                gpx_segment.points.append(point)
            if (datetime.datetime.now() - start_time) > datetime.timedelta(minutes=10):
                start_time = datetime.datetime.now()
                fn = "/home/pi/meteo/tracks/track" + datetime.datetime.now().strftime("-%d%m-%H%M") + ".gpx"
                with open(fn, "w") as f:
                    print datetime.datetime.now().isoformat(), "GPX file printed! Filename: " + fn
                    f.write(gpx.to_xml(version="1.1"))
                gpx, gpx_segment = new_gpx_file()

            gps.clear_data()

        time.sleep(60)