Change MQTT broker for personal one
This commit is contained in:
parent
72e9c256bf
commit
83523d9e44
33
code/main.py
33
code/main.py
@ -11,6 +11,7 @@ import config
|
||||
|
||||
# connect to WLAN
|
||||
wlan = network.WLAN(network.STA_IF)
|
||||
wlan.active(True)
|
||||
nets = wlan.scan()
|
||||
for net in nets:
|
||||
net_ssid = net[0].decode()
|
||||
@ -18,7 +19,7 @@ for net in nets:
|
||||
print('Network found!')
|
||||
wlan.connect(net_ssid, config.WIFI_PSK)
|
||||
while not wlan.isconnected():
|
||||
machine.idle() # save power while waiting
|
||||
machine.idle() # save power while waiting
|
||||
print('WLAN connection succeeded!')
|
||||
break
|
||||
if not wlan.isconnected():
|
||||
@ -43,19 +44,27 @@ bme.set_measurement_settings({
|
||||
bme.set_power_mode(bme280_i2c.BME280_NORMAL_MODE)
|
||||
|
||||
|
||||
client = MQTTClient(client_id="int_weather_station",
|
||||
server="io.adafruit.com",
|
||||
user=config.ADAFRUIT_IO_USERNAME,
|
||||
password=config.ADAFRUIT_IO_KEY,
|
||||
port=1883)
|
||||
client = MQTTClient(client_id=config.CLIENT_ID,
|
||||
server=config.MQTT_HOST,
|
||||
user=config.MQTT_USERNAME,
|
||||
password=config.MQTT_PASSWD,
|
||||
port=config.MQTT_PORT)
|
||||
client.connect()
|
||||
|
||||
client.publish("test/bme280/humidity/unit", "%", retain=True, qos=0)
|
||||
time.sleep_ms(100)
|
||||
client.publish("test/bme280/pressure/unit", "hPa", retain=True, qos=0)
|
||||
time.sleep_ms(100)
|
||||
client.publish("test/bme280/temperature/unit", "oC", retain=True, qos=0)
|
||||
time.sleep_ms(1000)
|
||||
|
||||
while 1:
|
||||
bme_data = bme.get_measurement()
|
||||
print(bme_data)
|
||||
client.publish("{}/feeds/weather.interior-hum".format(config.ADAFRUIT_IO_USERNAME), "{:.0f}".format(bme_data["humidity"]))
|
||||
time.sleep_ms(2000)
|
||||
client.publish("{}/feeds/weather.interior-press".format(config.ADAFRUIT_IO_USERNAME), "{:.2f}".format(bme_data["pressure"]/100))
|
||||
time.sleep_ms(2000)
|
||||
client.publish("{}/feeds/weather.interior-temp2".format(config.ADAFRUIT_IO_USERNAME), "{:.1f}".format(bme_data["temperature"]))
|
||||
time.sleep_ms(16000)
|
||||
client.publish("test/bme280/humidity/value",
|
||||
"{:.0f}".format(bme_data["humidity"]))
|
||||
client.publish("test/bme280/pressure/value",
|
||||
"{:.2f}".format(bme_data["pressure"]/100))
|
||||
client.publish("test/bme280/temperature/value",
|
||||
"{:.1f}".format(bme_data["temperature"]))
|
||||
time.sleep_ms(1000)
|
||||
|
Loading…
Reference in New Issue
Block a user