Skip to content

Instantly share code, notes, and snippets.

@LarsBergqvist
LarsBergqvist / index.html
Created May 15, 2016 07:25
Remote control front end
<!DOCTYPE html>
<html ng-app="myApp" style="height: 100%">
<head>
<script data-require="[email protected]" data-semver="1.4.8" src="https://code.angularjs.org/1.4.8/angular.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/css/bootstrap.css" />
<script src="/static/Controller.js"></script>
</head>
<body style="height: 100%">
@LarsBergqvist
LarsBergqvist / Controller.js
Created May 15, 2016 12:24
AngularJS controller for rc outlet web app
var myApp = angular.module('myApp', []);
myApp.controller('OutletController', ['$scope', '$http', function($scope, $http) {
$scope.header = 'Outlets';
var getOutletInfo = function() {
$http.get("api/outlets").then(function(response) {
var outlets = response.data.outlets;
$scope.outlets = outlets;
@LarsBergqvist
LarsBergqvist / remotecontrol.sh
Created June 18, 2016 11:39
init file for remotecontrol service on Raspbian
#!/bin/sh
# from http://blog.scphillips.com/posts/2013/07/getting-a-python-script-to-run-in-the-background-as-a-service-on-boot/
### BEGIN INIT INFO
# Provides: remotecontrol
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: A service for a web server that handles remote controlled outles
@LarsBergqvist
LarsBergqvist / subscriber.py
Last active March 1, 2018 06:02
paho mqtt subscriber example
import paho.mqtt.client as mqtt
def on_connect(client, userdata, flags, rc):
print("Connected with result code "+str(rc))
client.subscribe("Hellos/+")
def on_message(client, userdata, msg):
print(msg.topic+" "+str(msg.payload))
client = mqtt.Client()
@LarsBergqvist
LarsBergqvist / arduinomqtt.ino
Created June 22, 2016 19:58
Example on Arduino-MQTT usage for setting up an ESP8266 board as an MQTT client
//
// This is a minimal example on MQTT publish and subscribe
// from an ESP8266 board to an MQTT broker (I have used a local Mosquitto running on a Raspberry Pi)
// This example uses the Arduino-MQTT library (https://github.com/256dpi/arduino-mqtt)
// Install it in the Arduino IDE before compiling the sketch
#include <ESP8266WiFi.h>
#include <MQTTClient.h>
#include "WIFI_and_broker_parameters.h"
@LarsBergqvist
LarsBergqvist / ESP8266_PubSub.ino
Last active February 13, 2017 17:58
An example on using PubSub client for publishing and subscribing data from an ESP8266 board via a locally hosted Mosquitto broker
//
// This is a minimal example on MQTT publish and subscribe from an ESP8266 board
// to an MQTT broker (I have used a local Mosquitto running on a Raspberry Pi)
// This example uses the PubSub client library (https://github.com/knolleary/pubsubclient)
// Install it in the Arduino IDE before compiling the sketch
#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include "WIFI_and_broker_parameters.h"
@LarsBergqvist
LarsBergqvist / GarageClient.ino
Last active September 6, 2018 19:56
MQTT publish of data from two DHT22 sensors
//
// This is an example on MQTT publish from an ESP8266 board
// to an MQTT broker (I have used a local Mosquitto running on a Raspberry Pi)
// This example uses the PubSub client library (https://github.com/knolleary/pubsubclient)
// Install it in the Arduino IDE before compiling the sketch
// Sensor values are fetched from an indoor DHT22 sensor and an outdoor DHT22 sensor
#include <ESP8266WiFi.h>
#include <PubSubClient.h>
@LarsBergqvist
LarsBergqvist / subscriber.py
Last active March 1, 2018 06:03
MQTT subscriber client that listens to all messages within "Home"
import paho.mqtt.client as mqtt
import datetime
def on_connect(client, userdata, flags, rc):
print("Connected with result code "+str(rc))
client.subscribe("Home/#")
def on_message(client, userdata, msg):
print(str(datetime.datetime.now()) + ": " + msg.topic + " " + str(msg.payload))
@LarsBergqvist
LarsBergqvist / GroundFloorClient.ino
Created June 24, 2016 13:37
Arduino loop of ESP8266 board that measure temperature, humidity and soilmoisture
void loop()
{
if ( firstTime || (millis() - lastTime > SECONDS_BETWEEN_MEASUREMENTS*1000) )
{
firstTime = false;
lastTime = millis();
if (!mqttClient.connected())
{
connectToWiFiAndBroker();
@LarsBergqvist
LarsBergqvist / subscriber_mongodb.py
Last active October 9, 2022 12:42
An MQTT subscriber client that persists data in a MongoDB database
#!/usr/bin/env python3
import paho.mqtt.client as mqtt
import datetime
from pymongo import MongoClient
def on_connect(client, userdata, flags, rc):
print("Connected with result code "+str(rc))
client.subscribe("Home/#")