From ff7e0534184a298a23b66f0b18986e52725f96e7 Mon Sep 17 00:00:00 2001 From: Simon Briere Date: Tue, 16 Apr 2024 14:37:34 -0400 Subject: [PATCH] Refs #14. Fixed sync files error when "ToProcess" folder doesn't exist --- README.md | 58 ++++++++++++++++------------- libs/servers/WatchServerOpenTera.py | 5 ++- 2 files changed, 36 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index b0dafc1..7c454b6 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Multi-network (cellular, wi-fi & ethernet) sensor and data hub with local re This project was designed to run on a Raspberry Pi board with a cellular hat (Waveshare SIM7600CE 4G HAT - https://www.waveshare.com/product/raspberry-pi/hats/iot/sim7600ce-4g-hat.htm). Main features of the project includes: - * Local wifi hub on which devices can connect and provides direct internet access + * Local Wi-Fi hub on which devices can connect and provides direct internet access * Over cellular network * Over connected ethernet cable * Data transfer hub: @@ -15,28 +15,40 @@ Main features of the project includes: * OpenTera (https://github.com/introlab/opentera) server ## Requirements -Tested on Python 3.10 +* Miniconda -## Pi setup +### Miniconda installation + +1. Open a terminal +2. `wget http://repo.continuum.io/miniconda/Miniconda3-py39_4.9.2-Linux-aarch64.sh -O ~/miniconda3/miniconda.sh` +3. `conda init bash` +4. Close the terminal and start it again (or reload bash) -This suppose that a working git environment is setup, and that a Personal Access Token (PAT) was generated to use as password. -Initialize credential manager (to remember PAT) `git config --global credential.helper store` +## Pi setup - 1. Clone the repository directly into `/home/pi/Desktop` folder (a PiHub folder will be created): `git clone https://github.com/CDRV/PiHub.git` +### Installation + 1. Clone the repository directly into `/home/pi/Desktop` folder (a PiHub folder will be created - you can also choose any other place you want): + `git clone https://github.com/CDRV/PiHub.git` 2. Create Python virtual environment: 1. `cd /home/pi/Desktop/PiHub` - 2. `python3 -m venv venv` - 3. `source venv/bin/activate` - 4. `pip install -r requirements.txt` - 5. `deactivate` - * **If miniconda is installed, the script "create_conda_venv" can also be used** - 4. Edit the config file `/home/pi/Desktop/PiHub/config/PiHub.json` with the appropriate values - 5. Setup the cron tasks using `sudo crontab -e` and the crontab job listed in the `/home/pi/Desktop/PiHub/setup/crontab.txt` file - 6. Setup and enable the main pihub service using
- `sudo cp /home/pi/Desktop/PiHub/setup/pihub.service /etc/systemd/system/pihub.service`
- `sudo systemctl enable pihub.service` - `sudo systemctl start pihub.service` + 2. `chmod +x create_conda_venv.sh` + 3. `./create_conda_venv.sh` + 4. Make a copy of the default config file `cp /home/pi/Desktop/PiHub/config/PiHub_Defaults.json /home/pi/Desktop/PiHub/config/PiHub.json` + 5. Edit the config file `/home/pi/Desktop/PiHub/config/PiHub.json` with the appropriate values + 6. Setup the cron tasks using `sudo crontab -e` and the crontab job listed in the `/home/pi/Desktop/PiHub/setup/crontab.txt` file + 7. Setup and enable the main pihub service using
+ `sudo cp /home/pi/Desktop/PiHub/setup/pihub.service /etc/systemd/system/pihub.service`
+ `sudo systemctl enable pihub.service` + `sudo systemctl start pihub.service` +### OpenTera configuration +Edit the `PiHub.json` configuration file: +* `WatchServer` + * `"transfer_type": "opentera"` +* `OpenTera` + * `"device_register_key": "(insert key)"` -> Device register key can be obtained by logging in on the target server and going in the "About" screen. Only super admins can see that key. + * `"default_session_type_id": (id)` -> Session type ID to use to create session. + ### Service usage To check if the service is running: `systemctl status pihub.service` To query service output (log): `journalctl -u pihub.service` @@ -46,12 +58,8 @@ If not developping directly on a Raspberry Pi, a virtual Python environment (ven 1. Install Python (see requirement version above) 2. Create a virtual environment: - 1. Open a command line interface - 2. Go to the PiHub folder - 3. Create the virtual environment: `python -m venv venv` - 4. Enable the virtual environment:
- On Mac/Linux: `source venv/bin/activate`
- On Windows: `venv\Scripts\activate.bat`
- **If miniconda is installed, the script "create_conda_venv" can also be used** - 5. Install requirements: `pip install -r requirements.txt` + 1. Install and setup miniconda for your OS + 2. Open a command line interface + 3. Go to the PiHub folder + 4. Create the virtual environment: `create_conda_venv` diff --git a/libs/servers/WatchServerOpenTera.py b/libs/servers/WatchServerOpenTera.py index 7f2d8f0..b162bbb 100644 --- a/libs/servers/WatchServerOpenTera.py +++ b/libs/servers/WatchServerOpenTera.py @@ -102,8 +102,9 @@ def sync_files(self): logging.info("WatchServerOpenTera: Checking if any pending transfers...") # Get base folder path base_folder = os.path.join(self.data_path, 'ToProcess') - for device_name in os.listdir(base_folder): - self.initiate_opentera_transfer(device_name) + if os.path.isdir(base_folder): + for device_name in os.listdir(base_folder): + self.initiate_opentera_transfer(device_name) logging.info("All done!")