Skip to content

Instantly share code, notes, and snippets.

View blindman2k's full-sized avatar

Aron Steg blindman2k

  • Launch Systems Pty Ltd
  • Melbourne, Australia
View GitHub Profile
@blindman2k
blindman2k / README.md
Last active August 29, 2015 14:18
Impeeduino (Arduino/Imp hybrid) audio spectrum display. https://youtu.be/C84TlH6OFyE

This was the result of a fun hackathon project at Electric Imp. I turned a NeoPixel ring and an Impeeduino (Arduino and Imp hybrid) into a basic audio spectrum display. The video can be seen on YouTube.

  1. The arduino code is responsible for reading audio data from the microphone, running a fast fourier transform on the data captured to product a spectrum and then handing it off to the Imp device code via UART.
  2. The agent code is responsible only for assisting with the programming of new Arduino code and could be done with the Arduino IDE directly.
  3. The device code is responsible for reading the spectrum data and displaying the animation on the NeoPixels.

This code is provided without warantee or support because I can't remember much about it.

@blindman2k
blindman2k / README.md
Last active August 29, 2015 14:15
Demonstration of some different ways of authenticating a http request using a static shared key.

Securing Electric Imp agents acting as API providers

There are a myriad of different ways to secure requests to agent URLs. By default, all requests have three simple security features:

  1. the unique URL for each device is randomly generated during the BlinkUp process;
  2. the commands required to activate the agent are unknown to anyone but the developers; and
  3. all requests to https://agent.electricimp.com are SSL encrypted which prevents anyone from sniffing the contents of any request.

For many applications, this encryption plus obfuscation is sufficient security, especially if the requests to the agent are coming from a server or a controlled application. If further security/obfuscation is required we propose a few simple and common methods here. These methods also provide a bonus feature that, if the security is compromised at any point in the future, the parameters can be easily changed to reassert the security.

/* 9 Degrees of Freedom Sensor Tail Firmware
* Uses LSM9DS0 IMU from ST
* http://www.adafruit.com/datasheets/LSM9DS0.pdf
*/
const XM_ADDR = 0x3C; // 8-bit I2C Student Address for Accel / Magnetometer
const G_ADDR = 0xD4; // 8-bit I2C Student Address for Angular Rate Sensor
const READING_INTERVAL = 1; // seconds between readings
/* CLASS AND GLOBAL FUNCTION DEFINITIONS ------------------------------------ */
/* Environmental Sensor Tail Firmware
* Ambient Light Sensor: APDS-9007-020 (http://www.avagotech.com/docs/AV02-0512EN)
* Air Pressure Sensor: LPS25HTR (http://www.st.com/web/en/resource/technical/document/datasheet/DM00066332.pdf)
* Humidity/Temp Sensor: SI7020-A10-GMR (http://www.silabs.com/Support%20Documents/TechnicalDocs/Si7020.pdf)
*/
const LPS25H_ADDR = 0xB8; // 8-bit I2C Student Address for LPS25HTR
const SI7020_ADDR = 0x80; // 8-bit I2C Student Address for SI7020
const ALS_RLOAD = 47000.0; // load resistor value on ALS
const READING_INTERVAL = 3; // seconds between readings
@blindman2k
blindman2k / meeting_minder.agent.nut
Last active August 29, 2015 14:10
Meeting minder using the latest Google Calendar API for PHP.
//------------------------------------------------------------------------------------------------
const CALENDAR_URL = "http://devious-dorris.gopagoda.com/meeting_minder";
const REFRESH_TIME = 60; // Once a minute
SESSION_TOKEN <- "token" in server.load() ? server.load().token : "";
// server.log(SESSION_TOKEN);
function check_calendar(reschedule = true) {
local headers = {};
headers["X-GCal-Session-Token"] <- SESSION_TOKEN;
@blindman2k
blindman2k / tempbug.agent.nut
Created October 8, 2014 00:29
Simple Nora temp bug which records and displays temperature and humidity graphs.
// -----------------------------------------------------------------------------
const html = @"
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<meta name='viewport' content='width=device-width, initial-scale=1'>
@blindman2k
blindman2k / number_format.nut
Created August 22, 2014 18:13
A handy utility function for formatting a number (integer or float) with a specified number of decimal places and commas at the thousand places.
function number_format(num, decimals=null, separator=",") {
// Fix the decimals
if (decimals == null) {
if (typeof num == "string") decimals = 0;
else if (typeof num == "integer") decimals = 0;
else if (typeof num == "float") decimals = 2;
else return num;
}
// Check we have a number or convert to one if required
if (typeof num == "string") {
@blindman2k
blindman2k / httpplus.agent.nut
Created July 23, 2014 00:07
HTTPPlus is an optimised http object replacement. It adds retry and redirect support for Imp agents. It also automatically converts tables to JSON requests.
// -----------------------------------------------------------------------------
class HTTPPlus {
_http = null;
// .........................................................................
// Keep a copy of the original http object for internal use
constructor() {
_http = http;
}
@blindman2k
blindman2k / example.agent.nut
Last active August 29, 2015 14:04
This HTTPRetry class automatically retries http requests when the agent backend throttles the request with a 429 error. Use it as you would the http object.
HTTPRetry.get("http://icanhazip.com").sendasync(function(res) {
if (res.statuscode == 200) {
server.log(res.body);
} else {
server.log("Error: " + res.statuscode);
}
});
@blindman2k
blindman2k / LEDDisplay.agent.nut
Last active August 29, 2015 14:03
This is some old code we used to light up the 16x16 LED display. The image loading no longer works because we lost the PHP code which used ImageMagick to convert the JPEGs and animated GIFS into bitstreams. But the rest works fine.
// ------------------------------------------------------------------------
// Takes a string, renders it and sends it to the device for display
text <- null;
function displayText(_text) {
device.send("text", _text);
text = _text;
}
// ------------------------------------------------------------------------