Skip to content

Instantly share code, notes, and snippets.

@matbor
matbor / subscribetotopic.html
Created February 6, 2014 03:29
Simply connects to a mqtt broker that is running websockets, subscribes to the topics and displays the messages in the console. Requires mqttws31.js to work. Get it from http://git.eclipse.org/c/paho/org.eclipse.paho.mqtt.javascript.git/tree/src
<html>
<title>Test subcriber</title>
<head>
<script src="vendor/mqttws31.js" type="text/javascript"></script>
<script type="text/javascript">
//mqtt broker setup
@matbor
matbor / Wemo-switch-v2.py
Last active December 29, 2015 05:39
Belkin Wemo discover switches and automatically subscribe to events. Needs the https://github.com/iancmcc/ouimeaux library to work.
import datetime
from ouimeaux.environment import Environment
def on_switch(switch): #discover light switches and register listeners
print('******** Switch found:'+ switch.name+ ', Current state : '+str(switch.get_state()))
x = switch.name.replace(" ", "") #remove spaces
x = env.get_switch(switch.name)
x.register_listener(on_change)
def on_change(value):
@matbor
matbor / switch.py
Last active December 28, 2015 22:59
testing wemo ouimeaux script to get the state of my belkin wemo device
from ouimeaux.environment import Environment
def on_switch(switch):
print ('******** Switch found:', switch.name)
def on_change(value):
print('******** light has changed state and has been switched!')
env = Environment(switch_callback=on_switch, with_cache=False)
@matbor
matbor / sabnzbd.py
Created October 28, 2013 22:19 — forked from kylef/sabnzbd.py
import urllib, json
class SABnzbd(object):
"""
Usage:
>>> from sabnzbd import SABnzbd
>>> s = SABnzbd('sakar.local', 8080, '4488f2881b90d7753bef8fb9e1bc56b3')
>>> s.pause() # Pauses the downloads
>>> s.shutdown() # Shut's down SABnzbd+
"""
@matbor
matbor / lwtnotfy.py
Created October 25, 2013 11:34
last will and testament notify when one of them goes offline. for MQTT.
#!/usr/bin/python
#
# October 2013
# Subscribes to multiple topics (and will also block sub-topics, based on keywords) and if it see's the work
# 'offline' it sends a notification to the pushingbox topic. Mainly using this to track if a program goes offline
#
# by Matthew Bordignon / @bordignon
#
@matbor
matbor / DistanceLatLon.py
Last active December 26, 2015 12:39
Handy example for working out distance between two sets of latitude and longitude points.... The start of a geo fence!
import math
def distance_on_unit_sphere(lat1, long1, lat2, long2):
# modified by Matthew Bordignon @bordignon Oct 2013
#
# handy example for finding distance between two sets of co-oridinates
# modified from http://www.johndcook.com/python_longitude_latitude.html
# handy tool to chk calculations, http://www.johndcook.com/lat_long_distance.html
# Convert latitude and longitude to
# spherical coordinates in radians.
@matbor
matbor / Distance.py
Created October 5, 2013 07:21
Simple python script to find the line of sight distance between two sets of latitude and longitude points. Will modified later for geofencing with mqttitude.org backend server.
import math
def distance_on_unit_sphere(lat1, long1, lat2, long2):
# by Matthew Bordignon @bordignon Oct 2013
#
# handy example for finding distance between two sets of co-oridinates
# modified from http://www.johndcook.com/python_longitude_latitude.html
# Convert latitude and longitude to
# spherical coordinates in radians.
degrees_to_radians = math.pi/180.0
@matbor
matbor / mqttitude-gmaps.html
Last active January 6, 2017 17:15
To be used with the http://mqttitude.org/ project, mqtt broker, websockets and google maps. Subscribes to a topic and plots the mqttitude in realtime using websockets. NOTE: you need a google map api.
<!DOCTYPE html>
<html>
<head>
<script src="http://maps.googleapis.com/maps/api/js?key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&sensor=false"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>
<script src="mqttws31.js" type="text/javascript"></script>
<TITLE>MQTTitude - find my family & friends</title>
<style type="text/css">
@matbor
matbor / gauge-mqtt-websockets.html
Created September 25, 2013 12:31
Steelseries gauge displaying temperature live using websockets from a mqtt/mosquitto broker.
<head>
<title>Testing Temp Gauge</title>
</head>
<body onload="init();">
<canvas id=gaugeCanvas width=200 height=200>No canvas in your browser...sorry...</canvas>
</body>
<script type="text/javascript" src="mosquitto-1.1.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type=text/javascript src=http://dl.dropbox.com/u/128855213/SteelSeries/tween-min.js></script>
<script type=text/javascript src=http://dl.dropbox.com/u/128855213/SteelSeries/steelseries-min.js></script>
@matbor
matbor / getlocations.php
Created September 13, 2013 04:39
Mysql -> Google Maps for mqttitude (using my mysql script). You need to add your google api key below to make it work.
<?php
$conn = mysql_connect("thebeast.localdomain", "root", "") or die(mysql_error());
mysql_select_db("mqtt") or die(mysql_error());
?>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google Maps</title>
<style type="text/css">