Skip to content

Instantly share code, notes, and snippets.

@marcboon
marcboon / round-trip-latency-xively-agent.nut
Last active December 18, 2015 06:38
Electric imp round-trip latency logger, using xively.com. It measures round-trip latency by feeding an output port back to an input port. Public feed of latency stats available at https://xively.com/feeds/220375411
// round-trip-latency-xively
// measures round-trip latency by sending inverted input back to output, log to xively.com
// [agent code]
// Xively account credentials
const MyApiKey = PRIVATE_API_KEY
const MyFeedID = "220375411"
// Class for reading/writing a feed at xively.com (formerly cosm)
class XivelyFeed {
@marcboon
marcboon / xively-shared-data-tags-agent.nut
Last active December 17, 2015 15:58
Using xively.com to share data between two or more electric imps. The imps can read and update named channels in the same feed, and notify each other after every successful update, so that data is synchronized between imps, without the need for polling. Upon start-up, every imp automatically adds a tag to the feed, containing its unique agent id…
// Xively account credentials
const MyApiKey = YOUR_API_KEY
const MyFeedID = YOUR_FEED_ID
// Class for reading/writing a feed at xively.com (formerly cosm)
class XivelyFeed {
static url = "https://api.xively.com/v2/feeds/"
apiKey = null
feedID = null
@marcboon
marcboon / MCP230xx.nut
Last active December 17, 2015 13:29
Encapsulates MCP23008 and MCP23017 family of I2C i/o expander for use with electric imp. Emulates the standard Pin class, allows easy moving of i/o from native pins to i/o expander pins. After creating one or more MCP23008 and/or MCP23017 class instances, user code should only access member functions of the MCP230xxPin class. See example at the …
// Base class for MCP23008 and MCP23017 family of I2C i/o expanders
class MCP230xx {
BASE_ADDR = 0x20
i2cPort = null
i2cAddr = null
regs = null
constructor(i2cPort, deviceAddr) {
this.i2cPort = i2cPort
this.i2cAddr = (BASE_ADDR + deviceAddr) << 1
@marcboon
marcboon / MCP23008Pin.nut
Last active December 17, 2015 11:59
Encapsulates a MCP23008 I2C i/o expander for use with electric imp. Emulates the standard Pin class, allows easy moving of i/o from native pins to i/o expander pins.
// This class is compatible with the general Pin class
class MCP23008Pin {
device = null
gpio = null
constructor(device, gpio) {
this.device = device
this.gpio = gpio
}
function configure(mode) {