Created
June 16, 2016 17:45
-
-
Save emilssolmanis/2854bcc90547b07b3900f1cb26c52620 to your computer and use it in GitHub Desktop.
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
function handle_request(code, data) | |
if code < 0 then | |
print("failed to post http") | |
do_it() | |
else | |
print("score, sleeping for 1 hour") | |
node.dsleep(4294967295, nil) | |
end | |
end | |
function read_value() | |
hx711.init(6, 7) | |
return hx711.read() | |
end | |
function post_value(value) | |
http.post( | |
"https://api.thingspeak.com/update.json", | |
"", | |
string.format("api_key=FOOBAR&field1=%s", value), | |
handle_request | |
) | |
end | |
function do_it() | |
value = read_value() | |
post_value(value) | |
end | |
if not tmr.alarm(0, 15000, tmr.ALARM_SINGLE, do_it) then | |
print("failed to set up timer") | |
else | |
print("starting things in 15s") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment