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 / WifiTimezone.agent.nut
Last active July 24, 2016 01:57
WifiTimezone class - Requests the imp to scan for wifi networks, sends that data to Mozilla to geolocate the imp, sends that data to timezonedb to collect timezone data.
// -----------------------------------------------------------------------------
// WifiTimezone class
//
// Requests the imp to scan for wifi networks, sends that data to Google Maps to
// geolocate the imp, sends that data to Google Maps to collect timezone data
//
class WifiTimezone {
@blindman2k
blindman2k / README.md
Last active August 29, 2015 14:00
Hexdump is a function to output binary data in a hex + text format on a serial port.

Hexdump

This function will dump a blob or string as a hexdump to a serial port.

The input looks like this:

hexdump("RECV", "Hello world\n", "uart57");

The output (with a more complex input!) will look like this:

@blindman2k
blindman2k / README.md
Last active August 29, 2015 14:00
Squirrel port of the BlueGiga BLE112 BGLib using BGAPI running on an Electric Imp device.

BGLib for Squirrel

This implements the BGLib library for Bluegiga's BLE112 Bluetooth Smart module.

It assumes you have connected from the Imp to the BLE112:

  • UART (uart1289 is recommended as flow control is important)
  • Wake pin (optional depending on BLE112 configuration)
  • Reset pin (optional but really helpful as software reset is not always reliable)
@blindman2k
blindman2k / persist.agent.nut
Created April 26, 2014 05:14
Agent persistent storage class
class Persist {
cache = null;
// -------------------------------------------------------------------------
function read(key = null, def = null) {
if (cache == null) {
cache = server.load();
}
return (key in cache) ? cache[key] : def;
@blindman2k
blindman2k / persist.agent.nut
Created April 26, 2014 05:14
Agent persistent storage class
class Persist {
cache = null;
// -------------------------------------------------------------------------
function read(key = null, def = null) {
if (cache == null) {
cache = server.load();
}
return (key in cache) ? cache[key] : def;
@blindman2k
blindman2k / uart_gateway.agent.nut
Last active August 29, 2015 14:00
Imp gateway demo - communicate with a line-oriented UART device through a web interface
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'>
<title>Imp Gateway Demo</title>
// =============================================================================
const NUMPIXELS = 24;
class NeoPixels {
// when instantiated, the neopixel class will fill this array with blobs to
// represent the waveforms to send the numbers 0 to 255. This allows the blobs to be
// copied in directly, instead of being built for each pixel - which makes the class faster.
bits = null;
@blindman2k
blindman2k / strtodate.nut
Created March 15, 2014 08:27
strtodate populates a date() table with the time represented by a string (and a timezone offset)
//
// strtodate populates a date() table with the time represented by a string (and a timezone offset)
// Note it is a very rigid date format. It is an exercise for the reader to expand/adapt the format to their needs.
//
function strtodate(str, tz=-300) {
// Capture the components of the date time string
local ex = regexp(@" ([a-zA-Z]+) ([0-9]+), ([0-9]+) ([0-9]+):([0-9]+) ([AP]M)");
local ca = ex.capture(str);
if (ca.len() != 7) throw "We are currently expecting, exactly, this format: 'Tuesday, January 7, 2014 9:57 AM'";
@blindman2k
blindman2k / agent_ping.agent.js
Last active December 24, 2015 00:59
The device pings the agent every second. If it misses a pong response it turns on the light for at least 10 seconds.
device.on("ping", function(ping) {
device.send("pong", ping);
})
server.log("Agent started")
// RGB sensor code, stripped to basics, to get initialization working...
const i2c_ioexp = 0x7C; // I2C channel base adddreses
const i2c_als = 0xE8; // adjusted to 8 bit values
// Initialise the imp hardware
local i2c = hardware.i2c89;
i2c.configure(CLOCK_SPEED_100_KHZ);
// ------------------------------------------------ rgbdcs register definitions -----------------------------------------------------
const rgbdcsRED = 0; const rgbdcsGREEN = 1; const rgbdcsBLUE = 2; const rgbdcsCLEAR = 3;