Skip to content

Instantly share code, notes, and snippets.

Avatar

Electric Imp, Inc. ElectricImpSampleCode

View GitHub Profile
@ElectricImpSampleCode
ElectricImpSampleCode / timer.class.nut
Last active Jun 2, 2021
imp API Cookbook recipe: repeating timers
View timer.class.nut
class Timer {
static version = "1.0.0";
/*
* Private Properties
*/
_repeat = true;
_period = 0;
_timer = null;
@ElectricImpSampleCode
ElectricImpSampleCode / gnss.get-nmea.device.nut
Created Jan 5, 2021
Electric Imp imp API GNSS example code: get NMEA sentences
View gnss.get-nmea.device.nut
// 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 Jan 5, 2021
Electric Imp imp API GNSS example code: get the device’s location
View gnss.get-location.device.nut
// Hold a reference to the GNSS Session object
gnssSession <- null;
// Store device location
location <- { "lat": 0, "lon": 0 };
function enableGNSS() {
// Not got a GNSS Session? Establish one
if (gnssSession == null) {
// Set up a session
@ElectricImpSampleCode
ElectricImpSampleCode / uart-pulse-count.device.nut
Last active Oct 21, 2020
Example code demonstrating pulse counting and pulse interval timing via imp UART
View uart-pulse-count.device.nut
/*
* 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 Oct 30, 2020
Effective Internet <-> Agent <-> Device communications with the Rocky and MessageManager libraries
View iad.comms.agent.nut
/*
* 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
View wake.pin.device.nut
/*
* 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 Aug 6, 2020
imp006 Breakout Kit Sample Code: Ultrasonic Raner and Display
View imp006bk.ranger-and-display.agent.nut
// 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 Aug 5, 2020
imp006 Breakout Kit Example Code: sensor and Grove display
View imp006bk.sensor-and-display.device.nut
// 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 Jul 24, 2020
An Introduction to Squirrel Applications Example 9
View MultiWebservicesSimpleRemoteMonitor.agent.nut
// 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 Jul 13, 2020
imp006 Breakout Board impt tutorial incorrect version
View imp006.impt.incorrect.device.nut
// 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