Skip to content

Instantly share code, notes, and snippets.

View ElectricImpSampleCode's full-sized avatar

Electric Imp, Inc. ElectricImpSampleCode

View GitHub Profile
@ElectricImpSampleCode
ElectricImpSampleCode / ALawFixedFrequencyDAC.agent.nut
Last active February 19, 2021 16:31
Electric Imp imp API fixedfrequencydac.addbuffer() example code
// AGENT CODE
const AMPLITUDE = 0x3FFF;
const NUMBER_POINTS = 1024;
const CLIP_VALUE = 32635;
const INCR_X = 0.78531475;
local streaming = false;
local logTable = [
1,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
@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 / factory.activation.dut.agent.nut
Last active November 23, 2020 14:29
Factory Activation Example Code 2.1.1
// ------------------------------------------------------------------------------
// File: factory.activation.dut.agent.nut
// Version: 2.1.2
//
// Copyright 2020 Twilio
//
// SPDX-License-Identifier: MIT
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@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 / 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 / webserver.agent.nut
Last active August 25, 2020 20:05
Example code showing how an agent can serve a dynamic web page
// Updated: 14 July 2020
// IMPORTS
#require "rocky.agent.lib.nut:3.0.0"
// CONSTANTS
const HTML_STRING = @"<!DOCTYPE html><html lang='en-US'><meta charset='UTF-8'>
<html>
<head>
<title>Environment Data</title>
<link rel='stylesheet' href='https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css' integrity='sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk' crossorigin='anonymous'>
@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 / factory.firmware.dut.agent.nut
Last active August 6, 2020 09:23
New Factory Firmware sample for separate DUT and Fixture Device Groups
// ------------------------------------------------------------------------------
// File: factory.firmware.dut.agent.nut
// Version: 2.1.1
//
// Copyright 2020 Twilio
//
// SPDX-License-Identifier: MIT
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@ElectricImpSampleCode
ElectricImpSampleCode / server.bless.agent.nut
Last active August 6, 2020 09:23
Electric Imp imp API server.bless() example
// ***************************************
// ***** SETUP *****
// ***************************************
// CONSTANTS
// Replace the following string with your server logging endpoint
const RESULTS_URL = "YOUR_RESULT_LOGGING_URL";
// ***************************************
// ***** DUT AGENT FUNCTIONS *****
@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,