diff --git a/README.md b/README.md index a4a35b5ec..a882e03e1 100755 --- a/README.md +++ b/README.md @@ -4,9 +4,9 @@ A contactless jukebox for the Raspberry Pi, playing audio files, playlists, podc *Important update news* -* **Phoniebox 1.1.1 released** Adding *recursive folder playout* and *recording* to the Phoniebox. With version 1.0.0 we switched the audio player to `mpd`, added *resume play* for audiobook lovers, RFID switch for *wifi off*, new *player interface*, *random* and *repeat*. At this stage the *recursive* playout only works in the web app, not RFID cards. (2018-09-13) -* **Upgrade** if you are looking for *how to upgrade* please check out [UPGRADE.md](docs/UPGRADE.md) - and if you found out something that should go there, please create a pull request. (2018-09-10) -* **One Line Install Script** As of version 1.0 there is a much simpler install procedure: copy and paste one line into your terminal and hit *enter*. Find out more about the [one-line Phoniebox install script](docs/INSTALL-stretch.md#oneLineInstall). (2018-08-18) +* **Phoniebox 1.1.6 released** Adding *recursive folder playout* and *recording* to the Phoniebox. With version 1.x we switched the audio player to `mpd`, added *resume play* for audiobook lovers, RFID switch for *wifi off*, new *player interface*, *random* and *repeat*. At this stage the *recursive* playout only works in the web app, not RFID cards. (2018-10-08) +* **Upgrade** if you are looking for *how to upgrade* please check out [UPGRADE.md](docs/UPGRADE.md) - and if you found out something that should go there, please create a pull request. (2018-10-08) +* **One Line Install Script** As of version 1.x there is a much simpler install procedure: copy and paste one line into your terminal and hit *enter*. Find out more about the [one-line Phoniebox install script](docs/INSTALL-stretch.md#oneLineInstall). (2018-08-18) * **Podcasts!** More for myself than anybody else, I guess, I added the [podcast feature for Phoniebox](docs/MANUAL.md#podcasts) (2018-05-09) * **Bleeding edge: `develop` branch** The maintenance with a growing contributor team (kudos!) got complicated. I introduced the branch `develop` which is where all new stuff is happening before merged to `master`. (2018-08-30) --- diff --git a/docs/UPGRADE.md b/docs/UPGRADE.md index 0b877fdcd..7626e45a0 100755 --- a/docs/UPGRADE.md +++ b/docs/UPGRADE.md @@ -13,7 +13,7 @@ There is a file `settings/version` containing the version number. **Note:*** This is work in progress, please share experience, improvements and insights in the [issue section](https://github.com/MiczFlor/RPi-Jukebox-RFID/issues). -# Upgrade from Version 1.1.1 to 1.1.3 +# Upgrade from Version 1.1.1 to 1.1.6 A few important bug fixes. And a new design. And the option to decide what the 'second swipe' of a card does (see settings in the web app). diff --git a/misc/sampleconfigs/rfid-reader.service.stretch-default.sample b/misc/sampleconfigs/rfid-reader.service.stretch-default.sample index e7b8aedda..fe345d509 100755 --- a/misc/sampleconfigs/rfid-reader.service.stretch-default.sample +++ b/misc/sampleconfigs/rfid-reader.service.stretch-default.sample @@ -10,4 +10,4 @@ WorkingDirectory=/home/pi/RPi-Jukebox-RFID ExecStart=/usr/bin/python2 /home/pi/RPi-Jukebox-RFID/scripts/daemon_rfid_reader.py [Install] -WantedBy=multi-user.target +WantedBy=multi-user.target \ No newline at end of file diff --git a/scripts/Reader.py b/scripts/Reader.py index 99d6f822f..9c49e6a61 100644 --- a/scripts/Reader.py +++ b/scripts/Reader.py @@ -1,137 +1,39 @@ # Forked from Francisco Sahli's https://github.com/fsahli/music-cards/blob/master/Reader.py + +import string +#import csv import os.path import sys -import serial -import string -import RPi.GPIO as GPIO from evdev import InputDevice, categorize, ecodes, list_devices -import MFRC522 - - -def get_devices(): - devices = [InputDevice(fn) for fn in list_devices()] - devices.append(NonUsbDevice('MFRC522')) - devices.append(NonUsbDevice('RDM6300')) - return devices - - -class NonUsbDevice(object): - name = None - - def __init__(self, name): - self.name = name - - -class UsbReader(object): - def __init__(self, device): - self.keys = "X^1234567890XXXXqwertzuiopXXXXasdfghjklXXXXXyxcvbnmXXXXXXXXXXXXXXXXXXXXXXX" - self.dev = device - - def read_card(self): - from select import select - stri = '' - key = '' - while key != 'KEY_ENTER': - select([self.dev], [], []) - for event in self.dev.read(): - if event.type == 1 and event.value == 1: - stri += self.keys[event.code] - key = ecodes.KEY[event.code] - return stri[:-1] - - -class Mfrc522Reader(object): - def __init__(self): - self.device = MFRC522.MFRC522() - - def read_card(self): - # Scan for cards - status, tag_type = self.device.MFRC522_Request(self.device.PICC_REQIDL) - - # If a card is found - if status == self.device.MI_OK: - print "Card detected" - - # Get the UID of the card - (status, uid) = self.device.MFRC522_Anticoll() - - # If we have the UID, continue - if status == self.device.MI_OK: - return ''.join((str(x) for x in uid)) - else: - print "No Device ID found." - return None - - @staticmethod - def cleanup(): - GPIO.cleanup() - - -class Rdm6300Reader: - def __init__(self): - device = '/dev/ttyS0' - baudrate = 9600 - ser_timeout = 0.1 - self.last_card_id = '' - try: - self.rfid_serial = serial.Serial(device, baudrate, timeout=ser_timeout) - except serial.SerialException as e: - print(e) - exit(1) - - def read_card(self): - byte_card_id = b'' - - try: - while True: - try: - read_byte = self.rfid_serial.read() - - if read_byte == b'\x02': # start byte - while read_byte != b'\x03': # end bye - read_byte = self.rfid_serial.read() - byte_card_id += read_byte - - card_id = byte_card_id.decode('utf-8') - byte_card_id = '' - card_id = ''.join(x for x in card_id if x in string.printable) - - # Only return UUIDs with correct length - if len(card_id) == 12 and card_id != self.last_card_id: - self.last_card_id = card_id - self.rfid_serial.reset_input_buffer() - return self.last_card_id - - else: # wrong UUID length or already send that UUID last time - self.rfid_serial.reset_input_buffer() - - except ValueError as ve: - print(ve) - - except serial.SerialException as se: - print(se) - - def cleanup(self): - self.rfid_serial.close() - - -class Reader(object): - def __init__(self): - path = os.path.dirname(os.path.realpath(__file__)) - if not os.path.isfile(path + '/deviceName.txt'): - sys.exit('Please run config.py first') - else: - with open(path + '/deviceName.txt', 'r') as f: - device_name = f.read() - - if device_name == 'MFRC522': - self.reader = Mfrc522Reader() - elif device_name == 'RDM6300': - self.reader = Rdm6300Reader() - else: - try: - device = [device for device in get_devices() if device.name == device_name][0] - self.reader = UsbReader(device) - except IndexError: - sys.exit('Could not find the device %s.\n Make sure it is connected' % device_name) +from select import select +class Reader: + def __init__(self): + path = os.path.dirname(os.path.realpath(__file__)) + self.keys = "X^1234567890XXXXqwertzuiopXXXXasdfghjklXXXXXyxcvbnmXXXXXXXXXXXXXXXXXXXXXXX" + if not os.path.isfile(path + '/deviceName.txt'): + sys.exit('Please run RegisterDevice.py first') + else: + with open(path + '/deviceName.txt','r') as f: + deviceName = f.read() + devices = [InputDevice(fn) for fn in list_devices()] + for device in devices: + if device.name == deviceName: + self.dev = device + break + try: + self.dev + except: + sys.exit('Could not find the device %s\n. Make sure is connected' % deviceName) + + def readCard(self): + stri='' + key = '' + while key != 'KEY_ENTER': + r,w,x = select([self.dev], [], []) + for event in self.dev.read(): + if event.type==1 and event.value==1: + stri+=self.keys[ event.code ] + #print( keys[ event.code ] ) + key = ecodes.KEY[ event.code ] + return stri[:-1] diff --git a/scripts/RegisterDevice.py b/scripts/RegisterDevice.py index 284c02569..e499a8dbf 100644 --- a/scripts/RegisterDevice.py +++ b/scripts/RegisterDevice.py @@ -1,17 +1,18 @@ #!/usr/bin/env python2 -# Forked from Francisco Sahli's https://github.com/fsahli/music-cards/blob/master/config.py -import os.path -from Reader import get_devices -devices = get_devices() +import os.path +from evdev import InputDevice, list_devices -print "Choose the reader from list:" -for i in range(len(devices)): - print i, devices[i].name +devices = [InputDevice(fn) for fn in list_devices()] +path = os.path.dirname(os.path.realpath(__file__)) +i = 0 +print "Choose the reader from list" +for dev in devices: + print i, dev.name + i += 1 dev_id = int(raw_input('Device Number: ')) -path = os.path.dirname(os.path.realpath(__file__)) -with open(path + '/deviceName.txt', 'w') as f: - f.write(devices[dev_id].name) - f.close() +with open(path + '/deviceName.txt','w') as f: + f.write(devices[dev_id].name) + f.close() diff --git a/scripts/daemon_rfid_reader.py b/scripts/daemon_rfid_reader.py index 046fed283..26752998d 100755 --- a/scripts/daemon_rfid_reader.py +++ b/scripts/daemon_rfid_reader.py @@ -1,37 +1,19 @@ -#!/usr/bin/env python2 import subprocess -import os -import signal - +import os from Reader import Reader reader = Reader() -continue_reading = True # get absolute path of this script dir_path = os.path.dirname(os.path.realpath(__file__)) +print dir_path -# Capture SIGINT for cleanup when the script is aborted -def end_read(signal, frame): - global continue_reading - print "Ctrl+C captured, ending read." - continue_reading = False - reader.reader.cleanup() - - -# Welcome message -print "Press Ctrl-C to stop." - -# Hook the SIGINT -signal.signal(signal.SIGINT, end_read) - -while continue_reading: - # reading the card id - cardid = reader.reader.read_card() - if cardid is not None: +while True: + # reading the card id + cardid = reader.readCard() try: - # start the player script and pass on the card id + # start the player script and pass on the cardid subprocess.call([dir_path + '/rfid_trigger_play.sh --cardid=' + cardid], shell=True) except OSError as e: - print "Execution failed:" + str(e) + print "Execution failed:" \ No newline at end of file diff --git a/settings/version b/settings/version index 314c3d717..ab679818c 100755 --- a/settings/version +++ b/settings/version @@ -1 +1 @@ -1.1.5 \ No newline at end of file +1.1.6 \ No newline at end of file