From dd8d70f6f026842e3d109b777abfcbd732dd8462 Mon Sep 17 00:00:00 2001 From: Kristy Fournier <124598538+kristy-fournier@users.noreply.github.com> Date: Thu, 17 Oct 2024 12:27:20 -0400 Subject: [PATCH 1/4] RaspPi integration plan --- plan.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 plan.md diff --git a/plan.md b/plan.md new file mode 100644 index 0000000..8cd568d --- /dev/null +++ b/plan.md @@ -0,0 +1,33 @@ +To design a self-running app for your Raspberry Pi based on your requirements, here’s a step-by-step plan that you can follow. I'll guide you through the steps without giving the full solution, so you can piece it together. + +### Steps to Implement + +1. **Automating Raspberry Pi Startup Actions:** + - **Systemd Service**: Use `systemd` to create a service that will automatically run when the Pi starts. This can manage your app’s startup logic. + - **Startup Script**: Alternatively, you can create a simple shell script that runs on boot, either placed in `/etc/rc.local` or managed by `cron` with the `@reboot` directive. + +2. **Detect USB Flash Drive on Boot:** + - **Automounting USB**: Set up the Raspberry Pi to automount flash drives when plugged in. Look into editing `/etc/fstab` or using the `usbmount` package. + - **Checking for MP3s**: Write Python logic that checks the mounted drives for files with `.mp3` extension. Use libraries like `os` or `pathlib` to scan directories. + +3. **Copying MP3s to a Directory:** + - You can use the `shutil` library in Python to handle file copying. + - Ensure this logic only triggers when new files are found (so you don’t overwrite your existing directory unnecessarily). + +4. **Running the Database Generator:** + - Since you only want the database generator to run when needed, you can add a condition to check whether the MP3s were updated. For example, store a checksum or file modification time, and if there's a change, trigger the generator. + +5. **Running the Flask Web Server:** + - After copying the files and running the database generator (if needed), the script should launch your Flask web server. + - Flask can be run as part of your startup service as well, once the other tasks are complete. + +### Suggested Order of Operations +- On boot, run your startup script. +- Check for connected USB drives. +- If MP3s are found, copy them to the designated folder. +- Run the database generator only if new files are detected. +- Launch the Flask web server. + +### Things to Consider: +- **Timing**: If there’s a delay for the USB drive to mount, you might want to add a short wait period or a retry loop when checking for the flash drive. +- **Combining Files**: You can combine the MP3-checking, copying, and database generation logic into a single Python script. Then, it can conditionally call the database generator only when new files are added, before starting the Flask server. From b489ae343ba960b6bb3f43bc071441ff6815c155 Mon Sep 17 00:00:00 2001 From: Kristy Fournier <124598538+kristy-fournier@users.noreply.github.com> Date: Thu, 17 Oct 2024 12:42:55 -0400 Subject: [PATCH 2/4] Update plan.md --- plan.md | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/plan.md b/plan.md index 8cd568d..e8b7126 100644 --- a/plan.md +++ b/plan.md @@ -1,3 +1,5 @@ +# Self Running Part + To design a self-running app for your Raspberry Pi based on your requirements, here’s a step-by-step plan that you can follow. I'll guide you through the steps without giving the full solution, so you can piece it together. ### Steps to Implement @@ -31,3 +33,47 @@ To design a self-running app for your Raspberry Pi based on your requirements, h ### Things to Consider: - **Timing**: If there’s a delay for the USB drive to mount, you might want to add a short wait period or a retry loop when checking for the flash drive. - **Combining Files**: You can combine the MP3-checking, copying, and database generation logic into a single Python script. Then, it can conditionally call the database generator only when new files are added, before starting the Flask server. + +# Raspberry Pi Image + +To create a distributable Raspberry Pi image of your project, here's how you can go about it: + +### Steps to Create a Distributable Image + +1. **Set Up and Configure Your Raspberry Pi:** + - Start with a clean installation of **Raspberry Pi OS (32-bit)** since you're testing on 32-bit devices. + - Install and configure your jukebox project (ensure everything works correctly on the hardware). + - Set up any additional packages or dependencies that your project needs. + +2. **Make Your Application Auto-Start:** + - Ensure your application (including the USB drive detection, MP3 copying, database generation, and Flask server) starts automatically on boot using `systemd` or another method like `cron` or `/etc/rc.local`. + - Test this setup by rebooting the Pi and checking if your application behaves as expected. + +3. **Install Any Required Packages:** + - Install any third-party libraries or software required by your Python scripts (e.g., Flask, `shutil`, `usbmount`). + - Use a `requirements.txt` file (if using Python’s `pip`) to track the dependencies. + +4. **Prepare the Image for Distribution:** + - Remove unnecessary files or software to make the image smaller and more efficient. + - Make sure all scripts, services, and permissions are set up properly for non-root users if required. + - Disable any development tools or services that shouldn't be included in the final image. + +5. **Create a Backup of Your Raspberry Pi SD Card:** + - **Shutdown the Pi** after everything is set up and working. + - Remove the SD card and connect it to your PC or Mac using an SD card reader. + - Use a tool like `Raspberry Pi Imager`, `Win32DiskImager` (on Windows), or `dd` (on Linux/Mac) to create a backup of your SD card. This will allow you to create an image file (`.img`). + +6. **Compress the Image:** + - Since SD card images can be large, compress the `.img` file using a tool like `gzip` or `7zip`. This will make it easier to distribute. + +7. **Test the Image:** + - Flash the `.img` file back onto a new SD card and test it on another Raspberry Pi to ensure it boots up and runs your application properly without requiring additional configuration. + +8. **Distribute the Image:** + - Once the image works as expected, you can distribute it by uploading it to a platform like Google Drive or Dropbox, where others can download it and flash it onto their Raspberry Pis. + +### Things to Keep in Mind: +- **Image Size**: If your image is too large, users might need SD cards with more capacity. Trim down unnecessary files to reduce the size. +- **Updates**: Consider how users will receive future updates. You could include a mechanism in your app to check for updates or distribute new versions of the image as needed. + +This should give you a distributable image that can be easily flashed and run on other Raspberry Pi devices! \ No newline at end of file From 54b4b88cfd59fbba77c02636121e971c0e1620ce Mon Sep 17 00:00:00 2001 From: Kristy Fournier <124598538+kristy-fournier@users.noreply.github.com> Date: Thu, 17 Oct 2024 15:50:05 -0400 Subject: [PATCH 3/4] init files for later --- RaspberryPI/startup.py | 1 + Server/webbyBits.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 RaspberryPI/startup.py diff --git a/RaspberryPI/startup.py b/RaspberryPI/startup.py new file mode 100644 index 0000000..84dd220 --- /dev/null +++ b/RaspberryPI/startup.py @@ -0,0 +1 @@ +import threading diff --git a/Server/webbyBits.py b/Server/webbyBits.py index 80e6b0f..037ab22 100644 --- a/Server/webbyBits.py +++ b/Server/webbyBits.py @@ -1,7 +1,7 @@ from flask import Flask from flask import request from flask_cors import CORS -import json,vlc,csv,threading,time,random, argparse +import json,vlc,threading,time,random, argparse parser=argparse.ArgumentParser(description="Options for the Webby Bits") parser.add_argument('-p','--port',help="Pick a port to host on, not the same as the web (client) port",default='19054') porttheuserpicked=parser.parse_args().port From deeea9720a022a10c6cbbaf3cb71430f9177cda8 Mon Sep 17 00:00:00 2001 From: Kristy Fournier <124598538+kristy-fournier@users.noreply.github.com> Date: Tue, 22 Oct 2024 00:01:18 -0400 Subject: [PATCH 4/4] you know breezy stuff --- RaspberryPI/FlashDrive/info.json | 4 ++++ RaspberryPI/startup.py | 13 ++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 RaspberryPI/FlashDrive/info.json diff --git a/RaspberryPI/FlashDrive/info.json b/RaspberryPI/FlashDrive/info.json new file mode 100644 index 0000000..2ee8f73 --- /dev/null +++ b/RaspberryPI/FlashDrive/info.json @@ -0,0 +1,4 @@ +{ + "port": 19054, + "LastFMKey":"" +} \ No newline at end of file diff --git a/RaspberryPI/startup.py b/RaspberryPI/startup.py index 84dd220..1c35700 100644 --- a/RaspberryPI/startup.py +++ b/RaspberryPI/startup.py @@ -1 +1,12 @@ -import threading +""" +Assume that this file is being run at startup, and should do all the things needed + () Check USB for new mp3's + () Check USB for updated data files (api keys, ports, ) + () Copy them to correct directory + () Make sure the audio device is set to the 3.5mm jack + () Run database updater if new files were found + () Run Server + () Run http module to host client + () Generate a qr code and display it somehow (maybe) +""" +import threading, os, shutil,