def __init__(self, state): led = None if reset_cause() == DEEPSLEEP_RESET else StatusLED(config.LED) wifi.connect(secrets.WIFI_NAME, secrets.WIFI_PASSWORD, led=led) if wifi.is_connected(): print(wifi.mac(), wifi.ip(), wifi.rssi()) mqtt = MQTT(config.NAME, secrets, uid = UID, led=led) opt = dict(exp_aft = config.FREQ * 2.5) mqtt.add('Temp', Temperature, **opt).set_state(state['temp']) mqtt.add('Humid', Humidity, **opt).set_state(state['humid']) mqtt.set_attr("freq", config.FREQ) mqtt.do_pub_cfg = reset_cause() != DEEPSLEEP_RESET or ticks_us() % 10 == 0 mqtt.connect() sleep(1) mqtt.pub_state() sleep(5) mqtt.discon() sleep(5)
def set_wifi_attr(self): self.set_attr("ip", wifi.ip()) self.set_attr("mac", self.mac) self.set_attr("rssi", wifi.rssi())
sost = 2 import driver driver.step(-1, 3400, 600, 12, 13, 4, 5) sost = 0 while True: try: sensor.measure() # Poll sensor t = sensor.temperature() h = sensor.humidity() if isinstance(t, float) and isinstance( h, float): # Confirm sensor results are numeric msg = (b'{0:3.1f},{1:3.1f}'.format(t, h)) print(msg) url = 'http://192.168.88.100/objects/?script=espdata&mac=' + wifi.mac( ) + '&ip=' + wifi.ip() + '&h=' + str(h) + '&t=' + str(t) import http tmust = http.get(url) print(tmust) print(sost) if (float(tmust) < t) and (sost != 0): driver.step(-1, 3400, 600, 12, 13, 4, 5) sost = 0 if (float(tmust) > t) and (sost != 1): driver.step(1, 3400, 600, 12, 13, 4, 5) sost = 1 else: print('Invalid sensor readings.') except OSError: print('Failed to read sensor.')