diff --git a/Documentation/CHANGELOG.md b/Documentation/history/CHANGELOG.md similarity index 89% rename from Documentation/CHANGELOG.md rename to Documentation/history/CHANGELOG.md index b50a47d..8e6e22e 100644 --- a/Documentation/CHANGELOG.md +++ b/Documentation/history/CHANGELOG.md @@ -41,3 +41,6 @@ Version control history: * Users using mail mode option will have to install and configure msmtp. * Details in Readme. +* version 2.3-4 05-05-202 + * added new graph mode option 12 GPU & CPU% & RAM% versus live time + * Automated creation of config file if missing (on start up new user) diff --git a/Documentation/rpi_tempmon.cfg b/Documentation/rpi_tempmon.cfg index da1c942..8c46f4a 100644 --- a/Documentation/rpi_tempmon.cfg +++ b/Documentation/rpi_tempmon.cfg @@ -2,6 +2,6 @@ RPI_AuthUser=example@gmail.com MAIL_ALERT=1 ALARM_MODE=1 -CPU_UPPERLIMIT=70 +CPU_UPPERLIMIT=20 LED_MODE=1 GPIO_LED=26 \ No newline at end of file diff --git a/screenshots/graphmode1.jpg b/Documentation/screenshots/graphmode1.jpg similarity index 100% rename from screenshots/graphmode1.jpg rename to Documentation/screenshots/graphmode1.jpg diff --git a/screenshots/graphmode10.jpg b/Documentation/screenshots/graphmode10.jpg similarity index 100% rename from screenshots/graphmode10.jpg rename to Documentation/screenshots/graphmode10.jpg diff --git a/screenshots/graphmode11.jpg b/Documentation/screenshots/graphmode11.jpg similarity index 100% rename from screenshots/graphmode11.jpg rename to Documentation/screenshots/graphmode11.jpg diff --git a/Documentation/screenshots/graphmode12.jpg b/Documentation/screenshots/graphmode12.jpg new file mode 100644 index 0000000..950c6e5 Binary files /dev/null and b/Documentation/screenshots/graphmode12.jpg differ diff --git a/screenshots/graphmode2.jpg b/Documentation/screenshots/graphmode2.jpg similarity index 100% rename from screenshots/graphmode2.jpg rename to Documentation/screenshots/graphmode2.jpg diff --git a/screenshots/graphmode3.jpg b/Documentation/screenshots/graphmode3.jpg similarity index 100% rename from screenshots/graphmode3.jpg rename to Documentation/screenshots/graphmode3.jpg diff --git a/screenshots/graphmode4.jpg b/Documentation/screenshots/graphmode4.jpg similarity index 100% rename from screenshots/graphmode4.jpg rename to Documentation/screenshots/graphmode4.jpg diff --git a/screenshots/graphmode5.jpg b/Documentation/screenshots/graphmode5.jpg similarity index 100% rename from screenshots/graphmode5.jpg rename to Documentation/screenshots/graphmode5.jpg diff --git a/screenshots/graphmode6.jpg b/Documentation/screenshots/graphmode6.jpg similarity index 100% rename from screenshots/graphmode6.jpg rename to Documentation/screenshots/graphmode6.jpg diff --git a/screenshots/graphmode7.jpg b/Documentation/screenshots/graphmode7.jpg similarity index 100% rename from screenshots/graphmode7.jpg rename to Documentation/screenshots/graphmode7.jpg diff --git a/screenshots/graphmode8.jpg b/Documentation/screenshots/graphmode8.jpg similarity index 100% rename from screenshots/graphmode8.jpg rename to Documentation/screenshots/graphmode8.jpg diff --git a/screenshots/graphmode9.jpg b/Documentation/screenshots/graphmode9.jpg similarity index 100% rename from screenshots/graphmode9.jpg rename to Documentation/screenshots/graphmode9.jpg diff --git a/screenshots/graphoptionsmenu.jpg b/Documentation/screenshots/graphoptionsmenu.jpg similarity index 100% rename from screenshots/graphoptionsmenu.jpg rename to Documentation/screenshots/graphoptionsmenu.jpg diff --git a/screenshots/graphstresstest.jpg b/Documentation/screenshots/graphstresstest.jpg similarity index 100% rename from screenshots/graphstresstest.jpg rename to Documentation/screenshots/graphstresstest.jpg diff --git a/screenshots/main_screen.jpg b/Documentation/screenshots/main_screen.jpg similarity index 100% rename from screenshots/main_screen.jpg rename to Documentation/screenshots/main_screen.jpg diff --git a/screenshots/nyalarm.jpg b/Documentation/screenshots/nyalarm.jpg similarity index 100% rename from screenshots/nyalarm.jpg rename to Documentation/screenshots/nyalarm.jpg diff --git a/stresstestdata/alldata.jpg b/Documentation/stresstestdata/alldata.jpg similarity index 100% rename from stresstestdata/alldata.jpg rename to Documentation/stresstestdata/alldata.jpg diff --git a/stresstestdata/stresstest.md b/Documentation/stresstestdata/stresstest.md similarity index 100% rename from stresstestdata/stresstest.md rename to Documentation/stresstestdata/stresstest.md diff --git a/stresstestdata/test1.jpg b/Documentation/stresstestdata/test1.jpg similarity index 100% rename from stresstestdata/test1.jpg rename to Documentation/stresstestdata/test1.jpg diff --git a/stresstestdata/test2.jpg b/Documentation/stresstestdata/test2.jpg similarity index 100% rename from stresstestdata/test2.jpg rename to Documentation/stresstestdata/test2.jpg diff --git a/stresstestdata/test3.jpg b/Documentation/stresstestdata/test3.jpg similarity index 100% rename from stresstestdata/test3.jpg rename to Documentation/stresstestdata/test3.jpg diff --git a/stresstestdata/test4.jpg b/Documentation/stresstestdata/test4.jpg similarity index 100% rename from stresstestdata/test4.jpg rename to Documentation/stresstestdata/test4.jpg diff --git a/stresstestdata/test5.jpg b/Documentation/stresstestdata/test5.jpg similarity index 100% rename from stresstestdata/test5.jpg rename to Documentation/stresstestdata/test5.jpg diff --git a/stresstestdata/test6.jpg b/Documentation/stresstestdata/test6.jpg similarity index 100% rename from stresstestdata/test6.jpg rename to Documentation/stresstestdata/test6.jpg diff --git a/Documentation/LICENSE.txt b/LICENSE.md similarity index 100% rename from Documentation/LICENSE.txt rename to LICENSE.md diff --git a/README.md b/README.md index fe50490..f58eeff 100644 --- a/README.md +++ b/README.md @@ -2,17 +2,19 @@ Overview -------------------------------------------- * Name: rpi_tempmon * Title : Display the ARM CPU and GPU temperature of Raspberry Pi -* Description: This python program will display the ARM CPU and +* Description: + +This python program will display the ARM CPU and GPU temperature of a Raspberry Pi features include command line display, GPIO (LED) output, logging, alarm limit, graphing, desktop notification, stress tests and e-mailing options. -The program is written in python 3. It is run in terminal and uses matplotlib -plots for graph modes. This software was built and tested on a raspberry pi 3 model B, -running Linux, Raspbian 8.0 jessie, LXDE lxpanel 0.7.2, Python 3.4.2. +It is run in terminal and uses matplotlib +plots for graph modes. + * Author: Gavin Lyons * URL: https://github.com/gavinlyonsrepo/raspeberrypi_tempmon -* History: [Changelog is at repository in documentation section](Documentation/CHANGELOG.md) -* Copyright: Copyright (C) 2017 - Gavin Lyons - GPLv3 [License is at repository in documentation section](Documentation/LICENSE.txt) +* Toolchain: RPI 3 model B, Raspbian 10 Buster, LXDE lxpanel 0.10.0, +Python 3.7.3. Table of contents --------------------------- @@ -30,25 +32,17 @@ Installation ----------------------------------------------- For Linux OS users. raspberrypi_tempmon is a python 3 program -Make sure that: - -* python3 -* pip3 - -Have been installed on your machine, - -Then Install with: +Make sure that: python3 & pip3 Have been installed on your machine, +Then Install form PyPi with: ```sh sudo pip3 install rpi_tempmon.py ``` - Usage ------------------------------------------- -Program is a python 3 package. - -Run in a terminal by typing rpi_tempmon.py or python3 rpi_tempmon.py: +Program is a python 3 package. Run in a terminal +by typing rpi_tempmon.py or python3 rpi_tempmon.py: rpi_tempmon.py -[options][arguments] @@ -62,7 +56,7 @@ Options list *(Note: Options are standalone, not designed to be combined)*: | -l | Creates and/or appends to log file at output folder | | -L | Creates a sub-folder at output folder with date/time stamp and puts a log file in it | | -m | Sends the log file to an email account | -| -g | graph mode, Generate a menu where 11 types of graphs can be selected | +| -g | graph mode, Generate a menu where 12 types of graphs can be selected | | -a | parse log file and produces a data report in terminal | | -n | send notifications to desktop, Number argument to define behaviour | | -s | CSV mode , parses log.txt and converts it to log.csv, CSV file | @@ -77,12 +71,12 @@ rpi_tempmon files needed are listed below: | rpi_tempmon.py | The main python script | | RpiTempmonWork.py| python module containing various utility functions used by main | | RpiTempmonGraph.py | python module dealing with graph output by matplotlib | -| $HOME/.config/rpi_tempmon/rpi_tempmon.cfg | config file, user made, NOT installed | +| $HOME/.config/rpi_tempmon/rpi_tempmon.cfg | config file | | README.md | help file | -Config file: The user **MUST** create a config file at path in table above. -The config file is NOT installed by setup. A dummy config file is available in documentation folder at repositry +Config file: The config file with dummy values is created if missing. +A dummy config file is available in documentation folder at repository , used for -m mail option, GPIO/LED feature and the alarm function. The setting "RPI_AuthUser" the is email address @@ -220,7 +214,7 @@ Data is sent to terminal screen. The GPIO pin in config file will be turned on and Data in red is displayed in screen for an Alarm state, if setup in config file. -![ScreenShot cont mode](https://raw.githubusercontent.com/gavinlyonsrepo/raspberrypi_tempmon/master/screenshots/main_screen.jpg) +![ScreenShot cont mode](https://raw.githubusercontent.com/gavinlyonsrepo/raspberrypi_tempmon/master/Documentation/screenshots/main_screen.jpg) **3. & 4. Log modes** @@ -277,9 +271,10 @@ This file allows for user to set an email address without access to msmtp config file which should be set up just for root account. 2. Install msmtp and dependencies as per installation section 3. Configure msmtp configuration file [MSMTP help](https://wiki.archlinux.org/index.php/Msmtp) -A working example msmtprc config file for gmail is in documentation folder, see link for details. +A working example msmtprc config file for gmail is in documentation folder, "example_msmtprc". 4. Optional, It is also possible you may need to configure your email account to accept msmtp mails this was the case for gmail and ssmtp. See here [Login credentials not working with Gmail SMTP](https://stackoverflow.com/questions/16512592/login-credentials-not-working-with-gmail-smtp#27515883) + "Less secure app access" in google mail to On. **6. graph mode** @@ -289,14 +284,14 @@ The logfile.txt created by logfile mode 3 is used for data for graph 1-8. graphs 1-4 use time-date stamp as yaxis value graphs 5-8 use Unix Epoch stamp as yaxis value, this is better for irregular data points across multiple dates. -The graphs 9-11 are live plots sampled every two seconds for 150 points, +The graphs 9-12 are live plots sampled every two seconds for 150 points, so five minutes of live data. -![graph menu](https://raw.githubusercontent.com/gavinlyonsrepo/raspberrypi_tempmon/master/screenshots/graphoptionsmenu.jpg) +![graph menu](https://raw.githubusercontent.com/gavinlyonsrepo/raspberrypi_tempmon/master/Documentation/screenshots/graphoptionsmenu.jpg) Sample graph screenshot, screenshots of all others are in [screenshot folder of repo](screenshots/). -![graph mode 6](https://raw.githubusercontent.com/gavinlyonsrepo/raspberrypi_tempmon/master/screenshots/graphmode2.jpg) +![graph mode 6](https://raw.githubusercontent.com/gavinlyonsrepo/raspberrypi_tempmon/master/Documentation/screenshots/graphmode2.jpg) **7. CSV(comma-separated values) convert** @@ -330,7 +325,7 @@ depending on system. for example * -n 2 = argument 2 = If run always display CPU temperature , no warning. * -n 3 = argument 3 = If run only display if CPU temperature exceeds limit -![notify mode](https://raw.githubusercontent.com/gavinlyonsrepo/raspberrypi_tempmon/master/screenshots/nyalarm.jpg) +![notify mode](https://raw.githubusercontent.com/gavinlyonsrepo/raspberrypi_tempmon/master/Documentation/screenshots/nyalarm.jpg) **10. Stress test mode** @@ -349,6 +344,6 @@ called stresslog.csv . sample output = test run num, CPU temp, CPU usage. At the end of test, there is an option to display results in a graph. -![stress test results](https://raw.githubusercontent.com/gavinlyonsrepo/raspberrypi_tempmon/master/screenshots/graphstresstest.jpg) +![stress test results](https://raw.githubusercontent.com/gavinlyonsrepo/raspberrypi_tempmon/master/Documentation/screenshots/graphstresstest.jpg) -Stress data carried out by rpi_tempmon for a RPi 3 can be found in repo [here](stresstestdata/stresstest.md) +Stress data carried out by rpi_tempmon for a RPi 3 can be found in repo [here](Documentation/stresstestdata/stresstest.md) diff --git a/rpiTempMod/RpiTempmonGraph.py b/rpiTempMod/RpiTempmonGraph.py index 0298bfe..c1e57a2 100644 --- a/rpiTempMod/RpiTempmonGraph.py +++ b/rpiTempMod/RpiTempmonGraph.py @@ -11,11 +11,11 @@ mpl.use('tkagg') import matplotlib.pyplot as plt import matplotlib.dates as md + # My modules from . import RpiTempmonWork as Work - class MatplotGraph(object): """ class with 6 methods to display graphs with matplotlib @@ -95,11 +95,12 @@ def display_menu(self): menu.append("CPU usage versus live Time") menu.append("GPU Temperature versus live Time") menu.append("RAM usage versus live Time") + menu.append("CPU GPU & RAM usage versus live time") menu.append("Exit") try: while True: print("\n") - Work.msg_func("blue", "Graph Menu Options") + Work.msg_func("blue", "RPI_tempmon :: Graph Menu Options") Work.msg_func("line", "") for number, string in enumerate(menu): print(number+1, string) @@ -117,6 +118,9 @@ def display_menu(self): self.graph_live_data("RAM") break elif self.selection == '12': + self.graph_all_live_data() + break + elif self.selection == '13': quit() else: Work.msg_func("red", "\n ** Warning : Unknown Option Selected! **") @@ -169,8 +173,72 @@ def draw_graph(self, timelist, yaxis_list1, plt.grid(True) plt.show() + def graph_all_live_data(self): + """ Draw a live graph of pi GPU/CPU/RAM """ + print("Drawing graph of all data usage versus live time") + print("Press CTRL+c to quit.") + try: + time_cpu_axis = [] + time_ram_axis = [] + time_gpu_axis = [] + yaxis_cpu_data = 0 + yaxis_ram_data = 0 + yaxis_gpu_data = 0 + plt.ion() + labels = () + + # pre-load dummy data + for i in range(0, 150): + time_cpu_axis.append(.5) + time_ram_axis.append(.5) + time_gpu_axis.append(.5) + + while True: + # get data + yaxis_cpu_data = Work.get_cpu_use() + yaxis_cpu_data = float(yaxis_cpu_data) + yaxis_ram_data = Work.get_ram_info() + yaxis_ram_data = float(yaxis_ram_data) + ostemp = os.popen('vcgencmd measure_temp').readline() + yaxis_gpu_data = (ostemp.replace("temp=", "").replace("'C\n", "")) + yaxis_gpu_data = float(yaxis_gpu_data) + + # update the graph + labels = "GPU Temp + CPU & RAM usage", "CPU-% RAM-% GPU-'C", "CPU-%", "RAM-%", "GPU-'C" + time_cpu_axis.append(yaxis_cpu_data) + time_ram_axis.append(yaxis_ram_data) + time_gpu_axis.append(yaxis_gpu_data) + time_cpu_axis.pop(0) + time_ram_axis.pop(0) + time_gpu_axis.pop(0) + self.plot_all_now(time_cpu_axis, time_ram_axis, time_gpu_axis, labels) + plt.pause(2) + + except Exception as error: + print(error) + Work.msg_func("bold", "Real-time matplotlib plot shutdown") + quit() + + def plot_all_now(self, time_cpu_axis, time_ram_axis, time_gpu_axis, labels): + """ Called from method graph_all_live_data to draw graph""" + + title, y_label, plot_cpu_label, plot_ram_label, plot_gpu_label = labels + plt.clf() + + plt.ylim([1, 100]) + plt.ylabel(y_label, color='red') + + plt.title(self.name + title, color='green') + plt.grid(True) + plt.xlabel("Time (last 300 seconds)", color='red') + plt.plot(time_cpu_axis, color='blue', marker='', label=plot_cpu_label) + plt.plot(time_ram_axis, color='red', marker='', label=plot_ram_label) + plt.plot(time_gpu_axis, color='green', marker='', label=plot_gpu_label) + plt.legend(loc='upper right', fancybox=True, shadow=True) + plt.show() + def graph_live_data(self, choice): - """ Draw a live graph of pi GPU """ + """ Draw a live graph of pi GPU or CPU or RAM """ try: time_axis = [] yaxis_data = 0 @@ -181,9 +249,6 @@ def graph_live_data(self, choice): time_axis.append(.5) while True: - - time_axis.append(yaxis_data) - time_axis.pop(0) if choice == "GPU": ostemp = os.popen('vcgencmd measure_temp').readline() yaxis_data = (ostemp.replace("temp=", "").replace("'C\n", "")) @@ -199,7 +264,7 @@ def graph_live_data(self, choice): time_axis.append(yaxis_data) time_axis.pop(0) self.plot_now(time_axis, labels) - else: # RAM + elif choice == 'RAM': yaxis_data = Work.get_ram_info() yaxis_data = float(yaxis_data) labels = (" RAM live usage", "Usage (%)", "RAM") diff --git a/rpiTempMod/RpiTempmonWork.py b/rpiTempMod/RpiTempmonWork.py index 52a2f35..025ddb6 100644 --- a/rpiTempMod/RpiTempmonWork.py +++ b/rpiTempMod/RpiTempmonWork.py @@ -107,7 +107,7 @@ def get_cpu_tempfunc(): def get_gpu_tempfunc(): """ Return GPU temperature as a character string""" res = os.popen('/opt/vc/bin/vcgencmd measure_temp').readline() - return res.replace("temp=", "") + return (res.replace("\n", "").replace("temp=", "")) def get_cpu_use(): @@ -165,7 +165,7 @@ def logging_func(choice, mail_alert, cpu_limit, mailuser, destlog, alarm_mode): with open("log.txt", "a+") as mylogfile: mylogfile.write("TS = " + str(today) + '\n') mylogfile.write("EP = " + str(round(time.time(), 0)) + '\n') - mylogfile.write("GPU temperature = " + get_gpu_tempfunc()) + mylogfile.write("GPU temperature = " + get_gpu_tempfunc() + '\n') mylogfile.write("CPU temperature = " + get_cpu_tempfunc() + '\n') mylogfile.write("Cpu usage = " + get_cpu_use() + '\n') mylogfile.write("RAM usage = " + get_ram_info() + '\n') @@ -193,7 +193,7 @@ def mail_func(sub, mailu, destlog): os.chdir(destlog) if os.path.exists("log.txt"): # Command to send mail from bash - os.system('echo "Datafile log.txt attached" > body.txt') + os.system('echo "Datafile log.txt attached" > body.txt') os.system('mpack -s "raspberry-PI-temperature {}" -d body.txt log.txt {}'.format(sub, mailu)) else: msg_func("red", "Error: log file is not there {}".format(destlog)) @@ -337,7 +337,7 @@ def msg_func(myprocess, mytext): OUTPUT yesno prompt return 1 or 0""" # colours for printf - blue = '\033[94m' + blue = '\033[96m' green = '\033[92m' yellow = '\033[93m' red = '\033[91m' @@ -385,7 +385,6 @@ def importtest(text): """import print test statement""" # print(text) pass - # ===================== MAIN =============================== diff --git a/rpiTempSrc/rpi_tempmon.py b/rpiTempSrc/rpi_tempmon.py index 2819bc5..91a9b81 100755 --- a/rpiTempSrc/rpi_tempmon.py +++ b/rpiTempSrc/rpi_tempmon.py @@ -7,7 +7,7 @@ # intial date :17/08/2017 # web url :https://github.com/gavinlyonsrepo/raspberrypi_tempmon # mail :glyons66@hotmail.com -# python version :3.4.2 +# python version : 3.7.3 # Functions: (1) exit_handler_func: exit handler function (2) stresstest_func: stresstest function @@ -17,6 +17,7 @@ (6) alarm_mode_check: checks for alarm condition (7) cont_mode_check: checks for continuous mode (8) main: main program loop +(9) set_paths_func: set and check the paths for config & cache """ # =========================IMPORTS====================== # Import the system modules needed to run rpi_tempmon.py. @@ -34,28 +35,13 @@ # =======================GLOBALS========================= # metadata -__VERSION__ = "2.2" +__VERSION__ = "2.3" __URL__ = "https://github.com/gavinlyonsrepo/raspberrypi_tempmon" - # set the path for logfile DESTLOG = os.environ['HOME'] + "/.cache/rpi_tempmon" -if not os.path.exists(DESTLOG): - os.makedirs(DESTLOG) - # set the path for config file DESTCONFIG = os.environ['HOME'] + "/.config/rpi_tempmon" -if not os.path.exists(DESTCONFIG): - os.makedirs(DESTCONFIG) -DESTCONFIG = DESTCONFIG + "/" + "rpi_tempmon.cfg" -if os.path.isfile(DESTCONFIG): - pass -else: - print("Config file is missing at {}".format(DESTCONFIG)) - print("User must create a config file, See url:-") - print("Example config file and info can be found at") - print(__URL__) - quit() - +DESTCONFIGFILE = DESTCONFIG + "/" + "rpi_tempmon.cfg" # ===================FUNCTION SECTION=============================== @@ -201,7 +187,7 @@ def read_configfile_func(): """Read in configfile, return 6 values in a tuple""" try: myconfigfile = configparser.ConfigParser() - myconfigfile.read(DESTCONFIG) + myconfigfile.read(DESTCONFIGFILE) mailuser = myconfigfile.get("MAIN", "RPI_AuthUser") mail_alert = myconfigfile.get("MAIN", "MAIL_ALERT") alarm_mode = myconfigfile.get("MAIN", "ALARM_MODE") @@ -217,7 +203,7 @@ def read_configfile_func(): Work.msg_func("red", " ERROR : ") print("Problem with config file: {}".format(error)) print("Must have section header of [MAIN] and six parameters") - print("Help and exmaple file at url") + print("Help and example file at url") print(__URL__) exit_handler_func(0) @@ -228,10 +214,10 @@ def alarm_mode_check(config_file_data_main): """function to check alarm mode """ alarm_mode, cpu_limit, led_mode, led_num = config_file_data_main if alarm_mode == "1": - Work.msg_func("bold", "Alarm mode is on: " + cpu_limit) + Work.msg_func("bold", "Alarm mode is on: " + cpu_limit + "'C") if Work.get_cpu_tempfunc() > cpu_limit: # display led mode - Work.msg_func("red", "Warning : cpu over the temperature limit: " + cpu_limit) + Work.msg_func("red", "Warning : CPU over the temperature limit: " + cpu_limit + "'C") if led_mode == "1": Work.msg_func("bold", "LED mode is on, GPIO pin selected: " + led_num) Work.led_toggle_func("on", led_num) @@ -250,9 +236,9 @@ def cont_mode_check(led_num): print("Sorry, input to -c must be a positive integer.") quit() delay = sys.argv[2] - Work.msg_func("bold", "Continuous mode is on.") - Work.msg_func("bold", "Sleep delay set to seconds: " + str(delay)) - Work.msg_func("bold", "Press CTRL+c to quit.") + Work.msg_func("bold", "Continuous mode: On") + Work.msg_func("bold", "Sleep delay set to: " + str(delay) + " seconds.") + print("\nPress CTRL+c to quit.") time.sleep(float(delay)) os.system('clear') else: # normal mode prompt @@ -262,24 +248,56 @@ def cont_mode_check(led_num): exit_handler_func(led_num) +def set_paths_func(): + """set and check the paths for config file and cache/logging""" + if not os.path.exists(DESTLOG): # Check cache path is there + os.makedirs(DESTLOG) + if not os.path.exists(DESTCONFIG): # Check config path is there + os.makedirs(DESTCONFIG) + + if os.path.isfile(DESTCONFIGFILE): # Check config file is there + pass + else: + try: + config = configparser.ConfigParser() + config.optionxform = lambda option: option # case sensitive option + config['MAIN'] = {'RPI_AuthUser': 'example@gmail.com', + 'MAIL_ALERT': '1', + 'ALARM_MODE': '1', + 'CPU_UPPERLIMIT': '70', + 'LED_MODE': '1', + 'GPIO_LED': '26'} + with open(DESTCONFIGFILE, 'w') as configfile: + config.write(configfile) + except Exception as error: + Work.msg_func("red", " ERROR : ") + print("Config file is missing at {}".format(DESTCONFIGFILE)) + print("Problem Creating default config file: {}".format(error)) + print("Example config file and info can be found at:") + print(__URL__) + exit_handler_func(0) + else: + Work.msg_func("yellow", " INFO : ") + print("Config file was missing at {}".format(DESTCONFIGFILE)) + print("Config file created with default values.") + input("Press to continue") + + def main(config_file_data_main): - """Function to hold main program loop, config file data tuple""" + """Function to hold main program loop, param1 : config file data tuple""" # unpack config file data main tuple alarm_mode, cpu_limit, led_mode, led_num = config_file_data_main - scan_count = 0 + # main loop try: while True: print_title_func() scan_count += 1 Work.msg_func("bold", "Number of scans: " + str(scan_count)) - # check for alarm mode alarm_mode_check(config_file_data_main) - # check for continuous mode cont_mode_check(led_num) - # call led function off Work.led_toggle_func("off", led_num) except KeyboardInterrupt: exit_handler_func(led_num) @@ -289,6 +307,7 @@ def main(config_file_data_main): if __name__ == "__main__": try: print("\nRPi temperature monitor:") + set_paths_func() exit(main(process_cmd_arguments())) except (KeyboardInterrupt, SystemExit): pass diff --git a/setup.py b/setup.py index c53f552..4f93866 100644 --- a/setup.py +++ b/setup.py @@ -2,21 +2,21 @@ setup( name="rpi_tempmon.py", - version="2.2", + version="2.3", author="gavin lyons", author_email="glyons66@hotmail.com", - description="Display the CPU and GPU temperature of Raspberry Pi", + description="Monitor RAM,CPU and GPU data of Raspberry Pi", license=" GPL", keywords="PI Raspberry CPU ARM GPU temperature temp rpi monitor display gavin lyons", url="https://github.com/gavinlyonsrepo/raspeberrypi_tempmon", - download_url='https://github.com/gavinlyonsrepo/raspeberrypi_tempmon/archive/2.2.tar.gz', + download_url='https://github.com/gavinlyonsrepo/raspeberrypi_tempmon/archive/2.3.tar.gz', packages=['rpiTempSrc','rpiTempMod',], install_requires= ['matplotlib','pip','psutil'], setup_requires = ['pip'], scripts=['rpiTempSrc/rpi_tempmon.py'], classifiers=[ "Topic :: Utilities", - "Programming Language :: Python :: 3.4", + "Programming Language :: Python :: 3.7", "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", ], )