def boot(): print('\n\nStarting system\n-----------------------') wifi.ap_on() nsv.start() credentials_state, cred_ssid, cred_psw = wifi.get_credentials() while credentials_state == False: print('Getting credentials...') credentials_state, cred_ssid, cred_psw = wifi.get_credentials() sleep(1) pass sleep(1) wifi_connected = wifi.connect(cred_ssid, cred_psw) while wifi_connected == False: print("WIFI not ready. Wait...") sleep(1) pass print('Connection successful\n') print('Check for updates') if update.check('sys_info')[0] == True: print('\nSystem OUTDATED') update.system() print('\nSystem UPDATED') print('\nRestarting system\n-----------------------\n\n') machine.reset() else: print('\nSystem up to date\nStart system') comv3.start(10)
def st_server(): print(blue + '\n\nStarting ST Server\n-----------------------') print('Check WiFi credentials\n') credentials_state, cred_ssid, cred_psw = wifi.get_credentials() while credentials_state == False: print('Getting credentials...') credentials_state, cred_ssid, cred_psw = wifi.get_credentials() sleep(1) pass print(green + 'Got WiFi credentials\n') wifi_connected = wifi.connect(cred_ssid, cred_psw) while wifi_connected == False: print("WIFI not ready. Wait...") sleep(2) pass print(green + 'Connection successful\n') while True: port = 80 wlan_ip = network.WLAN(network.STA_IF).ifconfig()[0] st_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) st_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) st_socket.bind((wlan_ip, port)) st_socket.listen(2) print('\nSocket now listening on', str(wlan_ip) + ':' + str(port)) while True: gc.collect() client, address = st_socket.accept() ip, port = str(address[0]), str(address[1]) print('\n{') print(green + 'Connection from ' + ip + ':' + port) try: th_new(handle_client, (client, ip, port)) except: print('error creating handle_client thread') st_socket.close() print('st_socket closed')
def boot(): print('\n\nStarting system\n-----------------------') print('Check WiFi credentials') credentials_state, cred_ssid, cred_psw = wifi.check_credentials() if credentials_state == True: print('Credentials true, connect to WIFI') wifi_state = wifi.connect(cred_ssid,cred_psw) if wifi_state == True: print('Check for updates') if update.check('sys_info')[0] == True: print('\nSystem OUTDATED') update.system() print('\nSystem UPDATED') print('\nRestarting system\n-----------------------\n\n') machine.reset() else: print('\nSystem up to date\nStart system') system.start() else: wifi.get_credentials()
import socket import time import dht import json import machine from machine import Timer, Pin import uasyncio as asyncio from time import sleep import uerrno from structure import machine_data, color, cam, wifi import gc import camera cam.start() wifi.connect('1255', '12551255') data_host = "asmon.com.ar" USER = "******" data_address = '' cam_address = '' json_command = {} h = { 'POST': """POST /$req HTTP/1.1 Host: 127.0.0.1:9515 X-AIO-Key: xxxxxxxxxxxxxxxxxxx Content-Type: $type Content-Length: """ }
file.close() wifi.start() sleep(1) wifi.set_credentials('1255,12551255') credentials_state, cred_ssid, cred_psw = wifi.get_credentials() while credentials_state == False: print('Getting credentials...') credentials_state, cred_ssid, cred_psw = wifi.get_credentials() sleep(1) pass sleep(1) wifi_connected = wifi.connect(cred_ssid, cred_psw) while wifi_connected == False: print("WIFI not ready. Wait...") sleep(2) pass print(green + 'Connection successful\n' + normal) pic = frame_gen() flash_light = Pin(04, Pin.OUT) socks = sockets() ports = [port1, port2] # 80, 81, 82 th(srv, (0, )) print(green + 'server started' + normal)