def check_WiFi(): global containerID global floor global brokerIP WiFiState = 0 WiFiTime = time.time() WiFiCount = 0 prevWiFiState = 0 while True: if (time.time() - WiFiTime > 20): if (sysRasp.isWiFi()): if (prevWiFiState == 2): ID, fl, IP = sysRasp.getData_JSON(sysRasp.PATH) if (ID != containerID and ID != ""): containerID = ID if (fl != floor and fl != ""): floor = fl if (IP != brokerIP and IP != ""): brokerIP = IP prevWiFiState = WiFiState WiFiState = 1 # Conected to WiFi WiFiCount = 0 elif (sysRasp.isAP()): prevWiFiState = WiFiState WiFiState = 2 # Access Point created WiFiCount = 0 else: prevWiFiState = WiFiState WiFiState = 0 # Not accesPoint or WiFi WiFiCount += 1 WiFiTime = time.time() if (WiFiCount >= 5): WiFiCount = 0 print("Configuring AP...") sysRasp.runShellCommand('sudo python APconfig.py')
import sys sys.path.insert(0, '../') from sysRasp import runShellCommand, getOutput_ShellCommand # Check Alternatives alt = getOutput_ShellCommand('update-alternatives --list python') if (alt == ''): runShellCommand( "sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1" ) runShellCommand( "sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.5 2" ) # Set Python Version runShellCommand("sudo update-alternatives --set python /usr/bin/python3.5")
from sysRasp import runShellCommand import json with open("../data/data.json", "r") as f: data = json.load(f) ssid = data["ssid"] password = data["password"] f.close() if (runShellCommand( 'cp /etc/wpa_supplicant/wpa_supplicant.conf wpa_supplicant.conf')): print("Getting WiFi settings...") else: print("Error: Cannot get WiFi settings") with open("wpa_supplicant.conf", "a+") as f: f.write("\nnetwork={\n") f.write('\tssid="{}"\n'.format(ssid)) f.write('\tpsk="{}"\n'.format(password)) f.write('\tkey_mgmt=WPA-PSK\n') f.write("}") f.close if (runShellCommand( 'sudo cp wpa_supplicant.conf /etc/wpa_supplicant/wpa_supplicant.conf') ): print("Adding new WiFi settings...") else: print("Error: Cannot add new WiFi settings") if (runShellCommand('rm wpa_supplicant.conf')):
import sys sys.path.insert(0, '../') from sysRasp import runShellCommand # Create camera1 in motionEye runShellCommand( 'sudo cp ../configFiles_MotionEye/camera-1.conf /etc/motioneye/camera-1.conf' ) # Change to python 2 runShellCommand('sudo python python3to2.py') # Restart motionEye runShellCommand('sudo systemctl restart motioneye') # Change to python 3 runShellCommand('sudo python python2to3.py')
import sys sys.path.insert(0, '../') from sysRasp import runShellCommand # Remove camera1 in motionEye runShellCommand('sudo rm /etc/motioneye/camera-1.conf') # Change to python 2 runShellCommand('sudo python python3to2.py') # Restart motionEye runShellCommand('sudo systemctl restart motioneye') # Change to python 3 runShellCommand('sudo python python2to3.py')
import sys sys.path.insert(0, '../') from sysRasp import runShellCommand # Stop hostapd if (runShellCommand('sudo systemctl stop hostapd')): print("Service: hostapd stopped") else: print("Error: stopping hostpad service") # Stop dnsmasq if (runShellCommand('sudo systemctl stop dnsmasq')): print("Service: dnsmasq stoped") else: print("Error: stopping hostpad service") # Save dhcpcd.conf if (runShellCommand('sudo cp /etc/dhcpcd.conf.orig /etc/dhcpcd.conf')): print("File: dhcpcd.conf saved") else: print("Error: saving dhcpcd.conf") # Restart dhcpcd if (runShellCommand('sudo systemctl restart dhcpcd')): print("Service: dhcpcd restarted") else: print("Error: restarting hostpad service") # Save hostapd.conf if (runShellCommand(
import sys sys.path.insert(0, '../') from sysRasp import runShellCommand, existFile # Stop hostapd if (runShellCommand('sudo systemctl stop hostapd')): print("Service: hostapd stopped") else: print("Error: stopping hostpad service") # Stop dnsmasq if (runShellCommand('sudo systemctl stop dnsmasq')): print("Service: dnsmasq stoped") else: print("Error: stopping hostpad service") # Save dhcpcd.conf if (runShellCommand('sudo cp /etc/dhcpcd.conf.ap /etc/dhcpcd.conf')): print("File: dhcpcd.conf saved") else: print("Error: saving dhcpcd.conf") # Restart dhcpcd if (runShellCommand('sudo systemctl restart dhcpcd')): print("Service: dhcpcd restarted") else: print("Error: restarting hostpad service") # Check if hostapd.conf exist if (existFile('/etc/hostapd/hostapd.conf.ap') == False): # Create file