def stop_wifi(self): if not zynconf.stop_wifi(): self.zyngui.show_info("STOPPING WIFI ERROR\n") self.zyngui.add_info("Can't stop WIFI network!", "WARNING") self.zyngui.hide_info_timer(2000) self.fill_list()
def post(self): errors = [] try: action = self.get_argument('ZYNTHIAN_WIFI_ACTION') logging.debug("ACTION: {}".format(action)) except: action = "SET_MODE" try: if action == "ADD_NETWORK": newSSID = self.get_argument('ZYNTHIAN_WIFI_NEW_SSID') newPassword = self.get_argument('ZYNTHIAN_WIFI_NEW_PASSWORD') if newSSID and newPassword: self.add_new_network(newSSID, newPassword) elif action[:7] == "REMOVE_": delSSID = action[7:] self.remove_network(delSSID) elif action[:7] == "UPDATE_": updSSID = action[7:] updOptions = self.get_argument( 'ZYNTHIAN_WIFI_OPTIONS_{}'.format(updSSID)) self.update_network_options(updSSID, updOptions) elif action == "SET_MODE": wifi_mode = self.get_argument('ZYNTHIAN_WIFI_MODE') current_wifi_mode = zynconf.get_current_wifi_mode() if wifi_mode != current_wifi_mode: if wifi_mode == "on": if not zynconf.start_wifi(): errors.append("Can't start WIFI network!") elif wifi_mode == "hotspot": if not zynconf.start_wifi_hotspot(): errors.append("Can't start WIFI Hotspot!") else: if not zynconf.stop_wifi(): errors.append("Can't stop WIFI!") except Exception as e: errors.append(e) self.get(errors)
def post(self): errors = [] try: #Remove CR characters added by x-www-form-urlencoded wpa_supplicant_data = self.get_argument('ZYNTHIAN_WIFI_WPA_SUPPLICANT').replace("\r\n", "\n") #Apply changes: delete network, change password, ... wpa_supplicant_data = self.apply_updated_fields(wpa_supplicant_data, ["ZYNTHIAN_WIFI_PRIORITY"]) newSSID = self.get_argument('ZYNTHIAN_WIFI_NEW_SSID') if newSSID: wpa_supplicant_data = self.add_new_network(wpa_supplicant_data, newSSID) fo = open(self.wpa_supplicant_config_fpath, "w") fo.write(wpa_supplicant_data) fo.flush() fo.close() except Exception as e: errors.append(e) try: wifi_mode = self.get_argument('ZYNTHIAN_WIFI_MODE') if wifi_mode == "on": if not zynconf.start_wifi(): errors.append("Can't start WIFI network!") elif wifi_mode == "hotspot": if not zynconf.start_wifi_hotspot(): errors.append("Can't start WIFI Hotspot!") else: if not zynconf.stop_wifi(): errors.append("Can't stop WIFI!") except Exception as e: errors.append(e) self.get(errors)