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 hardware.pin5 to a global variable, therm | |
therm <- hardware.pin5; | |
// Configure pin5/therm for analog input | |
therm.configure(ANALOG_IN); | |
// These constants are particular to the thermistor we're using. | |
// Check your datasheet for what values you should be using | |
const B_THERM = 3977.0; | |
const T0_THERM = 298.15; |
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 a global variable, led, to the imp001 pin to which the LED is connected | |
led <- hardware.pin9; | |
// Configure it for PWM output | |
led.configure(PWM_OUT, 1.0 / 400.0, 0.0); | |
// Record the state and delta of the LED's cycle | |
ledState <- 0.0; | |
ledChange <- 0.05; | |
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
// These constants may be different for your servo | |
const SERVO_MIN = 0.03; | |
const SERVO_MAX = 0.1; | |
// Create global variable for the pin to which the servo is connected | |
// then configure the pin for PWM | |
servo <- hardware.pin7; | |
servo.configure(PWM_OUT, 0.02, SERVO_MIN); | |
// Define a function to control the servo. |
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
// WEATHER UPDATE CLASS | |
class WeatherUpdate { | |
// Simple Squirrel class for interaction with Forecast.io | |
url = "https://api.forecast.io/forecast/"; | |
apikey = "YOUR API KEY HERE"; | |
function forecastRequest(longitude = 52.205082, latitude = 0.130209) { | |
// Parameters: longitude and latitude of location for which a forecast is required | |
// Return: configured HTTP request |
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
#require "Twitter.class.nut:1.2.1" | |
// CONSTANTS | |
// Twitter keys | |
const API_KEY = "YOUR API KEY"; | |
const API_SECRET = "YOUR API SECRET"; | |
const AUTH_TOKEN = "YOUR AUTH TOKEN"; | |
const TOKEN_SECRET = "YOUR TOKEN SECRET"; | |
// GLOBAL VARIABLES |
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
// AGENT CODE | |
function requestHandler(request, response) { | |
try { | |
if ("setcolor" in request.query) { | |
device.send("setcolor", request.query.setcolor); | |
response.send(200, "Color Set"); | |
return; | |
} | |
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 the disconnection policy | |
server.setsendtimeoutpolicy(RETURN_ON_ERROR, WAIT_TIL_SENT, 10); | |
// Constants | |
const RECONNECT_TIME = 900; | |
const RECONNECT_TIMEOUT = 60; | |
// Globals | |
disData <- ""; | |
disFlag <- false; |
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
// On wake from deep sleep or cold boot, Squirrel starts here | |
// Check if nv table doesn't exist or, if it does, whether it lacks the key 'count' | |
if (!("nv" in getroottable()) || !("count" in nv)) { | |
// Either the nv table hasn't been instantiated or it has but lacks a 'count' slot, | |
// so create them. If nv table exists, this code just adds 'count' to it. If nv | |
// doesn't exist yet, impOS will automatically create it when we add 'count' | |
nv <- { "count": 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
function startTime(time) { | |
// Send the device a 'pong' message immediately | |
device.send("pong", time); | |
} | |
// When we get a 'ping' message from the device, call startTime() | |
device.on("ping", startTime); |
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 outgoing request object | |
local request = http.get(webServiceURL, webServiceHeaders) | |
// Define the response handler | |
function handleResponse(responseTable) { | |
// Called when the imp receives a response from the remote service | |
if (responseTable.statuscode == 200) { | |
// Remote service has responded with 'OK' so decode | |
// the response's body 'responseTable.body' and headers 'responseTable.headers' | |
// Code omitted for clarity... |