remove cron
This commit is contained in:
parent
dd56be27dd
commit
506dc8a0ef
@ -10,7 +10,9 @@ This is a Gadgetbridge MQTT bridge for TrueNAS Scale, which allows you to connec
|
||||
- your Timezone
|
||||
- environment variables for your MQTT broker
|
||||
- your DEVICE_NAME. (Can be skipped first time: If you start the app with "unknown" as DEVICE_NAME, you will see all devices from the Gadgetbridge Database in your App Log.)
|
||||
- create ```Config``` Dataset in TrueNAS Scale with App Preset "Generic"
|
||||
- write your compose.yaml into the Config Dataset, e.g. ```sudo nano /mnt/Data/Apps/GadgetbridgeMqtt/Config/compose.yaml```
|
||||
- use the Console give admin access (instead of root) e.g:```sudo chown -R 950:950 /mnt/Data/Apps/GadgetbridgeMqtt/App``` (this should prevent apps to modify the config?)
|
||||
- include it in your TrueNAS Scale Custom Apps e.g. ```include: [/mnt/Data/Apps/GadgetbridgeMqtt/Config/compose.yaml]```
|
||||
- start the app
|
||||
- find your DEVICE_NAME in the App Log and set it in the compose.yaml, then restart the app
|
||||
- (AI told me to ignore the cron setup error)
|
||||
- find your DEVICE_NAME in the App Log and set it in the compose.yaml, then restart
|
||||
|
||||
16
compose.yaml
16
compose.yaml
@ -6,23 +6,21 @@ services:
|
||||
network_mode: host
|
||||
working_dir: /app
|
||||
volumes:
|
||||
- /mnt/Data/Apps/GadgetbridgeMqtt/App:/app
|
||||
- /mnt/Data/Apps/GadgetbridgeMqtt/Logs:/app/logs
|
||||
- /mnt/Data/Apps/Nextcloud10/data/oliver/files/Backups/Android/Apps/Gadgetbridge/GadgetbridgeOld.db:/data/Gadgetbridge.db:ro
|
||||
- /mnt/Data/Apps/GadgetbridgeMqtt/App:/app # Create Dataset with App Preset in TrueNAS Scale
|
||||
- /mnt/Data/Apps/GadgetbridgeMqtt/Logs:/app/logs # Create Dataset with App Preset in TrueNAS Scale
|
||||
- /mnt/Data/Apps/*****/Gadgetbridge/Gadgetbridge.db:/data/Gadgetbridge.db:ro
|
||||
environment:
|
||||
- TZ=Europe/Berlin
|
||||
- TZ=Europe/Berlin # Get from e.g. https://webbrowsertools.com/timezone/ -> Timezone info Table -> Timezone
|
||||
- MQTT_BROKER=192.168.***.***
|
||||
- MQTT_PORT=1883
|
||||
- MQTT_USERNAME=*****
|
||||
- MQTT_PASSWORD=*****
|
||||
- GADGETBRIDGE_DB_PATH=/data/Gadgetbridge.db
|
||||
- DEVICE_NAME="unknown" # Set your device name here, or leave as "unknown" to see all devices in the logs
|
||||
- DEVICE_NAME="unknown"
|
||||
- PYTHONUNBUFFERED=1
|
||||
- PUBLISH_INTERVAL_SECONDS=300
|
||||
command: >
|
||||
sh -c "
|
||||
apt-get update &&
|
||||
apt-get install -y cron &&
|
||||
pip install --no-cache-dir -r requirements.txt &&
|
||||
python setup.py &&
|
||||
cron -f
|
||||
python main.py
|
||||
"
|
||||
|
||||
11
main.py
11
main.py
@ -25,6 +25,9 @@ class GadgetbridgeMQTTPublisher:
|
||||
self.device_name = re.sub(r"\W+", "_", raw_name).lower()
|
||||
self.load_config()
|
||||
self.mqtt_client = None
|
||||
self.publish_interval = int(
|
||||
os.getenv("PUBLISH_INTERVAL_SECONDS", "300")
|
||||
) # <-- Add this
|
||||
|
||||
def setup_logging(self):
|
||||
"""Setup logging configuration"""
|
||||
@ -258,10 +261,14 @@ class GadgetbridgeMQTTPublisher:
|
||||
) as client:
|
||||
self.mqtt_client = client
|
||||
await self.setup_home_assistant_entities()
|
||||
while True:
|
||||
steps_data = self.get_steps_data()
|
||||
if steps_data:
|
||||
await self.publish_steps_data(steps_data)
|
||||
self.logger.info("Gadgetbridge MQTT Publisher completed")
|
||||
self.logger.info(
|
||||
f"Sleeping for {self.publish_interval} seconds before next publish..."
|
||||
)
|
||||
await asyncio.sleep(self.publish_interval)
|
||||
except Exception as e:
|
||||
self.logger.error(f"Failed to connect to MQTT broker: {e}")
|
||||
|
||||
@ -370,6 +377,6 @@ if __name__ == "__main__":
|
||||
time.sleep(600)
|
||||
print("Terminating script.")
|
||||
exit(0)
|
||||
# Original code follows, only runs if device_name is present and valid
|
||||
# continuous publisher only runs if device_name is present and valid
|
||||
publisher = GadgetbridgeMQTTPublisher()
|
||||
asyncio.run(publisher.run())
|
||||
|
||||
Loading…
Reference in New Issue
Block a user