Skip to content

Commit 44d4ea7

Browse files
committed
Ensure that the json file exists
1 parent 50b7ff0 commit 44d4ea7

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

sofar2mqtt-v2.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from multiprocessing import Process
1616
import paho.mqtt.client as mqtt
1717
import requests
18+
import os
1819

1920
VERSION = "3.1.0"
2021

@@ -67,8 +68,14 @@ def __init__(self, daemon, retry, retry_delay, write_retry, write_retry_delay, r
6768

6869
if self.raw_data.get('protocol') == "SOFAR-1-40KTL.json":
6970
logging.error("Unsupported protocol detected. Exiting")
71+
exit(1)
72+
73+
protocol_file = self.raw_data.get('protocol')
74+
if not os.path.isfile(protocol_file):
75+
logging.error(f"Protocol file {protocol_file} does not exist. Exiting")
76+
exit(1)
7077

71-
self.config = load_config(self.raw_data.get('protocol'))
78+
self.config = load_config(protocol_file)
7279
self.write_registers = []
7380
untested = False
7481
for register in self.config['registers']:

0 commit comments

Comments
 (0)