Skip to content

Instantly share code, notes, and snippets.

@jamesbulpin
jamesbulpin / Program.cs
Created Mar 15, 2019
Quick test of a MQTT client to control PowerPoint slides
View Program.cs
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 Mar 13, 2019
Simple Python HTTP server that provides an API to turn Fitbit watch orientation data into commands to a pan-tilt unit
View server.py
import SocketServer
import SimpleHTTPServer
import math
import json
import pantilthat
pantilthat.pan(0)
pantilthat.tilt(0)
PORT = 9090
@jamesbulpin
jamesbulpin / face.py
Created Mar 13, 2019
Simple (and fairly crap) face tracker for Raspberry Pi with a pan-tilt hat.
View face.py
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 Dec 19, 2018
Sketch for the Christmas countdown bauble
View bauble.ino
// 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 Dec 10, 2018
#IoTree MQTT version
View ws2811v2.js
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 Nov 25, 2018
Alexa skill definition for Cambridge bin collection query
View skill.json
{
"interactionModel": {
"languageModel": {
"invocationName": "my house",
"intents": [
{
"name": "AMAZON.CancelIntent",
"samples": []
},
{
@jamesbulpin
jamesbulpin / lambda_function.py
Created Nov 25, 2018
Alexa skill handler for Cambridge bin collection query
View lambda_function.py
# 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,
View package.json
{
"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"
}
}
View piaudio.js
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';
View azure-tts.js
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>";