Skip to content

Instantly share code, notes, and snippets.

@cweems
Last active October 21, 2020 15:27
Show Gist options
  • Save cweems/56c8ef174e9aea64d5533250ddfaf655 to your computer and use it in GitHub Desktop.
Save cweems/56c8ef174e9aea64d5533250ddfaf655 to your computer and use it in GitHub Desktop.
function requestHandler(request, response) {
try {
local agentStatus = http.urldecode(request.body).WorkerActivityName;
server.log(agentStatus);
local ledState = (agentStatus == "Available") ? false : true;
device.send("set.led", ledState);
// Send a response back to TaskRouter saying everything was OK.
response.send(200, "OK");
} catch (ex) {
response.send(500, "Internal Server Error: " + ex);
}
}
// Register the HTTP handler to begin watching for HTTP requests from your browser
http.onrequest(requestHandler);
// Import Electric Imp’s WS2812 library
#require "WS2812.class.nut:3.0.0"
// Set up global variables
spi <- null;
led <- null;
// Define the led colors
function setLedState(state) {
local color = state ? [50,0,0] : [0,50,0];
led.set(0, color).draw();
}
// Set up the SPI bus the RGB LED connects to
spi = hardware.spi257;
spi.configure(MSB_FIRST, 7500);
hardware.pin1.configure(DIGITAL_OUT, 1);
// Set up the RGB LED
led = WS2812(spi, 1);
// Register a handler function for incoming "set.led" messages from the agent
agent.on("set.led", setLedState);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment