Skip to content

Instantly share code, notes, and snippets.

@jamesbulpin
jamesbulpin / lambda.py
Created December 22, 2016 15:12
AWS Lambda code for Alexa skill handler for WS2811 control via Octoblu
from __future__ import print_function
import urllib
import urllib2
octoblu_trigger = "https://triggers.octoblu.com/v2/flows/3791898c-6234-4c57-a860-92a8e6c616fc/triggers/6b5c0082-37ab-459b-9912-8228ccb43a15"
# --------------- Helpers that build all of the responses ----------------------
def build_speechlet_response(output):
return {
@jamesbulpin
jamesbulpin / ws2811.js
Created December 22, 2016 15:18
Second version of an Octoblu-connected WS2811 LED string driver. Adds corodinate-based patterns and dot-matrix message display.
var ws281x = require('rpi-ws281x-native');
var meshblu = require('meshblu');
var meshbluJSON = require("./meshblu.json");
var tinycolor = require("tinycolor2");
var mic = require('microphone');
var VUMeter = require('vu-meter')
var mqtt = require('mqtt');
var font5x7 = require('./font.js');
var fs = require('fs');
try {
@jamesbulpin
jamesbulpin / hama.py
Created November 11, 2017 10:58
Prototype IR control to MQTT gateway
import os
import signal
import uuid
import threading
import sys
import time
import datetime
import subprocess
import paho.mqtt.client as mqtt
import evdev
@jamesbulpin
jamesbulpin / index.js
Created November 23, 2017 22:48
Azure Function to publish a message to my local MQTT broker via Azure IoT Hub
var Client = require('azure-iothub').Client;
var Message = require('azure-iot-common').Message;
function printResultFor(op) {
return function printResult(context, err, res) {
context.log('printResult for ' + op);
if (err) context.log(op + ' error: ' + err.toString());
if (res) context.log(op + ' status: ' + res.constructor.name);
if (err) {
context.res = {
{
"dependencies": {
"azure-iothub": "^1.1.17",
"azure-iot-common": "^1.2.0"
}
}
@jamesbulpin
jamesbulpin / index.js
Created November 23, 2017 23:09
Azure Function to handle device-to-cloud messages
var request = require('request');
function jrbHomeAutomation(context, event) {
context.log("jrbHomeAutomation event " + JSON.stringify(event));
if ((event.topic) && (event.message)) {
switch (event.topic) {
case "Alert":
request({
url: "<logic app trigger URL>",
@jamesbulpin
jamesbulpin / xmas.js
Created December 15, 2017 20:28
Simple Azure IoT client to relay messages to an Arduino via serial-over-USB
var SerialPort = require("serialport");
var clientFromConnectionString = require('azure-iot-device-amqp').clientFromConnectionString;
var tinycolor2 = require("tinycolor2");
var connectionString = "<IoT Hub connection string>";
var portdev = "/dev/ttyACM0";
var port = new SerialPort(portdev, {
baudRate: 9600,
});
@jamesbulpin
jamesbulpin / xmasjumper.ino
Created December 17, 2017 10:30
Arduino sketch to drive WS281x LEDs as part of my Christmas jumper project
#include <Adafruit_NeoPixel.h>
#define WS2811_PIN 6
#define WS2811_LED_COUNT 20
// Set to true to flash the LEDs on and off at approx 1Hz
boolean flash = false;
// The target color for the LED string, indexed by LED number
int target_r[WS2811_LED_COUNT];
@jamesbulpin
jamesbulpin / index.js
Created December 17, 2017 12:08
Azure Function code for a demo Alexa Skill handler for the Christmas Jumper project
// Alexa skill handler for the "Citrix" demo skill.
//
// This runs as an Azure Function and must have the NPM libraries installed into the
// Function App image: ensure that package.json is populated with the required
// dependencies and follow the instructions at
// https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-node#node-version-and-package-management
//
// Example package.json:
// {
// "dependencies": {
@jamesbulpin
jamesbulpin / xmas.js
Created December 19, 2017 17:34
Node.js program to update LEDs via a serial-over-USB connected Arduino for my Christmas Jumper project
var SerialPort = require("serialport");
var tinycolor2 = require("tinycolor2");
var request = require('request');
var portdev = "/dev/ttyACM0";
var port = new SerialPort(portdev, {
baudRate: 9600,
});
port.on('error', function(err) {