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
// Start of agent | |
// Load the data from persistent storage | |
settings <- server.load() | |
// It the load is null, it tells us this is the first time the agent is running | |
if (settings == 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
// On wake from deep sleep or cold boot, Squirrel starts here | |
// Check if nv table exists and if it contains 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, this code will automatically create it when it adds 'count' | |
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
// Define the regular expression: | |
// Look for digits one or more times (\d+) | |
// Look for spaces | |
// Look for any case character one or more times ([a-zA-Z]+) | |
// Look for the first punctuation mark (\p) | |
local expression = regexp2(@"\d+ [a-zA-Z]+\p") | |
local compareString = "stuff 123 Test." | |
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
// Define the regular expression: | |
// Look for digits one or more times (\d+) | |
// Look for spaces | |
// Look for any case character one or more times ([a-zA-Z]+) | |
// Look for the first punctuation mark (\p) | |
local expression = regexp2(@"(\d+) ([a-zA-Z]+)(\p)") | |
local compareString = "stuff 123 Test." | |
// Generate an array of matches | |
local results = expression.capture(compareString) |
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
// Define the regular expression: | |
// Look for digits one or more times: \d+ | |
local expression = regexp2(@"\d+") | |
local compareString = "91939312" | |
if (expression.match(compareString)) | |
{ | |
// Do we have a match? |
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 KeenIO class can be found at: | |
// https://github.com/electricimp/reference/blob/master/webservices/keenio/keenio.agent.nut | |
class KeenIO { ... } | |
const PROJECT_ID = ""; // Your Project ID (from Keen Dashboard) | |
const API_KEY = ""; // Your API Write Key (from Keen Dashboard) | |
// Create the KeenIO Client: | |
keen <- KeenIO(PROJECT_ID, API_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
class TestDigitalOut(ElectricImpTestCase): | |
def test_digital_out_can_write_high(self): | |
value = 1 | |
mbedPin = mbedrpc.DigitalIn(self.mbedrpc, "p10") | |
self.loadAndRunSquirrelCode(""" | |
hardware.pin5.configure(DIGITAL_OUT); | |
hardware.pin5.write(%d); | |
""" % value | |
assert_that(mbedPin.read(), is_(value)) |
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 getImpType() | |
{ | |
// Determines which kind of imp is in use, returning | |
// an integer value according to type: eg. imp001 returns 1 | |
if (imp.environment() == ENVIRONMENT_CARD) | |
{ | |
return 1 | |
} | |
else |
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 getImpType() | |
{ | |
// Determines which kind of imp is in use, returning | |
// an integer value according to type: eg. imp001 returns 1 | |
if (imp.environment() == ENVIRONMENT_CARD) | |
{ | |
return 1 | |
} | |
else |
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 getImpType() | |
{ | |
// Determines which kind of imp is in use, returning | |
// an integer value according to type: eg. imp001 returns 1 | |
if (imp.environment() == ENVIRONMENT_CARD) | |
{ | |
return 1 | |
} | |
else |