Skip to content

Instantly share code, notes, and snippets.

@jamesbulpin
jamesbulpin / gist:8ee829cc918a58a017ffeff68b6397e5
Created September 6, 2016 14:29
Simple LightwaveRF Octoblu connector
var meshblu = require('meshblu');
var meshbluJSON = require("./meshblu.json");
var LightwaveRF = require("lightwaverf");
// Specifies how you want your message payload to be passed
// from Octoblu to your device
var MESSAGE_SCHEMA = {
type: 'object',
properties: {
roomNumber: {
@jamesbulpin
jamesbulpin / lwrf.js
Created September 8, 2016 18:37
Control LightwaveRF lights based on MQTT messages
var LightwaveRF = require("lightwaverf");
var mqtt = require('mqtt');
var config_lwrf = require("../config/config_lwrf.js");
var lw = new LightwaveRF({ip:"10.52.2.118"});
function LWRFController(lw) {
this.timeout = 100;
this.queue = [];
this.ready = true;
@jamesbulpin
jamesbulpin / calendar.js
Created September 8, 2016 18:42
Process events from a Google calendar to create MQTT messages for lighting control etc.
var fs = require('fs');
var readline = require('readline');
var google = require('googleapis');
var googleAuth = require('google-auth-library');
var S = require('string');
var schedule = require('node-schedule');
var mqtt = require('mqtt');
// Based on sample code from https://developers.google.com/google-apps/calendar/quickstart/nodejs
@jamesbulpin
jamesbulpin / gist:bdfae2113b40ebdad7f8106c3f242a95
Created September 28, 2016 20:59
An AWS Echo "skill adapter" Lambda function to route lighting control requests to Octoblu via a POST trigger
import urllib
import urllib2
octoblu_trigger = "https://triggers.octoblu.com/v2/flows/<your flow>/triggers/<your trigger>
def lambda_handler(event, context):
access_token = event['payload']['accessToken']
if event['header']['namespace'] == 'Alexa.ConnectedHome.Discovery':
return handleDiscovery(context, event)
@jamesbulpin
jamesbulpin / lwrf433rx.ino
Created October 9, 2016 15:43
Arduino firmware to decode LightwaveRF 433.92MHz messages received via a simple receiver module.
#define BAUD_RATE 57600
// Receiver state
bool lastValue = LOW;
unsigned long last = -1;
const unsigned int upperThreshold = 70; //upper threshold value
const unsigned int lowerThreshold = 50; //lower threshold value
// Decoder state
#define MAX_REPS 64
@jamesbulpin
jamesbulpin / 433listener.py
Created October 9, 2016 15:45
A proxy that forwards MQTT messages received over Arduino USB serial to a MQTT broker - designed to be used as part of a Kodi add-on
#!/usr/bin/python
import threading
import time
import glob
import os
import os.path
import signal
import sys
import Queue
@jamesbulpin
jamesbulpin / lwrf433.py
Created October 9, 2016 15:47
A Kodi add-on main script to spawn a Arduino->MQTT proxy
#!/usr/bin/python
import os
try:
import xbmc
import xbmcaddon
except ImportError, e:
import time
class xbmc:
class Monitor:
@jamesbulpin
jamesbulpin / test.js
Created October 12, 2016 00:52
*Really* rough prototype Octoblu connector to drive a USBMicro U421 device connected to a novelty button
var meshblu = require('meshblu');
var meshbluJSON = require("./meshblu.json");
// meshblu.json must contain the UUID and token for a generic device created
// within Octoblu: {"server":"meshblu.octoblu.com","port":80,"uuid":"56<redacted>c0","token":"93<redacted>42"}
// Specifies how you want your message payload to be passed
// from Octoblu to your device
var MESSAGE_SCHEMA = {
type: 'object',
@jamesbulpin
jamesbulpin / billybass.ino
Created November 20, 2016 13:38
Arduino sketch to control the motors in a Big Mouth Billy Bass novelty animatronic fish.
const long DEBOUNCE_DELAY = 50;
const long TRIGGER_PULSE = 50;
const int PIN_MOTOR_MOUTH = 10;
const int PIN_MOTOR_HEAD = 9;
const int PIN_MOTOR_TAIL = 11;
const int PIN_CMD_MOUTH = 1;
const int PIN_CMD_HEAD = 2;
const int PIN_CMD_TAIL = 0;
@jamesbulpin
jamesbulpin / piaudio.js
Created November 20, 2016 15:49
A simple Meshblu connector to play base64 encoded mp3 and drive a Big Mouth Billy Bass motors.
// Put a meshblu.json file in the same directory as this file. This must
// contain the Meshlu device UUID and token, e.g.:
// {"server":"meshblu.octoblu.com","port":80,"uuid":"01234567-89ab-cdef-0123-456789abcdef","token":"123456789012345678901234567890"}
var meshblu = require('meshblu');
var meshbluJSON = require("./meshblu.json");
var exec = require('child_process').exec;
var tempfile = require('tempfile');
var fs = require('fs');