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
http.onrequest(function(req, resp) { | |
if(req.path=="/led/on") { | |
device.send("led", 1); | |
} | |
if(req.path=="/led/off") { | |
device.send("led", 0); | |
} | |
resp.send(200, "OK") | |
}); |
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
// ----------------------------------------------------------------------------- | |
class Firebase { | |
// General | |
db = null; // the name of your firebase | |
auth = null; // Auth key (if auth is enabled) | |
baseUrl = null; // Firebase base url | |
prefixUrl = ""; // Prefix added to all url paths (after the baseUrl and before the Path) | |
// For REST calls: | |
defaultHeaders = { "Content-Type": "application/json" }; |
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
// Copyright (c) 2014 Electric Imp | |
// This file is licensed under the MIT License | |
// http://opensource.org/licenses/MIT | |
/* | |
BGLib for Squirrel | |
================== | |
This implements the BGLib library for Bluegiga's BLE112 Bluetooth Smart module. | |
It assumes you have connected from the Imp to the BLE112: |
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
http.onrequest(function(req, resp) { | |
if (req.query != null && "username" in req.query) server.log("Got a YO from " + req.query.username); | |
device.send("toggleLed", null); | |
resp.send(200, "OK"); | |
}); |
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
class Stepper { | |
pinArray = null; | |
currentPosition = null; // 0 | |
stepsPerFullRotation = null; // 200 | |
pin = null; // id for pinArray | |
delayTime = null; // seconds | |
constructor(_firstPin, _secondPin, _thirdPin, _fourthPin, _stepsPerFullRotation, _delayTime) | |
{ | |
pinArray = [_firstPin, _secondPin, _thirdPin, _fourthPin]; |
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
isHacking <- null; | |
message <- ""; | |
device.on("hacking", function(data) { | |
isHacking = data.state; | |
message = format("%s (as of %i) - via an @electricimp agent", (data.state == 0) ? "NOT HACKING" : "HACKING", time()) | |
if (!data.boot) { | |
twitter.tweet(message); | |
} | |
}); |
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"}% |
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
/***** 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
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 = "[]"; |