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
|
- your Timezone
|
||||||
- environment variables for your MQTT broker
|
- 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.)
|
- 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]```
|
- include it in your TrueNAS Scale Custom Apps e.g. ```include: [/mnt/Data/Apps/GadgetbridgeMqtt/Config/compose.yaml]```
|
||||||
- start the app
|
- start the app
|
||||||
- find your DEVICE_NAME in the App Log and set it in the compose.yaml, then restart the app
|
- find your DEVICE_NAME in the App Log and set it in the compose.yaml, then restart
|
||||||
- (AI told me to ignore the cron setup error)
|
|
||||||
|
|||||||
16
compose.yaml
16
compose.yaml
@ -6,23 +6,21 @@ services:
|
|||||||
network_mode: host
|
network_mode: host
|
||||||
working_dir: /app
|
working_dir: /app
|
||||||
volumes:
|
volumes:
|
||||||
- /mnt/Data/Apps/GadgetbridgeMqtt/App:/app
|
- /mnt/Data/Apps/GadgetbridgeMqtt/App:/app # Create Dataset with App Preset in TrueNAS Scale
|
||||||
- /mnt/Data/Apps/GadgetbridgeMqtt/Logs:/app/logs
|
- /mnt/Data/Apps/GadgetbridgeMqtt/Logs:/app/logs # Create Dataset with App Preset in TrueNAS Scale
|
||||||
- /mnt/Data/Apps/Nextcloud10/data/oliver/files/Backups/Android/Apps/Gadgetbridge/GadgetbridgeOld.db:/data/Gadgetbridge.db:ro
|
- /mnt/Data/Apps/*****/Gadgetbridge/Gadgetbridge.db:/data/Gadgetbridge.db:ro
|
||||||
environment:
|
environment:
|
||||||
- TZ=Europe/Berlin
|
- TZ=Europe/Berlin # Get from e.g. https://webbrowsertools.com/timezone/ -> Timezone info Table -> Timezone
|
||||||
- MQTT_BROKER=192.168.***.***
|
- MQTT_BROKER=192.168.***.***
|
||||||
- MQTT_PORT=1883
|
- MQTT_PORT=1883
|
||||||
- MQTT_USERNAME=*****
|
- MQTT_USERNAME=*****
|
||||||
- MQTT_PASSWORD=*****
|
- MQTT_PASSWORD=*****
|
||||||
- GADGETBRIDGE_DB_PATH=/data/Gadgetbridge.db
|
- 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
|
- PYTHONUNBUFFERED=1
|
||||||
|
- PUBLISH_INTERVAL_SECONDS=300
|
||||||
command: >
|
command: >
|
||||||
sh -c "
|
sh -c "
|
||||||
apt-get update &&
|
|
||||||
apt-get install -y cron &&
|
|
||||||
pip install --no-cache-dir -r requirements.txt &&
|
pip install --no-cache-dir -r requirements.txt &&
|
||||||
python setup.py &&
|
python main.py
|
||||||
cron -f
|
|
||||||
"
|
"
|
||||||
|
|||||||
17
main.py
17
main.py
@ -25,6 +25,9 @@ class GadgetbridgeMQTTPublisher:
|
|||||||
self.device_name = re.sub(r"\W+", "_", raw_name).lower()
|
self.device_name = re.sub(r"\W+", "_", raw_name).lower()
|
||||||
self.load_config()
|
self.load_config()
|
||||||
self.mqtt_client = None
|
self.mqtt_client = None
|
||||||
|
self.publish_interval = int(
|
||||||
|
os.getenv("PUBLISH_INTERVAL_SECONDS", "300")
|
||||||
|
) # <-- Add this
|
||||||
|
|
||||||
def setup_logging(self):
|
def setup_logging(self):
|
||||||
"""Setup logging configuration"""
|
"""Setup logging configuration"""
|
||||||
@ -258,10 +261,14 @@ class GadgetbridgeMQTTPublisher:
|
|||||||
) as client:
|
) as client:
|
||||||
self.mqtt_client = client
|
self.mqtt_client = client
|
||||||
await self.setup_home_assistant_entities()
|
await self.setup_home_assistant_entities()
|
||||||
steps_data = self.get_steps_data()
|
while True:
|
||||||
if steps_data:
|
steps_data = self.get_steps_data()
|
||||||
await self.publish_steps_data(steps_data)
|
if steps_data:
|
||||||
self.logger.info("Gadgetbridge MQTT Publisher completed")
|
await self.publish_steps_data(steps_data)
|
||||||
|
self.logger.info(
|
||||||
|
f"Sleeping for {self.publish_interval} seconds before next publish..."
|
||||||
|
)
|
||||||
|
await asyncio.sleep(self.publish_interval)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error(f"Failed to connect to MQTT broker: {e}")
|
self.logger.error(f"Failed to connect to MQTT broker: {e}")
|
||||||
|
|
||||||
@ -370,6 +377,6 @@ if __name__ == "__main__":
|
|||||||
time.sleep(600)
|
time.sleep(600)
|
||||||
print("Terminating script.")
|
print("Terminating script.")
|
||||||
exit(0)
|
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()
|
publisher = GadgetbridgeMQTTPublisher()
|
||||||
asyncio.run(publisher.run())
|
asyncio.run(publisher.run())
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user