Skip to content

Instantly share code, notes, and snippets.

View ElectricImpSampleCode's full-sized avatar

Electric Imp, Inc. ElectricImpSampleCode

View GitHub Profile
@ElectricImpSampleCode
ElectricImpSampleCode / timer.class.nut
Last active June 2, 2021 08:29
imp API Cookbook recipe: repeating timers
class Timer {
static version = "1.0.0";
/*
* Private Properties
*/
_repeat = true;
_period = 0;
_timer = null;
@ElectricImpSampleCode
ElectricImpSampleCode / gnss.get-nmea.device.nut
Created January 5, 2021 11:41
Electric Imp imp API GNSS example code: get NMEA sentences
// Get GSV (satellites in view) NMEA sentences from modem
// NOTE #1 See https://gpsd.gitlab.io/gpsd/NMEA.html#_nmea_standard_sentences
// for sentence details
// NOTE #2 Assumes you have an existing configured and enabled gnss-session
// instance, as per https://developer.electricimp.com/api/gnss-session/enable
// Callback to process read sentences
function processSentences(result) {
if (result.status == 0) {
// No error, so just output each received sentence,
@ElectricImpSampleCode
ElectricImpSampleCode / gnss.get-location.device.nut
Last active June 6, 2022 11:39
Electric Imp imp API GNSS example code: get the device’s location
// Hold a reference to the GNSS Session object
gnssSession <- null;
// Store device location
location <- { "lat": 0, "lon": 0 };
function isGnssEnabled() {
// Is GNSS ready to use?
if (gnssSession == null) return false;
try {
@ElectricImpSampleCode
ElectricImpSampleCode / uart-pulse-count.device.nut
Last active October 21, 2020 11:28
Example code demonstrating pulse counting and pulse interval timing via imp UART
/*
* Demonstrate pulse counting using an imp UART
*
* This code uses the falling edge of the input signal to trigger a UART receive.
* A framing error will be generated, but we ignore this - and the data -
* and just use the event information.
*
* Copyright 2020, Twilio.
*
*/
@ElectricImpSampleCode
ElectricImpSampleCode / iad.comms.agent.nut
Last active May 12, 2022 13:14
Effective Internet <-> Agent <-> Device communications with the Rocky and MessageManager libraries
/*
* Load the libraries that we need:
* Rocky to serve the API,
* MessageManager to handle the agent-device interaction
*/
#require "Rocky.agent.lib.nut:3.0.0"
#require "MessageManager.lib.nut:2.4.0"
/*
* Instantiate instances of Rocky and MessageManager
@ElectricImpSampleCode
ElectricImpSampleCode / wake.pin.device.nut
Created October 7, 2020 12:47
Electric Imp Wake Pin Example
/*
* Electric Imp Wake Pin example code
*
* Requires any imp (but not relevant to imp005)
*
* Copyright 2020 Twilio
* License: MIT
*
*/
@ElectricImpSampleCode
ElectricImpSampleCode / imp006bk.ranger-and-display.agent.nut
Created August 6, 2020 12:35
imp006 Breakout Kit Sample Code: Ultrasonic Raner and Display
// Register an handler to deal with incoming 'trigger'
// messsages from the device -- it just logs the event
device.on("trigger", function(isCut) {
if (isCut) server.log("Beam cut");
});
@ElectricImpSampleCode
ElectricImpSampleCode / imp006bk.sensor-and-display.device.nut
Last active August 5, 2020 14:30
imp006 Breakout Kit Example Code: sensor and Grove display
// IMPORTS
// Get the temperature sensor library
#require "HTS221.device.lib.nut:2.0.2"
// CLASSES
// The following driver class and enum provides support
// for the TM1637 display chip
enum TM1637_LED_CLASS {
ADDR_AUTO = 0x40,
CMD_SET_ADDR = 0xC0,
@ElectricImpSampleCode
ElectricImpSampleCode / MultiWebservicesSimpleRemoteMonitor.agent.nut
Created July 24, 2020 09:42
An Introduction to Squirrel Applications Example 9
// Simple Remote Monitoring Application Agent Code
// ---------------------------------------------------
// CLOUD SERVICE LIBRARY
// ---------------------------------------------------
// Libraries must be required before all other code
// Initial State Library
#require "InitialState.class.nut:1.0.0"
#require "IBMWatson.class.nut:1.1.0"
@ElectricImpSampleCode
ElectricImpSampleCode / imp006.impt.incorrect.device.nut
Last active July 13, 2020 10:49
imp006 Breakout Board impt tutorial incorrect version
// 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