Skip to content

Instantly share code, notes, and snippets.

View ElectricImpSampleCode's full-sized avatar

Electric Imp, Inc. ElectricImpSampleCode

View GitHub Profile
@ElectricImpSampleCode
ElectricImpSampleCode / factory.wifi.agent.nut
Created October 3, 2017 15:18
Factory firmware with agent-hosted WiFi credentials UI
// Import Electric Imp's REST API management library
#require "Rocky.class.nut:2.0.0"
// Replace the following two strings with your server logging endpoint
const RESULTS_URL = "<YOUR_RESULT_LOGGING_URL>";
// Define the web page HTML as a constant
const HTML_STRING = @"<!DOCTYPE html><html lang='en-US'><meta charset='UTF-8'>
<html>
<head>
@ElectricImpSampleCode
ElectricImpSampleCode / logs.js
Last active September 21, 2017 12:45
impCentral API Example Code: Device Logging via Stream
// CONSTANTS
// Replace the 'USERNAME' and 'PASSWORD' values with your own, and enter
// Replace the 'DEVICE_ID' value with the ID of a device accessible via impCentral (not the IDE)
// Replace the 'ACCESS_TOKEN' value with one retrieved using 'products.js' at
// https://gist.github.com/ElectricImpSampleCode/f0fb7f8bd04be009beeb5ee86dbd406a
const USERNAME = '...';
const PASSWORD = '...';
const DEVICE_ID = '...';
const ACCESS_TOKEN = '...';
const API_URL = 'api.electricimp.com';
@ElectricImpSampleCode
ElectricImpSampleCode / accesstokens.js
Last active September 18, 2017 17:19
impCentral API Example Code: Working with Access Tokens
// CONSTANTS
// Replace the 'USERNAME' and 'PASSWORD' values with your own
const USERNAME = '...'
const PASSWORD = '...'
const API_URL = 'api.electricimp.com'
const API_VER = '/v5/'
const FILE_NAME = '.impCentralData'
// GLOBALS
var https = require('https');
@ElectricImpSampleCode
ElectricImpSampleCode / pagination.js
Last active September 21, 2017 09:29
impCentral API Example Code: Data Pagination
// CONSTANTS
// Replace the 'USERNAME' and 'PASSWORD' values with your own
// Replace the 'ACCESS_TOKEN' value with one retrieved using 'products.js' at
// https://gist.github.com/ElectricImpSampleCode/f0fb7f8bd04be009beeb5ee86dbd406a
const USERNAME = '...'
const PASSWORD = '...'
const ACCESS_TOKEN = '...'
const API_URL = 'api.electricimp.com'
const API_VER = '/v5/'
@ElectricImpSampleCode
ElectricImpSampleCode / undevices.js
Last active September 21, 2017 09:29
impCentral API Example Code: Listing Unassigned Devices
// CONSTANTS
// Replace the 'USERNAME' and 'PASSWORD' values with your own
// Replace the 'ACCESS_TOKEN' value with one retrieved using 'products.js' at
// https://gist.github.com/ElectricImpSampleCode/f0fb7f8bd04be009beeb5ee86dbd406a
const USERNAME = '...'
const PASSWORD = '...'
const ACCESS_TOKEN = '...'
const API_URL = 'api.electricimp.com'
const API_VER = '/v5/'
@ElectricImpSampleCode
ElectricImpSampleCode / upload.js
Last active September 21, 2017 09:29
impCentral API Example Code: Uploading Device and Agent Code
// CONSTANTS
// Replace the 'USERNAME' and 'PASSWORD' values with your own
// Replace the 'ACCESS_TOKEN' value with one retrieved using 'products.js' at
// https://gist.github.com/ElectricImpSampleCode/f0fb7f8bd04be009beeb5ee86dbd406a
const USERNAME = '...'
const PASSWORD = '...'
const ACCESS_TOKEN = '...'
const API_URL = 'api.electricimp.com'
const API_VER = '/v5/'
@ElectricImpSampleCode
ElectricImpSampleCode / products.js
Last active January 17, 2020 11:38
impCentral API Example Code: Retrieve Products and their Device Groups
// CONSTANTS
// Replace the 'USERNAME' and 'PASSWORD' values with your own
const USERNAME = '...'
const PASSWORD = '...'
const API_URL = 'api.electricimp.com'
const API_VER = '/v5/'
// GLOBALS
var https = require('https');
var products = [];
@ElectricImpSampleCode
ElectricImpSampleCode / ssd1306a.class.nut
Last active August 10, 2017 23:30
Squirrel Class to control Adafruit SSD1306-based 0.96in 128 x 32/64 OLED
// Constants for the OLED and the SSD1306
const SSD1306_SETCONTRAST = "\x81";
const SSD1306_DISPLAYALLON_RESUME = "\xA4";
const SSD1306_DISPLAYALLON = "\xA5";
const SSD1306_NORMALDISPLAY = "\xA6";
const SSD1306_INVERTDISPLAY = "\xA7";
const SSD1306_DISPLAYOFF = "\xAE";
const SSD1306_DISPLAYON = "\xAF";
const SSD1306_SETDISPLAYOFFSET = "\xD3";
const SSD1306_SETCOMPINS = "\xDA";
@ElectricImpSampleCode
ElectricImpSampleCode / weather.agent.nut
Last active July 21, 2017 13:37
Code for the Wireless Weather Station project 2.0
// WEATHER UPDATE CLASS
#require "Darksky.class.nut:1.0.1"
const REFRESH_TIME = 900;
// AGENT FUNCTIONS
function sendForecast(unusedValue) {
request = weather.forecastRequest(myLongitude, myLatitude);
request.sendasync(forecastHandler);
}
@ElectricImpSampleCode
ElectricImpSampleCode / poststream.agent.nut
Last active June 6, 2017 12:28
Electric Imp imp API http.poststream() example
// CONSTANTS
const PLOTLY_USERNAME = "<your_username>";
const PLOTLY_KEY = "<your_key>";
const PLOTLY_TOKEN = "<your_token>";
// GLOBAL VARIABLES
// 'stream' will hold the httpstream object we create in initiateStream()
stream <- null;
dataCount <- 0;