diff --git a/compressed_sized_timed_rotating_logger.py b/compressed_sized_timed_rotating_logger.py index cf8ca6cdc62e5837ac624306b2615141f74d63b3..16c76584170b0e5a032964550649c9c20d2e6216 100644 --- a/compressed_sized_timed_rotating_logger.py +++ b/compressed_sized_timed_rotating_logger.py @@ -39,7 +39,7 @@ class CompressedSizedTimedRotatingFileHandler(handlers.TimedRotatingFileHandler) dir_name, base_name = os.path.split(self.baseFilename) file_names = os.listdir(dir_name) result = [] - prefix = f'{base_name}.2' # we want to find a rotated file with eg filename.2017-12-12... name + prefix = f'{base_name}.2' # we want to find a rotated file with e.g. filename.2017-12-12... name for file_name in file_names: if file_name.startswith(prefix) and not file_name.endswith('.zip'): result.append(file_name) @@ -55,4 +55,4 @@ class CompressedSizedTimedRotatingFileHandler(handlers.TimedRotatingFileHandler) os.remove(dfn_zipped) with zipfile.ZipFile(dfn_zipped, 'w', self.zip_mode) as f: f.write(dfn) - os.remove(dfn) \ No newline at end of file + os.remove(dfn) diff --git a/install_local_mqtt_broker.sh b/install_local_mqtt_broker.sh index ef3c81457253e14fa0b98bf2f60c8d385ef4b022..f9085ce4a3010c7cfd2af0187c7941945e4f2aae 100644 --- a/install_local_mqtt_broker.sh +++ b/install_local_mqtt_broker.sh @@ -1,6 +1,20 @@ +txtred='\e[0;31m' # Red +txtgrn='\e[0;32m' # Green +txtylw='\e[0;33m' # Yellow +txtdef='\e[0;0m' # Default + +echo -e "${txtgrn}>>> Updating system and installing MQTT broker...${txtdef}" sudo apt update && sudo apt upgrade sudo apt install -y mosquitto mosquitto-clients sudo systemctl enable mosquitto.service -echo "Broker is intalled. Starting now..." -mosquitto -v - + +echo -e "\n${txtgrn}>>> Broker is installed. Starting now...${txtdef}" +mosquitto -v + +echo -e "\n${txtgrn}>>> Updating configuration to allow anonymous remote connections...${txtdef}" +echo "listener 1883" | sudo tee -a /etc/mosquitto/mosquitto.conf +echo "allow_anonymous true" | sudo tee -a /etc/mosquitto/mosquitto.conf +echo -e "\n${txtgrn}>>> Current configuration stored in /etc/mosquitto/mosquitto.conf is displayed below${txtdef}" +cat /etc/mosquitto/mosquitto.conf +echo -e "\n${txtylw}>>> Adapt it according to your needs!${txtdef}\n" + diff --git a/logging_setup.py b/logging_setup.py index 556c77804868cc20d9da32d9b01fa5aae172783a..3c0f8536b77e3c670c39e55a49d79999b8f296be 100644 --- a/logging_setup.py +++ b/logging_setup.py @@ -68,7 +68,7 @@ def setup_loggers(mqtt=True): return msg_logger, msg_log_filename, data_logger, data_log_filename, logging_level -def init_logging(msg_logger, logging_level, log_path, data_log_filename): +def init_logging(msg_logger, logging_level, data_log_filename): """ This is the init sequence for the logging system """ init_logging_status = True diff --git a/webserver.py b/webserver.py index 5a49ea8175299143c331cfbc9f44541336ce7797..f2f85f596ab86e90f2676ec87167a7a4eaedef02 100644 --- a/webserver.py +++ b/webserver.py @@ -1,13 +1,12 @@ from http.server import SimpleHTTPRequestHandler, HTTPServer -import time +# import time import os import json -from Ohmpi import OhmPi -import threading +from ohmpi import OhmPi +# import threading import pandas as pd import shutil -#hostName = "0.0.0.0" hostName = 'localhost' serverPort = 8080 @@ -18,6 +17,7 @@ with open('ohmpi_param.json') as json_file: ohmpi = OhmPi(pardict) + class MyServer(SimpleHTTPRequestHandler): # because we use SimpleHTTPRequestHandler, we do not need to implement # the do_GET() method (if we use the BaseHTTPRequestHandler, we would need to) @@ -32,9 +32,10 @@ class MyServer(SimpleHTTPRequestHandler): # self.end_headers() # with open(os.path.join('.', self.path[1:]), 'r') as f: # self.wfile.write(bytes(f.read(), "utf-8")) - + def do_POST(self): - global ohmpiThread, status, run + # global ohmpiThread, status, run + dic = json.loads(self.rfile.read(int(self.headers['Content-Length']))) rdic = {} if dic['command'] == 'start':