Skip to content

Instantly share code, notes, and snippets.

@gmorell
Last active January 11, 2017 18:52
Show Gist options
  • Save gmorell/94c511ca4bff790974d82698c533a9d4 to your computer and use it in GitHub Desktop.
Save gmorell/94c511ca4bff790974d82698c533a9d4 to your computer and use it in GitHub Desktop.
plant.py
import network
sta_if = network.WLAN(network.STA_IF)
ap_if = network.WLAN(network.AP_IF)
if not sta_if.isconnected():
sta_if.active(True)
sta_if.connect('YYY', '')
ap_if.active(False)
while not sta_if.isconnected():
pass
import machine
adc = machine.ADC(0)
d_s = adc.read()
import dht
d = dht.DHT22(machine.Pin(13)) # 7 on the nodemcu
d.measure()
d_t = d.temperature() # eg. 23.6 (°C)
d_h = d.humidity()
import urequests
q = urequests.post("https://hole.thingcosm.us/h", json={"temp":d_t, "hum":d_h, "soil":d_s, "authentifier":"XXX"})
# now we rest
rtc = machine.RTC()
rtc.irq(trigger=rtc.ALARM0, wake=machine.DEEPSLEEP)
rtc.alarm(rtc.ALARM0, 30000)
machine.deepsleep()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment