Merge branch 'wifi' into 'master'

Wifi

See merge request arofarn/micropy-light!2
This commit is contained in:
Pierrick C 2018-11-18 23:15:25 +01:00
commit 32ebdd4d30
5 changed files with 44 additions and 1 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
code/wifi_config.py

View File

@ -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()

View File

@ -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

View File

@ -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",
}

10
pymakr_wifi.conf Normal file
View File

@ -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
}