def sta_active(mode): sta = network.WLAN(network.STA_IF) sta.active(mode) if mode is True: from utils import connect_wifi, get_wifi_data essid, password = get_wifi_data() if essid: connect_wifi(sta, essid, password)
def __init__(self, ssid: str, **kwargs): if not connect_wifi(ssid): raise OSError(f"Failed to connect to wifi {ssid}") self.udp_address = 'udp://@' + self.VS_UDP_IP + ':' + str( self.VS_UDP_PORT) self.armed = False self.command_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.stream = CameraStream(self.udp_address, **kwargs) self.is_flying = False self.is_streaming = False
def check_mac(): devices = Device() mac = Mac() macs = [] data_list = devices.get(page='all') for data in data_list: macs.append(data['mac']) while True: wifi_connected = utils.check_wifi_connected() if not wifi_connected: utils.connect_wifi() for ip in range(155): if ip not in [0, 1, 2, 5, 255]: network = utils.check_arp(ip) if network: # app.logger.info(network) if network['mac'] not in macs: macs.append(network['mac']) devices.new_post({'mac': network['mac']}) mac.post(network) time.sleep(5)
async def main(): # get configuration from file with open("configuration.json") as f: conf = json.load(f) # wifi is not connected we just got the coroutine wifi = connect_wifi(ssid=conf["network"]["ssid"], passphrase=conf["network"]["passphrase"]) # mqtt mqtt = MQTTCommunicator(host=conf["mqtt"]["host"], wifi_network=wifi) # sensor for sensor in conf["sensors"]: if sensor["class"] not in sensor_class: print("Sensor class %s not available" % (sensor["class"])) continue print("Activate sensor %s (%s)" % (sensor['name'], sensor['class'])) s = sensor_class[sensor["class"]](sensor, communicator=mqtt) asyncio.ensure_future(s.run())
def connect_wifi(self): """ Connect to a specific WIFI hotspot with SSID and password """ params = request.get_json() return jsonify({'success': utils.connect_wifi(params['ssid'], params['password'])})