Skip to content

Instantly share code, notes, and snippets.

View ElectricImpSampleCode's full-sized avatar

Electric Imp, Inc. ElectricImpSampleCode

View GitHub Profile
@ElectricImpSampleCode
ElectricImpSampleCode / PowerEfficientRemoteMonitoringApp.agent.nut
Last active July 24, 2020 09:23
An Introduction To Squirrel Applications Example 6
// Power Efficient 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"
// Library to manage agent/device communication
@ElectricImpSampleCode
ElectricImpSampleCode / AsynchronousRemoteMonitoringApp.agent.nut
Last active July 24, 2020 09:24
An Introduction To Squirrel Applications Example 5
// Asynchronous 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"
// Library to manage agent/device communication
@ElectricImpSampleCode
ElectricImpSampleCode / RefrigeratorMonitoringApp.agent.nut
Last active July 24, 2020 09:27
An Introduction To Squirrel Applications Example 4
// Refrigerator Monitor Application Agent Code
// ---------------------------------------------------
// CLOUD SERVICE LIBRARY
// ---------------------------------------------------
// Libraries must be required before all other code
// Initial State Library
#require "InitialState.class.nut:1.0.0"
// Library to manage agent/device communication
@ElectricImpSampleCode
ElectricImpSampleCode / SimpleRemoteMonitoringApp.agent.nut
Last active July 24, 2020 09:26
An Introduction To Squirrel Applications Example 3
// 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"
@ElectricImpSampleCode
ElectricImpSampleCode / SimpleRefridgeratorMonitor.agent.nut
Last active July 24, 2020 09:22
An Introduction To Squirrel Applications Example 2
// Simple Refrigerator Monitor Application Agent Code
// ---------------------------------------------------
// CLOUD SERVICE LIBRARY
// ---------------------------------------------------
// Libraries must be required before all other code
// Initial State Library
#require "InitialState.class.nut:1.0.0"
@ElectricImpSampleCode
ElectricImpSampleCode / ReadingASensor.agent.nut
Last active July 24, 2020 09:29
Introduction To Squirrel Applications Example 1
// Reading a Sensor Agent Code
// ---------------------------------------------------
// CLOUD SERVICE LIBRARY
// ---------------------------------------------------
// Libraries must be included before all other code
// Initial State Library
#require "InitialState.class.nut:1.0.0"
@ElectricImpSampleCode
ElectricImpSampleCode / impexplorer.motion.agent.nut
Last active November 25, 2019 13:43
impExplorer Sample Code: Motion Detector
// Copyright (c) 2018, Electric Imp, Inc.
// Licence: MIT
// IMPORTS
#require "rocky.class.nut:2.0.2"
// CONSTANTS
const DATA_PER_SECOND = 50.0;
const TWO_PI = 6.283185307179586;
const HTML_DATA = @"
@ElectricImpSampleCode
ElectricImpSampleCode / crypto.sign.agent.nut
Last active September 10, 2018 14:45
Electric Imp imp API crypto.sign() PKCS#8 example
// CONSTANTS
// Full PKCS#8 key omitted but can be generated with:
// $ openssl req -x509 -nodes -newkey rsa:2048 -batch -keyout key.pem
const RSA_PRIVATE8_KEY_PEM = @"
-----BEGIN PRIVATE KEY-----
...
-----END PRIVATE KEY-----";
function decodePrivatePem(pemString) {
local lines = split(pemString, "\n");
@ElectricImpSampleCode
ElectricImpSampleCode / getwifihints.device.nut
Last active January 29, 2019 14:00
Electric imp imp API imp.getwifihints() example
// Post-reconnection attempt handler
function reconnect(reason) {
if (reason != SERVER_CONNECTED) {
// Reconnection failed, so re-attempt in 1 minute
imp.wakeup(60, function() {
server.connect(reconnect, 30);
});
}
}
@ElectricImpSampleCode
ElectricImpSampleCode / simple.factory.firmware.device.nut
Last active June 20, 2018 12:10
Sample fixture factory firmware
// ------------------------------------------------------------------------------
// File: factory.firmware.device.nut
// Version: 1.1.2
//
// Copyright 2015-18 Electric Imp
//
// 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