Skip to content

Instantly share code, notes, and snippets.

@claws
claws / mqtt-ws-proxy
Created February 3, 2014 23:39
Simple WebSockets Proxy for a MQTT broker
# This gist demonstrates a simple method to create a WebSockets proxy for a MQTT broker.
# I use this method to provide a WebSockets interface for the Mosquitto MQTT broker.
# This lets my browser based MQTT applications to access my MQTT broker.
# I consider this approach simpler than the common alternative which is to run lighttpd
# with the mod_websocket addon which can be complex to setup.
#
# Dependencies are Python, Twisted and Autobahn.
#
# This example sets up a WebSockets server listening on localhost:9000. Messages received from
# WebSocket clients are forwarded to the MQTT broker using the endpointforward plugin provided
@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)
@cliss
cliss / organize-photos.py
Created October 6, 2013 14:43
Photo management script. This script will copy photos from "~/Pictures/iPhone Incoming" into a tree the script creates, with folders representing month and years, and photo names timestamped. Completely based on the work of the amazing Dr. Drang; see here: http://www.leancrew.com/all-this/2013/10/photo-management-via-the-finder/ You can see more…
#!/usr/bin/python
import sys
import os, shutil
import subprocess
import os.path
from datetime import datetime
######################## Functions #########################
@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>
#!/usr/bin/env python
import mosquitto
import ssl
def on_connect(mosq, userdata, rc):
print("Connect: rc: "+str(rc))
def on_message(mosq, userdata, msg):
print "%s (qos=%s, r=%s) %s" % (msg.topic, str(msg.qos), msg.retain, str(msg.payload))
@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">
@matbor
matbor / mqttitudeTOmysql.py
Last active September 3, 2022 13:32
Simple Python script (v2.7x) that subscribes to a MQTT broker topic and inserts the data into a mysql database for later querying. This is designed to be used with the http://mqttitude.org/
#!/usr/bin/env python
# September 2013
# by Matthew Bordignon, @bordignon on Twitter
#
# Simple Python script (v2.7x) that subscribes to a MQTT broker topic and inserts the topic into a mysql database
# This is designed for the http://mqttitude.org/ project backend
#
import MySQLdb
import mosquitto
@matbor
matbor / 00readme.md
Last active April 23, 2017 18:03
Onewire Temperatures to mqtt broker server.Have modified the onewire example program so that no mater how many sensors u have plugged in it will always publish each reading to my MQTT broker server. It will use the onewire sensor ROM ID as part of the topic, ie. /house/arduino/[DEVICE ID/temperature/current and the message payload will be the Ce…