def button_get(self): """ Displays the selected configuration of the first selected and online sensor. """ ip_list = self.ip_selection.get_verified_ip_list() if len(ip_list) > 0: network_commands = app_variables.CreateNetworkGetCommands() try: if self.combo_dropdown_selection.value == "Installed Sensors": command = sensor_commands.CreateSensorNetworkCommand( ip_list[0], self.current_config.network_timeout_data, network_commands.installed_sensors_file) elif self.combo_dropdown_selection.value == "Configuration": command = sensor_commands.CreateSensorNetworkCommand( ip_list[0], self.current_config.network_timeout_data, network_commands.sensor_configuration_file) elif self.combo_dropdown_selection.value == "Wifi": command = sensor_commands.CreateSensorNetworkCommand( ip_list[0], self.current_config.network_timeout_data, network_commands.wifi_config_file) elif self.combo_dropdown_selection.value == "Trigger Variances": command = sensor_commands.CreateSensorNetworkCommand( ip_list[0], self.current_config.network_timeout_data, network_commands.variance_config) else: command = sensor_commands.CreateSensorNetworkCommand( ip_list[0], self.current_config.network_timeout_data, "") command.command = "" self.textbox_config.value = str( sensor_commands.get_data(command)) except Exception as error: app_logger.sensor_logger.error(str(error)) else: app_useful_functions.no_ip_selected_message()
def datetime_update(self): """ Sends the Date & Time update command to the Sensor Units IP, along with the computers Date & Time. """ app_logger.sensor_logger.debug("Updating Sensors DateTime") threads = [] network_timeout = self.current_config.network_timeout_data ip_list = self.ip_selection.get_verified_ip_list() if len(ip_list) > 0: command = network_commands.set_datetime for ip in ip_list: sensor_command = sensor_commands.CreateSensorNetworkCommand( ip, network_timeout, command) sensor_command.command_data = self.current_config.get_str_datetime_now( ) threads.append( Thread(target=sensor_commands.put_command, args=[sensor_command])) for thread in threads: thread.start() guizero.info( "Sensors DateTime Set", "Sensors Date & Time synchronized with local computer's") else: app_useful_functions.no_ip_selected_message()
def hostname_change(self): """ Sends the host name change command to the Sensor Units IP, along with the new host name. """ app_logger.sensor_logger.debug("Change Sensor Hostname") threads = [] network_timeout = self.current_config.network_timeout_data ip_list = self.ip_selection.get_verified_ip_list() if len(ip_list) > 0: for ip in ip_list: new_hostname = simpledialog.askstring(ip, "New Hostname: ") app_logger.sensor_logger.debug("Sent Hostname: " + str(new_hostname)) validated_hostname = sensor_commands.get_validated_hostname( new_hostname) app_logger.sensor_logger.debug("Validated Hostname: " + validated_hostname) if validated_hostname is not "Cancelled": command = network_commands.set_host_name sensor_command = sensor_commands.CreateSensorNetworkCommand( ip, network_timeout, command) sensor_command.command_data = validated_hostname threads.append( Thread(target=sensor_commands.put_command, args=[sensor_command])) else: guizero.info(ip, "Hostname Cancelled or blank for " + ip) for thread in threads: thread.start() else: app_useful_functions.no_ip_selected_message()
def send_commands(self, command): """ Sends provided command to the Sensor Units IP's. """ threads = [] ip_list = self.ip_selection.get_verified_ip_list() network_timeout = self.current_config.network_timeout_data for ip in ip_list: sensor_command = sensor_commands.CreateSensorNetworkCommand( ip, network_timeout, command) threads.append( Thread(target=sensor_commands.send_command, args=[sensor_command])) for thread in threads: thread.daemon = True thread.start() if len(ip_list) > 0: message = command + " sent to " + str(len(ip_list)) if len(ip_list) is 1: message += " sensor" else: message += " sensors" guizero.info("Sensor Command Sent", message) else: app_useful_functions.no_ip_selected_message()
def _sensor_add_note_button(self): """ Send the note to selected sensor. """ if self.textbox_current_note.value.strip() == "": guizero.warn("Empty Note", "Cannot add a blank Note") else: if self.checkbox_use_current_datetime.value: self._reset_datetime() try: user_datetime_var = self.adjust_datetime(self.textbox_note_date.value, self.current_config.datetime_offset * -1) except Exception as error: user_datetime_var = self.textbox_note_date.value app_logger.sensor_logger.error("Unable to convert user entered DateTime: " + str(error)) command = self.network_send_commands.put_sql_note network_timeout = self.current_config.network_timeout_data sensor_command = sensor_commands.CreateSensorNetworkCommand(self.selected_ip, network_timeout, command) sensor_command.command_data = user_datetime_var + \ self.network_send_commands.command_data_separator + \ self.sterilize_notes(self.textbox_current_note.value) sensor_commands.put_command(sensor_command) guizero.info("Note Inserted into Sensors " + self.selected_ip, "Inserted with DateTime: " + user_datetime_var) app_logger.sensor_logger.info("Inserted note into sensors " + str(self.selected_ip) + " with DateTime " + user_datetime_var) self._connect_to_sensor()
def _sensor_update_note_button(self): current_note_number = int(self.textbox_on_number_notes.value.strip()) - 1 utc_0_datetime_current = self.database_notes_dates[current_note_number] reverse_datetime_offset = self.current_config.datetime_offset * -1 if self.checkbox_use_current_datetime.value: datetime_var = self.current_config.get_str_datetime_now() else: datetime_var = self.textbox_note_date.value.strip() self.database_user_note_dates[current_note_number] = datetime_var self.textbox_note_date.value = datetime_var utc_0_datetime_user = str(self.adjust_datetime(datetime_var, reverse_datetime_offset)) sql_note = self.sterilize_notes(self.textbox_current_note.value) try: on_note_number = int(self.textbox_on_number_notes.value.strip()) - 1 self.database_notes[on_note_number] = self.undue_sterilize_notes(sql_note) if sql_note == "": guizero.warn("Empty Note", "Cannot add a blank Note") else: command = self.network_send_commands.update_sql_note network_timeout = self.current_config.network_timeout_data sensor_command = sensor_commands.CreateSensorNetworkCommand(self.selected_ip, network_timeout, command) sensor_command.command_data = utc_0_datetime_current + \ self.network_send_commands.command_data_separator + \ utc_0_datetime_user + \ self.network_send_commands.command_data_separator + \ sql_note sensor_commands.put_command(sensor_command) except Exception as error: guizero.warn("Invalid Note Number", str(error))
def get_sensor_data(self, ip): """ Gets configuration report data from the provided sensor IP and puts it in the instance que. """ command_data = sensor_commands.CreateSensorNetworkCommand( ip, self.network_timeout, network_get_commands.system_data) sensor_system = sensor_commands.get_data(command_data).split(",") try: sensor_system[3] = app_useful_functions.convert_minutes_string( sensor_system[3]) except Exception as error: app_logger.app_logger.error("Sensor Config Report: " + str(error)) command_data.command = network_get_commands.sensor_configuration sensor_config = sensor_commands.get_data(command_data).split(",") final_sensor_config = [ str(sensor_system[0]), str(sensor_system[1]), str(sensor_system[2]), str(sensor_config[0]), str(sensor_config[1]), str(sensor_config[2]), str(sensor_config[3]), str(sensor_config[4]), str(sensor_config[5]) ] self.data_queue.put([ip, final_sensor_config])
def button_set(self): """ Sends the update configuration command to the Sensor Units IP, along with the new configuration. """ network_commands = app_variables.CreateNetworkSendCommands() ip_list = self.ip_selection.get_verified_ip_list() threads = [] if len(ip_list) > 0: for ip in ip_list: try: if self.combo_dropdown_selection.value == "Installed Sensors": command = sensor_commands.CreateSensorNetworkCommand( ip, self.current_config.network_timeout_data, network_commands.set_installed_sensors) elif self.combo_dropdown_selection.value == "Configuration": command = sensor_commands.CreateSensorNetworkCommand( ip, self.current_config.network_timeout_data, network_commands.set_configuration) elif self.combo_dropdown_selection.value == "Wifi": command = sensor_commands.CreateSensorNetworkCommand( ip, self.current_config.network_timeout_data, network_commands.set_wifi_configuration) elif self.combo_dropdown_selection.value == "Trigger Variances": command = sensor_commands.CreateSensorNetworkCommand( ip, self.current_config.network_timeout_data, network_commands.set_variance_configuration) else: command = sensor_commands.CreateSensorNetworkCommand( ip, self.current_config.network_timeout_data, "") command.command = "" command.command_data = self.textbox_config.value.strip() threads.append( Thread(target=sensor_commands.put_command, args=[command])) except Exception as error: app_logger.sensor_logger.error(str(error)) for thread in threads: thread.start() guizero.info( "Sensors " + self.combo_dropdown_selection.value + " Set", self.combo_dropdown_selection.value + " set & services restarted on:\n" + str(ip_list)[1:-1]) else: app_useful_functions.no_ip_selected_message()
def _connect_to_sensor(self): """ Prompts for Database to open and opens it. """ ip_list = self.ip_selection.get_verified_ip_list() if len(ip_list) > 0: self.selected_ip = ip_list[0] self.text_connected_to.value = self.text_variables_sensor.text_connected_to[:-2] + self.selected_ip command = self.sensor_get_commands.database_notes network_timeout = self.current_config.network_timeout_data sensor_command = sensor_commands.CreateSensorNetworkCommand(self.selected_ip, network_timeout, command) test_database_notes = sensor_commands.get_data(sensor_command).split(",") if str(test_database_notes)[2:-2] == self.text_variables_generic.sensor_return_no_notes: self._no_sql_notes() else: self.database_notes = test_database_notes sensor_command.command = self.sensor_get_commands.database_note_dates self.database_notes_dates = sensor_commands.get_data(sensor_command).split(",") sensor_command.command = self.sensor_get_commands.database_user_note_dates self.database_user_note_dates = sensor_commands.get_data(sensor_command).split(",") count = 0 datetime_offset = self.current_config.datetime_offset for date in self.database_user_note_dates: new_date = self.adjust_datetime(date, datetime_offset) self.database_user_note_dates[count] = new_date count += 1 if len(self.database_notes) > 0: self.database_notes = self.undue_sterilize_notes(self.database_notes) self.textbox_total_notes.value = str(len(self.database_notes)) self.checkbox_use_current_datetime.enable() self.textbox_current_note.enable() self.textbox_on_number_notes.enable() self.textbox_current_note.value = self.database_notes[0] self.textbox_note_date.value = self.database_user_note_dates[0] self.textbox_on_number_notes.value = "1" self.button_next_note.enable() self.button_back_note.enable() self.button_delete_note.enable() self.button_new_note.enable() self.button_update_note.enable() else: self.textbox_current_note.enable() self.textbox_current_note.value = self.text_variables_generic.no_notes_found self._disable_notes_window_functions() else: self._disable_notes_window_functions() self.text_connected_to.value = self.text_variables_sensor.text_connected_to app_useful_functions.no_ip_selected_message()
def test_app_sensor_commands(self): print("\nThis REQUIRES an online sensor @ " + sensor_ip) get_network_commands = app_variables.CreateNetworkGetCommands() send_network_commands = app_variables.CreateNetworkSendCommands() network_timeout = config_default.network_timeout_data sensor_command = sensor_commands.CreateSensorNetworkCommand( sensor_ip, network_timeout, "") log_download = sensor_commands.CreateSensorNetworkCommand( sensor_ip, 2, get_network_commands.download_zipped_logs) zip_log_download_url = "http://" + log_download.ip + ":" + log_download.port + log_download.command sensor_commands.download_zipped_logs(zip_log_download_url) sensor_status = sensor_commands.check_sensor_status( sensor_ip, network_timeout) self.assertEqual(sensor_status, "Online") sleep(2) # self.assertTrue(os.path.isfile(save_to + sensor_ip[-3:].replace(".", "_") + "PrimaryLog.txt")) # self.assertTrue(os.path.isfile(save_to + sensor_ip[-3:].replace(".", "_") + "NetworkLog.txt")) # self.assertTrue(os.path.isfile(save_to + sensor_ip[-3:].replace(".", "_") + "SensorsLog.txt")) sensor_command.command = get_network_commands.sensor_name old_hostname = sensor_commands.get_data(sensor_command) verified_bad_hostname = sensor_commands.get_validated_hostname( "^^$##_###This.is$NOT-Good!**") self.assertEqual(verified_bad_hostname, "_________This_is_NOT_Good___") sensor_command.command = send_network_commands.set_host_name sensor_command.command_data = verified_bad_hostname sensor_commands.put_command(sensor_command) sensor_command.command = get_network_commands.sensor_name verify_hostname = sensor_commands.get_data(sensor_command) self.assertEqual(verify_hostname, verified_bad_hostname) sensor_command.command = send_network_commands.set_host_name sensor_command.command_data = old_hostname sensor_commands.put_command(sensor_command) sensor_command.command = get_network_commands.sensor_name verify_hostname = sensor_commands.get_data(sensor_command) self.assertEqual(verify_hostname, old_hostname)
def get_sensor_data(self, ip): """ Gets system report data from the provided sensor IP and puts it in the instance que. """ command_data = sensor_commands.CreateSensorNetworkCommand( ip, self.network_timeout, network_get_commands.system_data) sensor_system = sensor_commands.get_data(command_data).split(",") try: sensor_system[3] = app_useful_functions.convert_minutes_string( sensor_system[3]) except Exception as error: app_logger.app_logger.error("Sensor System Report: " + str(error)) self.data_queue.put([ip, sensor_system])
def _sensor_delete_button(self): current_note_on = int(self.textbox_on_number_notes.value) - 1 if guizero.yesno("Delete Note", "Are you sure you want to Delete Note " + self.textbox_on_number_notes.value + " out of " + self.textbox_total_notes.value + "?\n\n"): utc_0_datetime = self.database_notes_dates[current_note_on] command = self.network_send_commands.delete_sql_note network_timeout = self.current_config.network_timeout_data sensor_command = sensor_commands.CreateSensorNetworkCommand(self.selected_ip, network_timeout, command) sensor_command.command_data = utc_0_datetime sensor_commands.put_command(sensor_command) app_logger.sensor_logger.info("Deleted note from sensor " + self.selected_ip) self._connect_to_sensor()
def send_text_message(self, message): """ Sends Message to display on the sensors installed display. """ app_logger.sensor_logger.debug("Sending message to sensor") network_timeout = self.current_config.network_timeout_data ip_list = self.ip_selection.get_verified_ip_list() ip = ip_list[0] if len(ip_list) > 0: app_logger.sensor_logger.debug("Sent Message: " + str(message)) command = network_commands.display_message sensor_command = sensor_commands.CreateSensorNetworkCommand( ip, network_timeout, command) sensor_command.command_data = message message_thread = Thread(target=sensor_commands.put_command, args=[sensor_command]) message_thread.daemon = True message_thread.start() else: app_useful_functions.no_ip_selected_message()
def _download_logs(self): """ Download all selected and online sensors logs. """ ip_list = self.ip_selection.get_verified_ip_list() if len(ip_list) > 0: network_command_data = sensor_commands.CreateSensorNetworkCommand( "", self.current_config.network_timeout_data, self.network_get_commands.download_zipped_logs) for ip in ip_list: network_command_data.ip = ip network_command_data.check_for_port_in_ip() download_url = "http://" + \ network_command_data.ip + \ ":" + \ network_command_data.port + \ "/" + \ network_command_data.command print(download_url) sensor_commands.download_zipped_logs(download_url) else: app_useful_functions.no_ip_selected_message()
def _get_log(self): """ Displays the chosen remote sensor log. """ ip_list = self.ip_selection.get_verified_ip_list() if len(ip_list) > 0: network_timeout = self.current_config.network_timeout_data command_data = sensor_commands.CreateSensorNetworkCommand( ip_list[0], network_timeout, "GetNetworkLog") if self.radio_log_type.value == "Network Log": log = sensor_commands.get_data(command_data) elif self.radio_log_type.value == "Primary Log": command_data.command = "GetPrimaryLog" log = sensor_commands.get_data(command_data) elif self.radio_log_type.value == "Sensors Log": command_data.command = "GetSensorsLog" log = sensor_commands.get_data(command_data) else: app_logger.app_logger.error("Bad Log Request") log = "Bad Log Request" self.textbox_log.value = log else: app_useful_functions.no_ip_selected_message()
def _update_graph(self, x_frame): """ Update the Live Graph Instance. """ current_time = str(datetime.time(datetime.now()))[:8] network_timeout = self.current_config.network_timeout_data command_data = sensor_commands.CreateSensorNetworkCommand( self.ip, network_timeout, "") command_data.command = self.get_commands.sensor_name sensor_name = sensor_commands.get_data(command_data) sensor_reading, sensor_type_name, measurement_type = self._get_sensor_reading_name_unit( command_data) try: self.ax1.clear() self.y.append(sensor_reading) self.x.append(x_frame) self.ax1.plot(self.x, self.y) if self.sensor_type is "SensorUpTime": sensor_reading = app_useful_functions.convert_minutes_string( sensor_reading) pyplot.title(sensor_name + " || " + self.ip + "\n" + sensor_type_name) pyplot.xlabel("Start Time: " + self.first_datetime + " || Updated: " + current_time + "\nCurrent Reading: " + str(sensor_reading) + measurement_type) if self.sensor_type is "SensorUpTime": measurement_type = "Minutes" pyplot.ylabel(measurement_type) pyplot.xticks([]) except Exception as error: app_logger.app_logger.error("Live Graph - Invalid Sensor Data: " + str(error))
def _remote_sensor_display_selection(self): network_timeout = self.current_config.network_timeout_data ip_list = self.ip_selection.get_verified_ip_list() if len(ip_list) > 0: command_data = sensor_commands.CreateSensorNetworkCommand( ip_list[0], network_timeout, "") display_message = "" if self.checkbox_custom_text.value: add_text = simpledialog.askstring( "Send Text to Sensor Display", "") display_message += add_text if self.checkbox_up_time.value: command_data.command = get_commands.system_uptime add_text = sensor_commands.get_data(command_data) display_message += " UpTime: " + add_text if self.checkbox_cpu_temp.value: command_data.command = get_commands.cpu_temp add_text = sensor_commands.get_data(command_data) display_message += " CPU Temp: " + add_text if self.checkbox_temperature.value: command_data.command = get_commands.environmental_temp add_text = sensor_commands.get_data(command_data) display_message += " Env Temp: " + add_text if self.checkbox_pressure.value: command_data.command = get_commands.pressure add_text = sensor_commands.get_data(command_data) display_message += " Pressure: " + add_text if self.checkbox_altitude.value: command_data.command = get_commands.altitude add_text = sensor_commands.get_data(command_data) display_message += " Altitude: " + add_text if self.checkbox_humidity.value: command_data.command = get_commands.humidity add_text = sensor_commands.get_data(command_data) display_message += " Humidity: " + add_text if self.checkbox_distance.value: command_data.command = get_commands.distance add_text = sensor_commands.get_data(command_data) display_message += " Distance: " + add_text if self.checkbox_gas.value: command_data.command = get_commands.gas_reduced add_text = sensor_commands.get_data(command_data) display_message += " GAS: " + add_text if self.checkbox_particulate_matter.value: command_data.command = get_commands.pm_1 add_text = sensor_commands.get_data(command_data) display_message += " PM: " + add_text if self.checkbox_lumen.value: command_data.command = get_commands.lumen add_text = sensor_commands.get_data(command_data) display_message += " Lumen: " + add_text if self.checkbox_colour.value: command_data.command = get_commands.rgb add_text = sensor_commands.get_data(command_data) display_message += " Colour: " + add_text if self.checkbox_ultra_violet.value: command_data.command = get_commands.ultra_violet_a add_text = sensor_commands.get_data(command_data) display_message += " UV: " + add_text if self.checkbox_acc.value: command_data.command = get_commands.accelerometer_xyz add_text = sensor_commands.get_data(command_data) display_message += " Acc: " + add_text if self.checkbox_mag.value: command_data.command = get_commands.magnetometer_xyz add_text = sensor_commands.get_data(command_data) display_message += " Mag: " + add_text if self.checkbox_gyro.value: command_data.command = get_commands.gyroscope_xyz add_text = sensor_commands.get_data(command_data) display_message += " Gyro: " + add_text if display_message != "": self.send_text_message(display_message) else: app_useful_functions.no_ip_selected_message()
def get_sensor_data(self, ip): """ Gets readings report data from the provided sensor IP and puts it in the instance que. """ command_data = sensor_commands.CreateSensorNetworkCommand( ip, self.network_timeout, network_get_commands.sensor_readings) sensor_data = sensor_commands.get_data(command_data).split(",") self.data_queue.put([ip, sensor_data])