Skip to content

Instantly share code, notes, and snippets.

@jamesbulpin
jamesbulpin / Program.cs
Created March 15, 2019 17:36
Quick test of a MQTT client to control PowerPoint slides
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MQTTnet;
using MQTTnet.Client;
using PPt = Microsoft.Office.Interop.PowerPoint;
using System.Runtime.InteropServices;
@jamesbulpin
jamesbulpin / server.py
Created March 13, 2019 17:35
Simple Python HTTP server that provides an API to turn Fitbit watch orientation data into commands to a pan-tilt unit
import SocketServer
import SimpleHTTPServer
import math
import json
import pantilthat
pantilthat.pan(0)
pantilthat.tilt(0)
PORT = 9090
@jamesbulpin
jamesbulpin / face.py
Created March 13, 2019 15:57
Simple (and fairly crap) face tracker for Raspberry Pi with a pan-tilt hat.
import numpy as np
import cv2
import pantilthat
import picamera
pantilthat.pan(0)
pantilthat.tilt(0)
faceCascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
camera = picamera.PiCamera()
@jamesbulpin
jamesbulpin / bauble.ino
Last active December 19, 2018 16:53
Sketch for the Christmas countdown bauble
// Christmas tree bauble countdown timer for ESP8266 with 128x32 OLED display
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266HTTPClient.h>
#include "SSD1306.h"
#include <ArduinoJson.h>
@jamesbulpin
jamesbulpin / ws2811v2.js
Created December 10, 2018 16:24
#IoTree MQTT version
var ws281x = require('rpi-ws281x-native');
var tinycolor = require("tinycolor2");
var mqtt = require('mqtt');
var font5x7 = require('./font.js');
var fs = require('fs');
try {
var xy = require('./xy.json');
}
catch (ex) {
var xy = null;
@jamesbulpin
jamesbulpin / skill.json
Created November 25, 2018 19:19
Alexa skill definition for Cambridge bin collection query
{
"interactionModel": {
"languageModel": {
"invocationName": "my house",
"intents": [
{
"name": "AMAZON.CancelIntent",
"samples": []
},
{
@jamesbulpin
jamesbulpin / lambda_function.py
Created November 25, 2018 19:17
Alexa skill handler for Cambridge bin collection query
# Set environment variable BIN_CALENDAR_URL to the specific ical calendar for your postcode
# https://refusecalendarapi.azurewebsites.net/calendar/ical/<id> where <id> can be found
# interactively using https://www.cambridge.gov.uk/check-when-your-bin-will-be-emptied
from urllib2 import urlopen
from datetime import datetime, timedelta
import os
from ask_sdk_core.skill_builder import SkillBuilder
from ask_sdk_core.dispatch_components import (
AbstractRequestHandler, AbstractExceptionHandler,
{
"dependencies": {
"azure-iot-device-amqp": "^1.3.0",
"azure-iot-device-amqp-ws": "^1.0.16",
"request": "^2.83.0",
"serialport": "^6.0.4",
"tinycolor2": "^1.4.1",
"tempfile": "^2.0.0"
}
}
var DeviceClient = require('azure-iot-device').Client
var DeviceProtocol = require('azure-iot-device-amqp').AmqpWs;
var exec = require('child_process').exec;
var tempfile = require('tempfile');
var fs = require('fs');
var SerialPort = require("serialport");
var request = require('request');
var connectionString = "HostName=[...]";
var azureCognitiveServicesAuthEndpoint = 'https://northeurope.api.cognitive.microsoft.com/sts/v1.0/issueToken';
var azureCognitiveServicesMainEndpoint = 'https://northeurope.tts.speech.microsoft.com/cognitiveservices/v1';
function azureCallApi(text, callback) {
var ssml = "<speak version='1.0' xmlns=\"http://www.w3.org/2001/10/synthesis\" xml:lang='en-US'>" +
"<voice name='Microsoft Server Speech Text to Speech Voice (en-GB, George, Apollo)'>" +
"<prosody rate=\"slow\">" +
text +
"</prosody>" +
"</voice>" +
"</speak>";