#!/usr/bin/env python2

import RFM69
from RFM69registers import *
import datetime
import time

NODE=1
NET=1
KEY="Something16chars"
TIMEOUT=3
TOSLEEP=0.1

radio = RFM69.RFM69(RF69_433MHZ, NODE, NET, True)
print "class initialized"

print "reading all registers"
results = radio.readAllRegs()
#for result in results:
#    print result

print "Performing rcCalibration"
radio.rcCalibration()

print "setting high power"
radio.setHighPower(True)

print "Checking temperature"
print radio.readTemperature(0)

print "setting encryption"
radio.encrypt(KEY)

print "starting loop..."
sequence = 0
while True:

    print "start recv..."
    radio.receiveBegin()
    timedOut=0
    while not radio.receiveDone():
        timedOut+=TOSLEEP
        time.sleep(TOSLEEP)
	      if timedOut > TIMEOUT:
            print "timed out waiting for recv"
            break
    if radio.ACKRequested():
        print "sending ack..."
        radio.sendACK()
    else:
        print "ack not requested..."
    print "end recv..."
    data = "".join([chr(letter) for letter in radio.DATA])
    
# Need an if then loop here for MPC control? Or just play/pause music if data = Pressed (2 sec debounce on the other end)... Propbably MPC/MPD I think
# Loop should react to data being "Pressed", then reset data to an empty string and sleep for 2 sec.

print "shutting down"
radio.shutdown()

@@ -86,16 +86,56 @@
 ort time
+%0Aimport subprocess%0Aimport os%0A#import sys
 %0A%0ANODE=1
@@ -157,17 +157,17 @@
 ething16
-c
+C
 hars%22%0ATI
@@ -185,16 +185,621 @@
 LEEP=0.1
+%0Aplayerprocess = None%0Asoundfile1 = %22/home/pi/bubblebutt.mp3%22%0A%0Adef playSound(soundFile):%0A    # check that we have started a process and the process is still running%0A    global playerprocess%0A    print playerprocess%0A    if (playerprocess != None): # and (playerprocess.poll()):%0A        # Dirty way to end it I guess because subprocess got updated in Python3 and is a bitch now.%0A        os.system(%22pkill -9 mpg321%22)%0A        playerprocess = None%0A    else:%0A        # start new process%0A        playerprocess = subprocess.Popen('mpg321 ' + soundFile , shell = True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
 %0A%0Aradio 
@@ -1240,16 +1240,30 @@
  True:%0A%0A
+    data=None%0A
     prin
@@ -1413,9 +1413,10 @@
 EP)%0A
-%09
+  
     
@@ -1723,16 +1723,509 @@
 A%5D)%0A    
+print data%0A    if data == 'Pressed':%0A        print %22Button pressed! data is %22+data%0A%09playSound(soundfile1)%0A#        if (playerprocess != None) and (playerprocess.poll()):%0A#            playerprocess.stdin.close()%0A#            playerprocess.terminate()%0A#        else:# start new process%0A#            playerprocess = subprocess.Popen('mpg321 ' + soundfile1 , stdout=subprocess.PIPE, shell=True)%0A#            #playerprocess.stdout.close()%0A##            playerprocess.wait()%0A        radio.DATA = %5B%5D%0A
 %0A# Need 
@@ -2470,16 +2470,18 @@
 2 sec.%0A%0A
+%0A%0A
 print %22s
@@ -2507,12 +2507,13 @@
 .shutdown()%0A
+%0A

Update theStation.py