Introduction
Introduction Statistics Contact Development Disclaimer Help
example.py - brcon2025-hackathons - Bitreichcon 2025 Hackathons
git clone git://bitreich.org/brcon2025-hackathons git://enlrupgkhuxnvlhsf6lc3fz…
Log
Files
Refs
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()
You are viewing proxied material from bitreich.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.