Slide 32
Slide 32 text
THETHINGS.IO
// configure led to be a digital output
micro.configure(ANALOG_IN);
function loop() {
// read values
local pin1Value = hardware.pin1.read();
// create json and send to agent
local data = { "thing":{ "id":"THING_TOKEN"}, "values": [{"key":
"noise", "value": pin1Value, "units": "", "type":"temporal"}]}
agent.send("senddata", data);
// recursively call self after 0.5 seconds
imp.wakeup(0.5, loop);
}
// start the loop
loop();
Device.nuts
local url = "https://api.thethings.io/0.1/ThingWrite/";
local user_token = "XXXXXXXXXXXX";
local headers = {
"Authorization": "theThingsIO-Token: " + user_token,
"Content-Type": "application/json; charset=UTF-8"
}
device.on("senddata", function(data) {
local body = http.jsonencode(data);
local resp = http.post(url, headers, body).sendsync();
return resp;
});
Agent.nuts