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
// Establish threshold trigger flags for all your sensors | |
local sensorOneTriggerFlag = false; | |
local sensorTwoTriggerFlag = false; | |
// Define the function that will be called when the device has connected | |
// to the server (or the connection attempt times out) | |
function connectResponseCallback(reason) { | |
if (reason == SERVER_CONNECTED) { | |
// Server is online. Because we can't say which sensor | |
// triggered the server.connect() we check both trigger |
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 logWokenReason() { | |
local s = "Device restarted. Reason: "; | |
local c = hardware.wakereason(); | |
switch (c) { | |
case WAKEREASON_POWER_ON: // 0 | |
s += "Cold boot"; | |
break; | |
case WAKEREASON_TIMER: // 1 | |
s += "Timer woke the imp"; | |
break; |
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
// UART Logger | |
// Copyright (c) 2014-19, Electric Imp, Inc. | |
// Licence: MIT | |
class Logger { | |
// Code version | |
static VERSION = "1.2.0"; | |
// Instance properties |
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
// Configure imp001 pin 1 | |
hardware.pin1.configure(DIGITAL_OUT, 0); | |
server.setsendtimeoutpolicy(RETURN_ON_ERROR, WAIT_FOR_ACK, 10); | |
data <- blob(4096); | |
state <- 0; | |
function blink() { | |
// Turn LED on or off | |
hardware.pin1.write(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
// Set the timeout policy to RETURN_ON_ERROR, ie. to continue running at disconnect | |
server.setsendtimeoutpolicy(RETURN_ON_ERROR, WAIT_TIL_SENT, 10); | |
// Configure Pin 1 to drive the connection status LED | |
hardware.pin1.configure(DIGITAL_OUT); | |
hardware.pin1.write(0); | |
// Create an array of WiFi networks, each defined by a table | |
connections <- [ | |
{ ssid = "SSID1", pw = "SSID1PW" }, |
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
#!/usr/bin/env python | |
import serial | |
s = serial.Serial("/dev/ttyAMA0", baudrate=115200, timeout=3.0) | |
message = "" | |
while True: | |
logChar = s.read() | |
if logChar: |
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 Logger { | |
_serial = null; | |
constructor (impUART) { | |
if (impUART != null) { | |
_serial = impUART; | |
_serial.configure(115200, 8, PARITY_NONE, 1, NO_RX); | |
} | |
} | |
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 pin9 to a global variable | |
led <- hardware.pin9; | |
// Configure LED pin for DIGITAL_OUTPUT, and set initial state to off | |
led.configure(DIGITAL_OUT, 0); | |
// Assign a global variable to track current state of LED pin | |
state <- 0; | |
// Function to blink LED |
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
// Alias the GPIO pin as 'button' | |
button <- hardware.pin1; | |
function buttonPress() { | |
local state = button.read(); | |
if (state == 1) { | |
// The button is released | |
server.log("Release"); | |
} else { | |
// The button is pressed |
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
// Alias pin 2 as pot | |
pot <- hardware.pin2; | |
// Configure the pin for analog input | |
pot.configure(ANALOG_IN); | |
// Define a function to poll the pin every 0.1 seconds | |
function poll() { | |
// Read the pin and log its value | |
server.log(pot.read()); |
OlderNewer