WebMention is a modern re-implementation of PingBack, which uses only HTTP and x-www-urlencoded content rather than infinitely more complicated, not to mention bloated, XMLRPC requests. It was developed by the #indieweb community at IndieWebCamp, and is rapidly seeing adoption.

Since the best way to understand a protocol is to write an implementation of it, I bashed together a basic implementation of it for Elgg.

The plugin will automatically send webmention pings for content with URLs in the $object->description field (you can easily expand on this), it also exposes a webmention endpoint, and sets the appropriate discovery headers and meta tags. Plugin authors can hook into the plugin hooks that elgg-webmention generates and handle incoming mentions appropriately.

There is still a little more to do, the next step I think is to hook into a microformats parser, in order to get some richer semantic information as to the type of mention one is generating. My friend Ben has a very neat video of this kind of thing in action, and his idno project already implements it in the core code.

Have a play!

» Visit the project on Github…

Thanks for visiting! If you found this helpful, you might be interested in knowing that I offer development and consultancy services, and am available to hire!


So, building on what I did before with lights and switches as well as the stuff I’ve been hacking together with my Home.API, I thought I’d build something that may actually be of practical use. So, here’s a device that will tell you, before you walk out the door, whether all your doors and windows are shut, and for bonus points, tell you when they were opened and closed.

As you can see from the video, my local Homebase didn’t have all the bits, so you’ll have to use your imagination a little. The “Real” version would use simple magnet + reed switch burglar alarm fittings connected with bell wire to the terminals on your Piface. An indicator panel connected on the PiFace’s output panel should sit somewhere visible by your front door.

The software, again written in python, is very simple. It loops through all 8 input connectors and turns on or off the corresponding light when it reads a switch open and closed, when it detects a change it writes some output to the terminal and writes a message to the system auth log. This last feature is made even more useful if you configure the Raspberry pi to send its logs to a central server, as I have previously written about.

The next obvious thing to do is to interface this system with the Home API, which would be straight forward to implement (and I will implement when I get a moment!)

Here’s the circuit:

Click on the circuit to see a larger image…

securitysystem

…and here’s the code:

import piface.pfio
import time
import sys
import syslog
class SecurityIndicator:
""" A switch and LED link: Displays light when switch is closed """
def __init__(self, pin_pair, label):
self.pin_pair = pin_pair
self.label = label
self.laststatus = ""
self.poll()
def poll(self):
if piface.pfio.digital_read(self.pin_pair) == 1:
if self.laststatus != 'closed':
piface.pfio.digital_write(self.pin_pair, 1)
self.log(self.label + ' is CLOSED')
self.laststatus = 'closed'
else:
if self.laststatus != 'open':
piface.pfio.digital_write(self.pin_pair, 0)
self.log(self.label + ' is OPEN')
self.laststatus = 'open'
def log(self, message):
# Echo message
print(message + ' at ' + time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime()))
# And for good measure, log entry to auth log
syslog.syslog(syslog.LOG_AUTH | syslog.LOG_INFO, message)
def main(argv):
piface.pfio.init()
# Initialise our indicator switches
indicators = ['Front Door', 'Study window', 'Study door', 'Bedroom Window', 'Back door', 'Living room window', 'Kitchen window', 'Bathroom window']
indicator_obj = [];
cnt = 0
for switch in indicators:
indicator_obj.append(SecurityIndicator(cnt, switch))
cnt = cnt + 1
# Loop and check indicators
while True:
for indicator in indicator_obj:
indicator.poll()
time.sleep(0.05)
if __name__ == "__main__":
sys.exit(main(sys.argv))

Enjoy!

Stepping up from traffic lights last time, I decided this time to have a crack at making a Pelican crossing.

A Pelican crossing is a pedestrian crossing consisting of two sets of traffic lights, a button, and a signal to indicate that it is safe for pedestrians to cross. The sequence that the lights follow is slightly more complex than before:

  • Initially, the traffic signal lights are green and the pedestrian “red man” is on red.
  • When the button is pressed, the traffic signal lights cycle to red.
  • Once the traffic signals are red, the pedestrian signal is set to green and a buzzer sounds for a period of time.
  • When the buzzer has finished beeping, the traffic signals are set on flashing amber and the pedestrian green signal also flashes.
  • After a little while, the traffic signal is reset to green and the pedestrian signal to red.

The Circuit

The circuit for this is slightly more complex.

The traffic signals are now linked, so each red, amber, and green light can be linked in parallel. We introduce two new lights for the pedestrian signal, together with a buzzer.

experiment 2 - traffic lights crossing

I know there are two red/green men in real life, but this is a slight simplification. Just connect red/green leds in parallel for the second set, as we did for the main linked traffic signals.

The Software

The code is fairly similar to before, we extend the class to control three additional outputs – the red and green man and a buzzer, as well as to listen to a given input button press.

The main loop waits for a button press and when detected it toggles the lights, sounds the buzzer, then toggles the lights back.

import piface.pfio
import time
import sys
class crossinglight:
""" A (UK) Crossing traffic light """
def __init__(self, red_pin, amber_pin, green_pin, red_man_pin, green_man_pin, beeper, button):
self.red_pin = red_pin
self.amber_pin = amber_pin
self.green_pin = green_pin
self.red_man_pin = red_man_pin
self.green_man_pin = green_man_pin
self.beeper = beeper
self.button = button
self.status = 'green'
piface.pfio.digital_write(self.green_pin, 1)
piface.pfio.digital_write(self.red_man_pin, 1)
def beep(self):
for cnt in range(1, 10):
piface.pfio.digital_write(self.beeper, 1)
time.sleep(1)
piface.pfio.digital_write(self.beeper, 0)
time.sleep(1)
def wait_for_button(self):
pressed = False;
while pressed == False:
if piface.pfio.digital_read(self.button) == 1:
pressed = True;
def toggle(self):
cnt = 0;
if self.status == 'red':
piface.pfio.digital_write(self.red_pin, 0)
# Transitioning from red to green, blink amber light and green man
for cnt in range(1, 5):
piface.pfio.digital_write(self.amber_pin, 1)
piface.pfio.digital_write(self.green_man_pin, 1)
time.sleep(1)
piface.pfio.digital_write(self.amber_pin, 0)
piface.pfio.digital_write(self.green_man_pin, 0)
time.sleep(1)
piface.pfio.digital_write(self.amber_pin, 0)
piface.pfio.digital_write(self.red_pin, 0)
piface.pfio.digital_write(self.green_pin, 1)
piface.pfio.digital_write(self.green_man_pin, 0)
piface.pfio.digital_write(self.red_man_pin, 1)
self.status = 'green'
else:
piface.pfio.digital_write(self.green_pin, 0)
piface.pfio.digital_write(self.amber_pin, 1)
time.sleep(2)
piface.pfio.digital_write(self.amber_pin, 0)
piface.pfio.digital_write(self.red_pin, 1)
piface.pfio.digital_write(self.green_man_pin, 1)
piface.pfio.digital_write(self.red_man_pin, 0)
self.status = 'red'
def main(argv):
piface.pfio.init()
# initialise our light
light = crossinglight(0,1,2, 3,4, 5, 0)
# Loop, waiting for button press (probably could be done better with interrupts)
while True:
light.wait_for_button();
light.toggle()
light.beep()
light.toggle()
if __name__ == "__main__":
sys.exit(main(sys.argv))

Here it is in action…