diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d448f36 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +code/wifi_config.py diff --git a/code/boot.py b/code/boot.py index aed995d..0ce4ca6 100644 --- a/code/boot.py +++ b/code/boot.py @@ -1,7 +1,32 @@ # This file is executed on every boot (including wake-boot from deepsleep) #import esp #esp.osdebug(None) + import gc +import time +import network import webrepl +from wifi_config import known_wifi_ap + +# Connect to one of the known wifi AP +interface = network.WLAN(network.STA_IF) +interface.active(True) +wifi_ap_list = interface.scan() + +for ap in wifi_ap_list: + if interface.isconnected(): + break + + ap_ssid = ap[0].decode("utf-8") + if ap_ssid in known_wifi_ap.keys(): + print("Known wifi network found : {}".format(ap_ssid)) + print("Try to connect...") + interface.connect(ap_ssid, known_wifi_ap[ap_ssid]) + +# Wait for wifi +time.sleep(5) + webrepl.start() + +print("Boot.py : Done") gc.collect() diff --git a/code/main.py b/code/main.py index c961d34..e20dd3b 100644 --- a/code/main.py +++ b/code/main.py @@ -23,6 +23,7 @@ __version__ = 0.2 import time import machine import neopixel + from uos import uname from encoder import Encoder @@ -84,7 +85,7 @@ ENCODER = Encoder(ENC_PIN_B, ENC_PIN_A, ENC_BUT = machine.Pin(ENC_PIN_C, machine.Pin.IN) #Variables d'état -BRIGHTN = 0 # Luminosité (0 - 100) +BRIGHTN = 50 # Luminosité (0 - 100) PWR = False # Est-ce que l'éclairage est allumé ? BUTTN_STATE = 1 diff --git a/code/wifi_config_template.py b/code/wifi_config_template.py new file mode 100644 index 0000000..7c91b2e --- /dev/null +++ b/code/wifi_config_template.py @@ -0,0 +1,6 @@ +# Just a dic with each known wifi access point's SSID and WPA key +# Update it with your own setting and rename it "wifi_config.py" + +known_wifi_ap = {"wifi_ssid": "wifi_wpa_key", + "wifi_ssid_2": "wifi_wpa_key_2", + } diff --git a/pymakr_wifi.conf b/pymakr_wifi.conf new file mode 100644 index 0000000..3628488 --- /dev/null +++ b/pymakr_wifi.conf @@ -0,0 +1,10 @@ +{ + "address": "192.168.1.20", + "username": "", + "password": "frE3d0M4", + "sync_folder": "code", + "sync_file_types": "py,txt,log,json,xml,html,js,css,mpy,pem,cet,crt,key", + "sync_all_file_types": true, + "open_on_start": true, + "safe_boot_on_upload": false +}