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
// 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
// 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
function stateChangeCallback(state) { | |
// Define a callback function, which we will bind to the interface record | |
// in 'getAvailableInterfaces()' so that we know which interface's change | |
// of state actually triggered the callback | |
// Is the interface available for use? It is if it's connected | |
this.isAvailable = (state == imp.net.CONNECTED); | |
// When we reach a terminal state consider the interface reported | |
if (state == imp.net.CONNECTED || |
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
// The 'interfaces' variables holds references to available interfaces | |
local interfaces = {}; | |
// Set flags that the app can check to see if an interface can be used | |
local availableForLocal = { "wifi" : false, | |
"ethernet" : false, | |
"cell" : false }; | |
// These globals are used for reporting | |
local interfaceCount = 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
// ********** Imports ********** | |
#require "Rocky.class.nut:2.0.2" | |
// ********** Web UI ********** | |
const HTML_STRING = @"<!DOCTYPE html> | |
<html lang='en'> | |
<head> | |
<meta charset='UTF-8'> | |
<meta name='viewport' content='width=device-width, initial-scale=1.0'> | |
<title>UDP Demo</title> |
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 a timer... | |
imp.wakeup(60, | |
function() { server.log("Timer \"wakeup_timer\" woke up"); }, | |
"wakeup_timer"); | |
// ...but cancel it before it fires... | |
local timer = imp.wakeup(40, function() { | |
server.log("Timer \"wakeup_timer\" cancelled"); | |
imp.cancelwakeup("wakeup_timer"); | |
}); |
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
// ------------------------------------------------------------------------------ | |
// File: factory.activation.dut.agent.nut | |
// Version: 2.1.2 | |
// | |
// Copyright 2020 Twilio | |
// | |
// SPDX-License-Identifier: MIT | |
// | |
// Permission is hereby granted, free of charge, to any person obtaining a copy | |
// of this software and associated documentation files (the "Software"), to deal |
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
// ------------------------------------------------------------------------------ | |
// File: simple.factory.firmware.device.nut | |
// Version: 2.0.0 | |
// | |
// Copyright 2015-19 Electric Imp | |
// | |
// SPDX-License-Identifier: MIT | |
// | |
// Permission is hereby granted, free of charge, to any person obtaining a copy | |
// of this software and associated documentation files (the "Software"), to deal |