This file contains hidden or 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
| local greenState = 0; | |
| local redState = 0; | |
| device.on("setRed", function(data) { | |
| redState = data; | |
| }); | |
| device.on("setGreen", function(data) { | |
| greenState = data; | |
| }); |
This file contains hidden or 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
| /******************************************************************************* | |
| * Reads a pulse (either HIGH or LOW) on a pin. If the pulseValue is HIGH, | |
| * the object will start timing when the pin goes HIGH, then waits for the pin | |
| * to go LOW, and executes the callback (callback expects a function with one | |
| * parameter, the length of the pulse in microseconds). | |
| * | |
| * The accuracy of this function has not been tested, and will have some | |
| * variance because of how callbacks work. | |
| ******************************************************************************/ | |
| class Pulse { |
This file contains hidden or 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
| // Create a class to control an LED from an input port | |
| class LedController extends InputPort { | |
| led = null; | |
| constructor(name, _led) { | |
| base(name); | |
| this.led = _led; | |
| } | |
This file contains hidden or 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
| responseQueue <- []; | |
| timeout <- 5; // timeout (in seconds) for roundtrip from agent -> device -> agent. | |
| // function that triggers responses if timeout expires | |
| function checkResponses() { | |
| local newQueue = []; | |
| // loop through http response queue | |
| local t = time(); | |
| for (local i = 0; i < responseQueue.len(); i++) { | |
| // if it's been sitting for more than allowed timeout |
This file contains hidden or 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
| html <- "<html><head><title>Hello World</title></head><body><h1>Hello World</h1><div>I'm being server by an angert!! Hurray</div></body></html>"; | |
| http.onrequest(function(req, res) { | |
| res.send(200, html); | |
| }); |
This file contains hidden or 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 stringify(t, i = 0) { | |
| local indentString = ""; | |
| for(local x = 0; x < i; x++) indentString += "."; | |
| if (typeof(t) != "table" && typeof(t) != "array") { | |
| server.log(indentString + t) | |
| } else { | |
| foreach(k, v in t) { | |
| if (typeof(v) == "table" || typeof(v) == "array") { | |
| local par = "[]"; |
This file contains hidden or 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
| /***** Include Hannah class here *****/ | |
| hannah <- Hannah(); | |
| function poll() { | |
| agent.send("temp", { temp = hannah.temp.get() }); | |
| imp.onidle(function() { server.sleepfor(30.0); }); | |
| } | |
| poll(); |
This file contains hidden or 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
| data <- { | |
| platform = "electric imp", | |
| online = true, | |
| token = "4e64e622-f456-44a6-af00-b996b6bea7a1", | |
| type = "temp", | |
| lat = 37.39674, | |
| long = -122.10473 | |
| } | |
| http.post(SKYNET_BASE + "devices", {}, http.urlencode(data)).sendasync(function(resp) { |
This file contains hidden or 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
| curl -X POST -d "type=drone&color=black&owner=bc7e4f6c-a0a7-4ab7-98b7-ec688fd36156" http://skynet.im/devices | |
| {"type":"drone","color":"black","owner":"bc7e4f6c-a0a7-4ab7-98b7-ec688fd36156","ipAddress":"173.8.157.38","uuid":"58402a41-f25c-11e3-ba2e-0b078550b2fe","timestamp":"2014-06-12T18:06:58.276Z","token":"b56jgbmi8xyo80k97rj9fx4p274d9529","channel":"main","online":false} | |
| verify that uuid exists by running: | |
| curl -X GET http://skynet.im/devices/58402a41-f25c-11e3-ba2e-0b078550b2fe --header "skynet_auth_uuid: bc7e4f6c-a0a7-4ab7-98b7-ec688fd36156" --header "skynet_auth_token: b56jgbmi8xyo80k97rj9fx4p274d9529" | |
| {"error":"unauthorized"}% |