This file contains 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
// APPLICATION LIBRARIES | |
// Include the temperature/humidity sensor Library | |
#require "HTS221.device.lib.nut:2.0.2" | |
// APPLICATION CONSTANTS | |
// The I2C address for the sensor | |
const I2C_ADDR = 0xBE; | |
// APPLICATION GLOBALS | |
// Set up the imp I2C bus the sensor is connected to |
This file contains 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
// Set up global variables | |
// Reference the imp006 pins connected two of the user LED's colors | |
red_pin <- hardware.pinR; | |
// Define the LED flash function | |
function setLed(state) { | |
// Set the user LED control pins' state | |
red_pin.write(state ? 1 : 0); | |
} |
This file contains 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
// Set up global variables | |
// Reference the imp006 pin connected the user LED's blue light | |
blue_pin <- hardware.pinXB; | |
// Track the LED flash state | |
state <- false; | |
// Define the LED flash function | |
function flash() { | |
// Set the user LED control pin's state | |
state = !state; |
This file contains 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
// Log the URLs we need | |
server.log("Turn LED On: " + http.agenturl() + "?led=1"); | |
server.log("Turn LED Off: " + http.agenturl() + "?led=0"); | |
// Define the function called when a request is sent to the agent | |
function requestHandler(request, response) { | |
try { | |
// Check if the user sent 'led' as a query parameter | |
if ("led" in request.query) { | |
// If they did, and led = anything or 0, set our state variable |
This file contains 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
// CONSTANTS | |
// Replace the 'USERNAME' and 'PASSWORD' values with your own | |
const USERNAME = '...' | |
const PASSWORD = '...' | |
const API_URL = 'api.electricimp.com' | |
const API_VER = '/v5/' | |
// GLOBALS | |
var https = require('https'); | |
var products = []; |
This file contains 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
// Assign parallel aliases for the UART according to role | |
arduino <- hardware.uart57; | |
computer <- hardware.uart57; | |
function relay() { | |
// UART initially configured for Arduino input | |
local byte = arduino.read(); | |
if (byte != -1) { | |
// We have a valid byte to relay so reconfigure the UART |
This file contains 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
helper <- { | |
function encode(str) { | |
return http.urlencode({ s = str }).slice(2); | |
} | |
} | |
class TwitterClient { | |
consumerKey = null; | |
consumerSecret = null; | |
accessToken = null; |
This file contains 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 blobToHexString(data) { | |
local s = "0x"; | |
foreach (b in data) s += format("%02X", b); | |
return s; | |
} | |
function testHash() { | |
local data = "The quick brown fox jumps over the lazy dog"; | |
local key = "key"; | |
local hash = http.hash.hmacsha256(data, key); |
This file contains 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 blobToHexString(data) { | |
local s = "0x"; | |
foreach (b in data) s += format("%02X", b); | |
return s; | |
} | |
function testHash() { | |
local data = "The quick brown fox jumps over the lazy dog"; | |
local key = "key"; | |
local hash = http.hash.hmacsha512(data, key); |
This file contains 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 blobToHexString(data) { | |
local s = "0x"; | |
foreach (b in data) s += format("%02X", b); | |
return s; | |
} | |
function testHash() { | |
local data = "The quick brown fox jumps over the lazy dog"; | |
local hash = http.hash.md5(data); | |