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:
// ----------------------------------------------------------------------------- | |
// 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 { | |
This implements the BGLib library for Bluegiga's BLE112 Bluetooth Smart module.
It assumes you have connected from the Imp to the BLE112:
class Persist { | |
cache = null; | |
// ------------------------------------------------------------------------- | |
function read(key = null, def = null) { | |
if (cache == null) { | |
cache = server.load(); | |
} | |
return (key in cache) ? cache[key] : def; |
class Persist { | |
cache = null; | |
// ------------------------------------------------------------------------- | |
function read(key = null, def = null) { | |
if (cache == null) { | |
cache = server.load(); | |
} | |
return (key in cache) ? cache[key] : def; |
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; | |
// | |
// 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'"; | |
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; |