Example #1
0
 def init_light(self):
     self.gpio_mutex.acquire()
     # TODO: Mutex Error
     try:
         self.lightSensor = si1145.SI1145()
         time.sleep(0.25)
     except OSError:
         raise ErrorHandling.IRConnectionError
     finally:
         self.gpio_mutex.release()
Example #2
0
    def __init__(self, ssid, password, mqtt_host, mqtt_root_topic, pin_soil_power, pin_pump, pin_scl, pin_sda, i2c_addr_bme280, event_periods, debug):
        """Setup the application"""
        self._events = []

        self.should_bail = False
        self.debug = debug
        self.event_periods = event_periods

        # ensure network is up
        do_network_connect(ssid, password)

        # configure mqtt client
        self.mqtt_root_topic = mqtt_root_topic
        self.mqtt_client = MQTTClient("umqtt_client", mqtt_host)
        self.mqtt_client.set_callback(self.mqtt_recieve)
        self.mqtt_client.connect()

        # configure output pins
        self.pin_soil_power = machine.Pin(pin_soil_power, machine.Pin.OUT)
        self.pin_pump = machine.Pin(pin_pump, machine.Pin.OUT)

        # set up i2c bus and sensors
        self.i2c = machine.I2C(scl=machine.Pin(pin_scl), sda=machine.Pin(pin_sda))
        self.sensor_bme280 = bme280.BME280(i2c=self.i2c, address=i2c_addr_bme280)    
        self.sensor_si1145 = si1145.SI1145(i2c=self.i2c)      
        self.sensor_adc = ads1x15.ADS1015(self.i2c)                                                                                                 

        # topic to trigger event loop end
        self.mqtt_client.subscribe(self.mqtt_make_topic("halt"))
        self.mqtt_client.subscribe(self.mqtt_make_topic("water_plant"))

        # fire off initial events. These are self submitting so each one
        # will submit the next job to the event queue.
        self.event_update_ntp(utime.time())
        current_time = utime.time()
        self.event_temperature(current_time)
        self.event_light(current_time)
        self.event_soil_moisture(current_time)
        self.schedule_pump_on(current_time)
Example #3
0
    X = -1
    start = time.time()
    while X != 0:
        time.sleep(0.5)
        try:
            # Attempt to connect to the MQTT Broker
            X = client.connect(broker, port=port)
        except:
            print("RED LED on")
            GPIO.write(FAIL_LED, 1)
            time.sleep(2)
            GPIO.write(FAIL_LED, 0)
            print(X)

    # Sensor initialisation
    lightSensor = si1145.SI1145()
    agSensor = AccGyro(debug=True)
    agSensor.setRange(AccGyro.RANGE_2G)
    time.sleep(1)

    # Get range of data values for all sensors
    max_array, min_array, med_array = sensor_calibration()
    print("Parameters for calibration extracted.")

    if X == 0:
        client.loop_start()
        while True:
            ir = ir_weight * 1.47 * log(lightSensor.readIR())
            max_array[0], min_array[0], update_med = min_max_test(ir,
                                                                  max_array[0],
                                                                  min_array[0])
Example #4
0

atexit.register(cleanup)

GPIO.cleanup()  # just in case?
GPIO.setmode(GPIO.BCM)  # global for the app

LOCATION = os.path.dirname(os.path.abspath(__file__))
#logging.basicConfig(level=logging.DEBUG,filename='mdm-2.log', format='%(process)d-%(levelname)s-%(message)s')

#logger = logging.getLogger()
logging.info('Starting Flight Computer')

tracker = telemetry
radio = loraRadio
uv = si1145.SI1145()

values = [0] * 28
headers = [0] * 28
headers = [
    "time", "temp", "humidity", "pressure", "pressure alt", "vert speed",
    "pitch", "roll", "yaw", "compass", "lat", "lon", "gps alt", "gps speed",
    "gps climb", "gps track", "gps time", "maxAltGps", "maxAltPressure",
    "HDOP", "VDOP", "LastFix", "Mode", "Message", "voltage", "current",
    "uvindex", "uv"
]
csvLog.writeCsvLog(headers)

LogFreqSeconds = 10
radio.DefaultReceive = True
lastMessageCode = 250
Example #5
0
    EN_DS18B20 = False

if debug:
    print("BMP180 : ", EN_BMP180, "\nSI1145 : ", EN_SI1145, "\nSCD30 : ",
          EN_SCD30, "\nDB18b20 : ", EN_DS18B20, "\n")
# TODO : test if sensor connected before handling it
if EN_SCD30:
    scd30 = SCD30()
    scd30.set_measurement_interval(5)
    scd30.start_periodic_measurement()
if EN_BMP180:
    BMP180 = bmp085.BMP085()
if EN_DS18B20:
    temp_probe = ds18b20_therm.DS18B20()
if EN_SI1145:
    uv_sensor = si1145.SI1145()

# Append the data in the sqlite-database, including a timestamp
try:
    if EN_SI1145:
        uv_index = float(uv_sensor.readUVIndex()) / 100
        ambient_light = uv_sensor.readAmbientLight()
        IR_light = uv_sensor.readIRLight()
    if EN_DS18B20:
        temp_DS18B20 = temp_probe.read_temp()
    if EN_BMP180:
        temp_BMP180 = BMP180.get_temperature()
        pressure_BMP180 = BMP180.get_pressure()
    if EN_SCD30:
        t = 0
        gdr = scd30.get_data_ready()
Example #6
0
import machine
import si1145
import time
i2c = machine.I2C(sda=machine.Pin(4), scl=machine.Pin(5))
sensor = si1145.SI1145(i2c=i2c)
for i in range(10):
    uv = sensor.read_uv
    ir = sensor.read_ir
    view = sensor.read_visible
    print(" UV: %f\n IR: %f\n Visible: %f" % (uv, ir, view))
    time.sleep(1)
Example #7
0
import time
import si1145 as SI1145

sensor = SI1145.SI1145()

print('Press Ctrl-Z to cancel')

while True:
    vis = sensor.readVisible()
    IR = sensor.readIR()
    UV = sensor.readUV()
    uvIndex = UV / 100.0
    print('Vis:             ' + str(vis))
    print('IR:              ' + str(IR))
    print('UV Index:        ' + str(uvIndex))
    print('--------')

    time.sleep(0.1)