Skip to content

Instantly share code, notes, and snippets.

View adoyle's full-sized avatar

Allan Doyle adoyle

View GitHub Profile
@adoyle
adoyle / mailip.py
Created October 23, 2015 18:26
Meant to be run on a Raspberry Pi to email the current IP address to yourself. Note that this uses unauthenticated SMTP and only works in certain circumstances. This lets you run a headless pi that you can ssh in to.
import smtplib
import subprocess
my_email = 'myemail@gmail.com'
to_email = 'myemail@gmail.com'
myip = subprocess.check_output(['hostname', '-I'])
msg = ("From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n") % (my_email, to_email, "IP from the Pi")
@adoyle
adoyle / raspi-init.sh
Last active April 21, 2021 11:35
Non-interactive command-line equivalents to raspi-config
# Non-interactive command-line equivalents to raspi-config
# These are not guaranteed to work under all circumstances.
# I use them in a fabric script to do unattended setup of a
# Raspberry Pi immediately after having booted up a NOOBS
# and installed Raspbian.
#
# 1. Install NOOBS
# 2. When the config screen comes up, hit TAB TAB RETURN to exit from it
# 3. Type 'sudo service ssh start' at the command line (no quotes).
# 4. (Optional) copy a public key to the pi account on the pi.
@adoyle
adoyle / robotControl.py
Created November 5, 2014 18:59
serves up foo.html and provides simple tests of motor control
from flask import Flask, render_template, request
import math, os, time, serial, time
import RPi.GPIO as GPIO
# initialize serial port
port = serial.Serial("/dev/ttyAMA0", baudrate=19200, timeout=3.0)
# wait 2 seconds
#time.sleep(2)
body {
background-color: white;
}
#control {
width: 512px; height: 512px;
background-color: #aaa;
}
@adoyle
adoyle / foo.html
Created November 5, 2014 18:56
snippet to create a single control box
<!DOCTYPE html>
<html>
<head>
<title>Light Ballet Controls</title>
<script type="text/javascript" src="./static/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="./static/foo.js"></script>
<link type="text/css" rel="stylesheet" href="./static/foo.css"/>
</head>
<body>
@adoyle
adoyle / foo.js
Last active August 29, 2015 14:08
Snippet to send motor controller requests via jQuery get()
// lock keeps requests from piling on top of each other.
// without this, you can get requests totally out of order
var lock = 0;
function mouseMove(event) {
var speed = event.pageY / 4; // Just a hack to make the control box bigger
if ( lock === 0 ) {
lock = 1;
$.get('/motors?m1s=' + speed + '&m2s=' + speed +'&m3s=' + speed,
function(data) {