Saturday, February 8, 2014

[Product Review] Raspbery Pi Cookbook Video

This is a product review for the Raspbery Pi Cookbook Video.

As they say, "Seeing is Believing", there is something to be said about a seeing something being done rather than reading about it. Perfect companion for the cookbook, in my opinion.

I reviewed the cookbook when it was in early draft and liked it very much. At the time, I honestly thought that it would be great if I can just see demonstrate of some of the recipes. Apparently I am not alone. Personally I believe if you have some experience with Raspberry Pi you will still get value out of the video, but it is best to be used with the cookbook so one can read about the recipe and reinforce the idea with the video.

Just like the cookbook, the video works from simple to more complex recipes. Some recipes builds on top of each other, but not much.

Overall, I believe if you like the cookbook, you will enjoy the video.


Here is a video for a mashup for "Recipe 04.09 Raspberry Pi Radio Transmitter". The idea is to tail /var/log/syslog, upon finding a suitable event, play the sound.


Here is the code:

#!/usr/env/bin python
# Eric Chou
# Fred Hsu
# Feb. 16, 2014
# The purpose of the file is to tail the syslog, upon finding a suitable event
# the device will push out the directflow to the Arista switch and transmit
# a FM radio sound to indicate triggered event.

import subprocess, time, re
from jsonrpclib import Server

p = subprocess.Popen('tail -f /var/log/syslog', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)

# Sets Arista API call parameters
username = "admin"
password = "admin"
switch = ""
dip = ""
outport = "Port-Channel 100"
urlString = "https://{}:{}@{}/command-api".format(username, password, switch)
switchReq = Server( urlString )

# Tails syslog and look for the re expression
while True:
    line = (p.stdout.readline()).strip()
    if'vThunder-2', line):
        print "Found Event: ", line
        print "Pushing Direct Flow out to Arista switch", switch
        # The following rpc request will match on the source IP, then punts traffic to output port
        #response = switchReq.runCmds( 1, ["enable", "configure", "openflow", "flow a10", "persistent", "match destination ip {}".format(dip), "action set output interface {}".format(outport)] )['./pifm', 'starwars.wav', '103.0']) #make sure pyfm available

Happy scripting with Raspberry Pi!

No comments:

Post a Comment