Last active
June 3, 2018 13:27
-
-
Save halmartin/f3a61922ea85337a2c8db17d7abf8e2a to your computer and use it in GitHub Desktop.
MicroPython for Wemos D1 mini to read temperature/humidity and report to InfluxDB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urequests | |
from time import sleep | |
from machine import Pin, reset | |
p2 = Pin(2, Pin.OUT) | |
HOST="wemos-5a0385" | |
LENGTH=60 | |
def TempSensReport(): | |
from sht30 import SHT30 | |
sensor = SHT30() | |
url = "http://orangepipc:8086/write?db=wemos_d1" | |
for i in range(0,LENGTH+1): | |
print('Reboot in %d minutes' % (LENGTH-i)) | |
# turn on the WeMOS LED | |
p2.off() | |
# measure values | |
temperature, humidity = sensor.measure() | |
temp = "temp_C,host=%s value=%.02f" % (HOST,temperature) | |
hum = "rel_humidity,host=%s value=%.02f" % (HOST,humidity) | |
# send to InfluxDB API | |
urequests.post(url,data=temp) | |
urequests.post(url,data=hum) | |
# print on uart for warm fuzzy feeling | |
print('Temperature:', temperature, ' C, RH:', humidity, '%') | |
# turn off LED | |
p2.on() | |
sleep(LENGTH) | |
# reboot every range*LENGTH | |
reset() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Line 15 says # turn on the WeMOS LED
Line 16 says p2.off()
Line 26 says # turn off LED
Line 27 says p2.on()
Shouldn't the command lines agree with their respective comments?