Commit 8ca02a05 authored by Sebastian Böhm's avatar Sebastian Böhm
Browse files

add startup arguments

parent 91886aed
......@@ -257,6 +257,9 @@ NOTE:
* Change the working directory: `cd edge_iot_simulator`
* Run:`python3 main.py`
NOTE: If you want disable the `TemperatureService` (not burdening your broker with a lot messages), start the application with the following command: `python3 main.py --services cpu_load_svc`.
Then, the `TemperatureService` is effectively disabled.
You should see the following output:
```bash
......
from datetime import datetime
from enum import Enum
import threading
import time
......@@ -6,6 +7,7 @@ import json
import copy
import logging
import os
import sys
from messaging.mqtt_client import MqttMessage
logging.basicConfig(format='%(asctime)s %(module)s %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p', level=logging.DEBUG)
......@@ -50,10 +52,11 @@ class TemperatureService(threading.Thread):
def get_temperature(self, unit):
with self.lock:
temperature_measurement = copy.deepcopy(self.last_temperature_measurement)
if (self.last_temperature_measurement is not None):
temperature_measurement = copy.deepcopy(self.last_temperature_measurement)
if (temperature_measurement is None):
raise TemperatureServiceException("No valid measurement available!")
if (self.last_temperature_measurement is None):
temperature_measurement = TemperatureMeasurement(time.time(), float('inf'), TemperatureUnits.celsius.name)
return temperature_measurement.convert(unit)
......
#!/usr/bin/env python3
import argparse
from core.temperature_svc import TemperatureMeasurement, TemperatureService,TemperatureUnits
from core.cpu_load_svc import CPULoadJobAllCores, CPULoadService
from messaging.mqtt_client import MqttException, MqttClient, MqttStatus, MessageBroker
......@@ -19,6 +20,15 @@ load_dotenv()
if __name__=="__main__":
parser = argparse.ArgumentParser(description='Edge-IoT Simulator')
parser.add_argument('--services', metavar='S', type=str, nargs='+', default='temperature_svc cpu_load_svc', help='add the services you would like to start')
args = parser.parse_args()
services = []
for item in [args.services]:
services += item
publisher_queue = queue.Queue()
consumer_queue = queue.Queue()
......@@ -31,8 +41,10 @@ if __name__=="__main__":
try:
logging.info('Start Edge-IoT Simulator...')
publisher.start()
temperature_svc.start()
cpu_load_svc.start()
if "temperature_svc" in services:
temperature_svc.start()
if "cpu_load_svc" in services:
cpu_load_svc.start()
web_app.start()
message_broker.start()
time.sleep(5) # wait for connection to mqtt broker
......@@ -45,16 +57,20 @@ if __name__=="__main__":
logging.error("Unknown error occurred: " + str(e))
finally:
publisher.stop()
temperature_svc.stop()
cpu_load_svc.stop()
if "temperature_svc" in services:
temperature_svc.stop()
if "cpu_load_svc" in services:
cpu_load_svc.stop()
web_app.stop()
message_broker.stop()
logging.info('Wait for graceful termination...')
publisher.join()
temperature_svc.join()
cpu_load_svc.join()
if "temperature_svc" in services:
temperature_svc.join()
if "cpu_load_svc" in services:
cpu_load_svc.join()
web_app.join()
message_broker.join()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment