Dépot de code divers pour mon TTGO v1.1
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.9 KiB

8 months ago
8 months ago
8 months ago
  1. """
  2. Connect to a Wifi Hotspot, creds are stored in 'creds' file.
  3. """
  4. import network
  5. # For display
  6. import random
  7. from machine import Pin, SPI
  8. import st7789 as st7789
  9. import time
  10. import utime
  11. # Choose a font
  12. #from fonts import vga1_8x8 as font
  13. #from fonts import vga2_8x8 as font
  14. #from fonts import vga1_8x16 as font
  15. from fonts import vga2_8x16 as font
  16. #from fonts import vga1_16x16 as font
  17. #from fonts import vga1_bold_16x16 as font
  18. #from fonts import vga2_16x16 as font
  19. #from fonts import vga2_bold_16x16 as font
  20. def main():
  21. tft = st7789.ST7789(
  22. SPI(2, baudrate=30000000, polarity=1, phase=1, sck=Pin(18), mosi=Pin(19)),
  23. 135,
  24. 240,
  25. reset=Pin(23, Pin.OUT),
  26. cs=Pin(5, Pin.OUT),
  27. dc=Pin(16, Pin.OUT),
  28. backlight=Pin(4, Pin.OUT),
  29. rotation=3
  30. )
  31. tft.init()
  32. tft.fill(st7789.BLACK)
  33. file = open('creds', 'r')
  34. wifi_ssid = file.readline().rstrip("\n")
  35. wifi_pass = file.readline().rstrip("\n")
  36. file.close()
  37. wlan = network.WLAN(network.STA_IF)
  38. wlan.active(True)
  39. if not wlan.isconnected():
  40. tft.text(font, "Init", 0, 0, st7789.WHITE)
  41. print('Init connection to Wifi...')
  42. wlan.connect(wifi_ssid, wifi_pass)
  43. while not wlan.isconnected():
  44. tft.text(font, "Connecting ...", 0, 0, st7789.RED)
  45. print('connecting...')
  46. utime.sleep(1)
  47. tft.text(font, "Connecting ...", 0, 0, st7789.BLACK)
  48. pass
  49. tft.text(font, "Connected", 0, 0, st7789.WHITE)
  50. print('Connected')
  51. wlan_config = wlan.ifconfig()
  52. print('network config:', wlan_config)
  53. tft.text(font, "IP/network: ", 0, 32, st7789.WHITE)
  54. tft.text(font, wlan_config[0] + "/" + wlan_config[1], 10, 53, st7789.GREEN)
  55. tft.text(font, "Gw/DNS: ", 0, 75, st7789.WHITE)
  56. tft.text(font, wlan_config[2] + "/" + wlan_config[3], 10, 96, st7789.GREEN)
  57. main()