Reorganisation

Add pyportal-controller "sub-project"
This commit is contained in:
Pierrick C 2020-04-05 18:15:20 +02:00
parent 97a81aec58
commit 9fc6f5f94f
19 changed files with 47 additions and 0 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
config.py config.py
*~ *~
.ropeproject*

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,46 @@
import board
import busio
from digitalio import DigitalInOut
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
from adafruit_esp32spi import adafruit_esp32spi
import adafruit_requests as requests
import config
# If you are using a board with pre-defined ESP32 Pins:
esp32_cs = DigitalInOut(board.ESP_CS)
esp32_ready = DigitalInOut(board.ESP_BUSY)
esp32_reset = DigitalInOut(board.ESP_RESET)
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
requests.set_socket(socket, esp)
if esp.status == adafruit_esp32spi.WL_IDLE_STATUS:
print("ESP32 found and in idle mode")
print("Firmware vers.", esp.firmware_version)
print("MAC addr:", [hex(i) for i in esp.MAC_address])
print("Connecting to AP...")
def WifiConnect(ssid, psk):
"""Connect to the wifi with given credentials."""
nets = esp.scan_networks()
for net in nets:
net_ssid = net['ssid']
if net_ssid == bytearray(ssid):
print('Network found!')
esp.connect_AP(net_ssid, psk)
while not esp.is_connected:
machine.idle() # save power while waiting
print('WLAN connection succeeded!')
break
if not esp.is_connected:
print("WLAN not found/not connected")
WifiConnect(config.WIFI_SSID, config.WIFI_PSK)
print("Connected to", str(esp.ssid, "utf-8"), "\tRSSI:", esp.rssi)
print("My IP address is", esp.pretty_ip(esp.ip_address))