Ejemplo n.º 1
0
	def __init__(self, event_handler, kill_event, sensor_period, data_cycles, query_base, user_config):
		# Set event handler
		self._ehandler = event_handler
		self._sensor_period = sensor_period
		self._data_cycles = data_cycles
		self._setpoint = 0.0	# Dummy value for startup
		self._setpoint_str = ''
		self._outdoor_temp_str = ''
		self._indoor_temp_str = ''
		self._override_on = False
		self._override_temp = 15.0  # Dummy to set the indicator at the bottom of the scale
		self._qbase = query_base
		self._thermo_on = False  # Set so first call to _set_thermo_status turns on the thermostat
		self._relay_on = True  # Set so first call to _set_relay_status turns off the relay
		self._user_config = user_config

		# Initialize logger
		self._logger = logging.getLogger('MAIN.THERMO')

		# Initialize the gpio
		self._gpio_bus = pigpio.pi()
#		self._gpio_bus.set_mode(THERMO_POWER_PIN, pigpio.OUTPUT)
		self._gpio_bus.set_mode(RELAY_POWER_PIN, pigpio.OUTPUT)
#		self._gpio_bus.set_mode(RELAY_STATUS_PIN, pigpio.OUTPUT)
#		self._gpio_bus.set_mode(POWER_SWITCH_PIN, pigpio.INPUT)

		# Initialize Sensors
#		self._lux_sensor = TSL2561(1)
		self._temp_sensor = HTU21D(1)

		# Initialize as a thread
		self._kill_event = kill_event
		threading.Thread.__init__(self)
Ejemplo n.º 2
0
class Sensor:
    htu = HTU21D(i2c=MY_I2C)
    temp = 0
    humidity = 0

    @classmethod
    def update(self):
        while True:
            self.temp = self.htu.temperature()
            self.humidity = self.htu.humidity()
            sleep_ms(10000)
Ejemplo n.º 3
0
def main():
    # start Power LED
    sensor = HTU21D()
    temp = sensor.get_temp()
    hum = sensor.get_hum()
    print('Temp: %s°C / Hum: %s%%' % (temp, hum))
    adcValue = IOConfig.__adcPin.read()
    print('adcValue: %s' % adcValue)
    networkConfig.mqtt_subscribe("1", "temp", "c", sensor.get_temp())
    networkConfig.mqtt_subscribe("2", "rel_hum", "p", sensor.get_hum())
    networkConfig.mqtt_subscribe("3", "analog_sensor", "null", adcValue)
    # ws = WebSocket()
    # ws.set_html()
    IOConfig.setPowerLED(__ledOn)
    switchState = IOConfig.__sleepSwitch.value()
    if switchState == 1:
        time.sleep(0.5)
        machine.deepsleep()
    else:
        pass
Ejemplo n.º 4
0
    def set_html(self):

        # TODO add in while loop! for live tracking
        while True:
            sensor = HTU21D()
            temp = sensor.get_temp()
            hum = sensor.get_hum()
            adcValue = IOConfig.__adcPin.read()
            html = "<!DOCTYPE html>" \
                   "<html><head>\
                    <title>Welcome</title>\
                        </head><body> <h1>ESP8266 Settings</h1>\
                            <p>Temp:"                                      + str(temp) + "C</p>\
                            <p>Hum:"                                     + str(hum) + "%</p>\
                            <p>ADCValue:"                                          + str(adcValue) + "</p>\
                    </body></html>"

            cl, addr = self.s.accept()
            print('client connected from', self.addr)
            cl.send(html)
            cl.close()
Ejemplo n.º 5
0
import pycom
import time
import gc
import socket
from network import LoRa
import ubinascii
import json
from htu21d import HTU21D
from ms5611 import MS5611

#init sensor
ms = MS5611()
htu = HTU21D()

# delay time
delay = 1

# Colors used for status LED
RGB_OFF = 0x000000
RGB_POS_UPDATE = 0x101000
RGB_POS_FOUND = 0x001000
RGB_POS_NFOUND = 0x100000
RGB_LORA = 0x000010
LED_TIMEOUT = 0.2
pycom.heartbeat(False)

# Set up the LoRa in longer range mode

lora = LoRa(mode=LoRa.LORA, region=LoRa.AS923)
s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
s.setblocking(False)
# main.py -- put your code here!
from network import LoRa
import socket
import ubinascii
import struct
import time
import os
import math
import abpkeys
import pycom
import ustruct
from machine import UART, I2C, Pin
from htu21d import HTU21D
from MPL3115A2 import MPL3115A2, ALTITUDE, PRESSURE
import TSL2561
sensor = HTU21D()
#from machine import I2C, Pin #added for si7021 rh sensor
#f = open('/flash/test.py', 'a') #create file (append mode)
#f.write("Start\n")
#f.close()
#from si7021 import SI7021 #added for si7021 rh sensor

uart = UART(1, 9600)  # init with given baudrate
uart.init(9600, bits=8, parity=None, stop=1)  # init with given parameters

#initialize i2c to link to rh sensor
i2c = I2C(0, pins=("P9", "P10"))
i2c.init(I2C.MASTER, baudrate=100000)
#tsl = adafruit_tsl2561.TSL2561(i2c)
sensor = HTU21D()
Ejemplo n.º 7
0
from htu21d import HTU21D
import utime

htu21d = HTU21D()

# do not forget to initialize
htu21d.init()

# set resolution
htu21d.set_resolution(htu21d.UserRegister.USER_REGISTER_RESOLUTION_RH12_TEMP14)

if not htu21d.heater_enabled:
    htu21d.toggle_heater()

print("Heater enabled: %r" % htu21d.heater_enabled)

while True:
    print("Temperature in Celsius: %.2f °C" %
          htu21d.read_temp(htu21d.Mode.NO_HOLD, htu21d.UNIT.Celsius))
    print("Temperature in Fahrenheit: %.2f °F" %
          htu21d.read_temp(htu21d.Mode.NO_HOLD, htu21d.UNIT.Fahrenheit))
    print("Humidity: %.2f %%" % htu21d.read_humidity(htu21d.Mode.NO_HOLD))
    utime.sleep(1)
Ejemplo n.º 8
0
from htu21d import HTU21D
from ssd1306 import SSD1306_I2C
from machine import I2C, Pin
import time

i2c = I2C(scl=Pin(14), sda=Pin(2), freq=100000)
h = HTU21D()
s = SSD1306_I2C(126, 64, i2c)

s.init_display()

while True:
    temp = 'Temp:' + str(h.read_temperature())
    hum = 'Humi:' + str(h.read_humidity())
    print(temp, hum)
    s.fill(0)
    s.text(temp, 20, 20)
    s.text(hum, 20, 40, 4)
    s.show()
    time.sleep(1)
class PiWeatherShield:
	htu21d = HTU21D(1)
	ms5637 = MS5637(1)
	tsys01 = TSYS01(1)
	tsd305 = TSD305(1)