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
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
// 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
/******************************************************************************* | |
* 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
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
// This is the function that actually handles the incoming HTTP Request | |
function SimpleRequestHandler(data) { | |
server.log("Got a request with value='" + data + "'"); | |
return 200; | |
} | |
// handles incoming HttpIn requests, and sends "responses" to an HttpRequest node through | |
// an output port. The ResponsePort sends a url-encoded message where "value" is the response code. | |
class HttpInPortWithResponse extends InputPort { | |
RequestHandler = null; // function that will be called whenever a request comes into the input port. Should return a status code. |
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
imp.configure("Analog In", [], []); | |
function readPots() | |
{ | |
local p = hardware.pin5.read(); | |
server.show(p); | |
imp.wakeup(0.5, readPots); | |
} | |
hardware.pin5.configure(ANALOG_IN); |
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 redPot = hardware.pin5; | |
local greenPot = hardware.pin7; | |
local bluePot = hardware.pin8; | |
local red = 0; | |
local green = 0; | |
local blue = 0; | |
local redPort = OutputPort("red"); | |
local greenPort = OutputPort("green"); |
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 simpleInputPort extends InputPort | |
{ | |
function set(value) | |
{ | |
if (value == 1) | |
{ | |
server.show("on"); | |
hardware.pin2.write(0); | |
} | |
else if (value == 0) |