Skip to content

Instantly share code, notes, and snippets.

@LarsBergqvist
LarsBergqvist / receiver_to_file.py
Created March 20, 2016 17:37
receiver_to_file
# Python 2.7.9
# Uses pi_switch from https://github.com/lexruee/pi-switch-python
# See pi_switch readme for details on setup
from pi_switch import RCSwitchReceiver
import time
import csv
receiver = RCSwitchReceiver()
receiver.enableReceive(2)
@LarsBergqvist
LarsBergqvist / LegoServoCar.ino
Last active March 26, 2016 22:11
LegoServoCar
// ---------------------------------------------------------------------------
// Sketch for a Lego car with two servos (with continuous rotation) for left
// and right wheel and an SR04 ultra sonic sensor for measuring the distance to
// objects in front of the car
// ---------------------------------------------------------------------------
#include <NewPing.h>
#include <Servo.h>
//
// SR04 distance sensor setup
@LarsBergqvist
LarsBergqvist / aRest_HuzzahRelay.ino
Last active March 27, 2016 20:06
Using an Adafruit Feather Huzzah to control relays via aRest
/*
* This is an example sketch on using aREST with an Adafruit Feather Huzzah board
* The sketch starts a web server and handles requests as REST calls via aREST
* The board uses two relays on pins 12 and 13 that can be toggled via the REST API
* Examples:
* HuzzahIP/digital/12 -> returns the state of relay 1
* HuzzahIP/digital/13 -> returns the state of relay 2
* HuzzahIP/digital/12/0 -> turns relay 1 off
* HuzzahIP/digital/12/1 -> turns relay 1 on
* HuzzahIP/digital/13/0 -> turns relay 2 off
@LarsBergqvist
LarsBergqvist / Adafuit_IO_REST_setup_and_loop.ino
Created April 11, 2016 05:42
Adafuit_IO_REST_setup_and_loop
void setup()
{
setupWiFi();
aio.begin();
dht.begin();
float h = dht.readHumidity();
float t = dht.readTemperature();
@LarsBergqvist
LarsBergqvist / Adafruit_IO_REST_send_data.ino
Last active April 11, 2016 08:43
Adafruit_IO_REST_send_data
void sendDataToAdafruitIO(float temperature, float humidity)
{
unsigned long startTime = millis();
if (isnan(temperature) || isnan(humidity))
{
Serial.println("Failed to read from DHT sensor!");
return;
}
@LarsBergqvist
LarsBergqvist / Adafruit_IO_MQTT_send_data.ino
Last active April 11, 2016 08:43
Adafruit_IO_MQTT_send_data
void sendDataToAdafruitIO(float temperature, float humidity)
{
unsigned long startTime = millis();
if (isnan(temperature) || isnan(humidity))
{
Serial.println("Failed to read from DHT sensor!");
return;
}
@LarsBergqvist
LarsBergqvist / remotecontrol.py
Last active May 15, 2016 12:22
A Flask web api for controlling RC outlets
from flask import Flask, jsonify, request
from outletdefinitions import outlets
import codesender
app = Flask(__name__)
@app.route("/Outlets/api/outlets", methods=["GET"])
def get_outlets():
return jsonify({"outlets" : outlets})
@LarsBergqvist
LarsBergqvist / codesender.py
Created May 15, 2016 07:14
Helper method for sending codes with pi-switch
import pi_switch
byte0codeON = 0x55
byte0codeOFF = 0x54
byte2 = 0x15 #This is group 1
buttonToIDCodesMap = {
1: 0x15,
2: 0x45,
3: 0x51,
@LarsBergqvist
LarsBergqvist / outletdefinitions.py
Last active May 15, 2016 12:23
outletdefinitions.py
outlets = [
{"id":"1","name":"Spotlights"},
{"id":"2","name":"Stereo"},
{"id":"3","name":"Table lamp"},
{"id":"4","name":"Floor lamp"}
]
@LarsBergqvist
LarsBergqvist / rendertemplate.py
Created May 15, 2016 07:22
rendertemplate.py
from flask import render_template
@app.route("/Outlets/",methods=["GET"])
def index():
return render_template("index.html")