example.py - brcon2025-hackathons - Bitreichcon 2025 Hackathons
 (HTM) git clone git://bitreich.org/brcon2025-hackathons git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/brcon2025-hackathons
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) Tags
       ---
       example.py (864B)
       ---
            1 #!/usr/bin/env micropython
            2 # coding=utf-8
            3 #
            4 # This is an example script that you can load into MicroPython prompt to
            5 # connect yourself to the WiFi access point.
            6 #
            7 
            8 import network
            9 import socket
           10 
           11 wlan = network.WLAN()
           12 wlan.active(True)
           13 wlan.scan()
           14 wlan.connect('seeeder', 'seeedrooots')
           15 
           16 while not wlan.isconnected():
           17         print('.', end='')
           18 
           19 print(' connected')
           20 
           21 myip = wlan.ipconfig('addr4')[0]
           22 print(myip)
           23 
           24 # To access internet services:
           25 # https://docs.micropython.org/en/latest/library/socket.html
           26 
           27 bindport = 70
           28 maxconn = 100
           29 myport = 7000 + int(myip.split('.')[3])
           30 myserver = 'bitreich.org'
           31 
           32 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
           33 s.bind((myip, bindport))
           34 s.listen(maxconn)
           35 
           36 print("available at gopher://%s:%u/0/" % (myserver, myport))
           37 
           38 while True:
           39         conn, addr = s.accept()
           40         conn.write("hello world!\r\n")
           41         conn.write(".\r\n")
           42         conn.close()