Skip to content

Instantly share code, notes, and snippets.

Avatar

Electric Imp, Inc. ElectricImpSampleCode

View GitHub Profile
@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
@ElectricImpSampleCode
ElectricImpSampleCode / UDP_Hub_secure.agent.nut
Last active Oct 21, 2020
impOS 42 UDP Local Networking Example
View UDP_Hub_secure.agent.nut
// ********** Imports **********
#require "Rocky.class.nut:2.0.2"
// ********** Web UI **********
const HTML_STRING = @"<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='UTF-8'>
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
<title>UDP Demo</title>
@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.
*
*/
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 / webserver.agent.nut
Last active Aug 25, 2020
Example code showing how an agent can serve a dynamic web page
View webserver.agent.nut
// 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 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 / factory.firmware.dut.agent.nut
Last active Aug 6, 2020
New Factory Firmware sample for separate DUT and Fixture Device Groups
View factory.firmware.dut.agent.nut
// ------------------------------------------------------------------------------
// 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 Aug 6, 2020
Electric Imp imp API server.bless() example
View server.bless.agent.nut
// ***************************************
// ***** 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 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"