Created
October 4, 2022 15:15
-
-
Save DavesCodeMusings/ef015591a182ebb09062854c6ad08489 to your computer and use it in GitHub Desktop.
MicroPython WebREPL with IP address on OLED and screen saver function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Enable MicroPython WebREPL (Console over Websockets) | |
| from machine import Pin, SoftI2C | |
| from ssd1306 import SSD1306_I2C | |
| from network import WLAN, STA_IF | |
| from webrepl import start | |
| from netcfg import AP_NAME, AP_PASS, WEBREPL_PASS | |
| from ubinascii import a2b_base64 | |
| from time import sleep | |
| i2c = SoftI2C(scl=Pin(4), sda=Pin(5)) # Wemos board with built-in OLED uses pins 4 (clock) & 5 (data) | |
| oled = SSD1306_I2C(128, 64, i2c) | |
| oled.fill(0) | |
| oled.show() | |
| wlan = WLAN(STA_IF) | |
| wlan.active(True) | |
| print("Connecting to wifi...") | |
| oled.text('Connecting...', 0, 0) | |
| oled.show() | |
| if not wlan.isconnected(): | |
| wlan.connect(AP_NAME, a2b_base64(AP_PASS).decode('utf8')) | |
| while not wlan.isconnected(): | |
| pass | |
| start(password=a2b_base64(WEBREPL_PASS).decode('utf8')) | |
| oled.text(wlan.ifconfig()[0], 0, 12) | |
| oled.show() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Blank the OLED screen after a bit of time to save battery and avoid burn-in. | |
| from machine import Timer | |
| screen_timeout = 30000 # In milliseconds | |
| def clearScreen(screen_timer): | |
| oled.fill(0) # oled was created in boot.py | |
| oled.show() | |
| screen_timer = Timer(0) | |
| screen_timer.init(period=screen_timeout, mode=Timer.ONE_SHOT, callback=clearScreen) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Passwords are base64 encoded. | |
| # *** Encoding is not the same as encryption! *** | |
| # Encoding is used here to avoid casual, over the shoulder password leaks. | |
| # Encode password values with: | |
| # >>> from ubinascii import b2a_base64 | |
| # >>> print(b2a_base64('PlainTextPassword').decode('utf8')) | |
| AP_NAME = 'RickRoll' | |
| AP_PASS = 'TmV2ZXJHb25uYUdpdmVZb3VVcA==' | |
| WEBREPL_PASS = 'TmV2ZXI=' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment