Ligne 25 : |
Ligne 25 : |
| * [[Hack-wipy-repl#Obtenir_une_ligne_de_commande_REPL|duplicate the REPL on UART]], so that you can run commands via USB. | | * [[Hack-wipy-repl#Obtenir_une_ligne_de_commande_REPL|duplicate the REPL on UART]], so that you can run commands via USB. |
| }} | | }} |
| + | |
| + | |
| + | == Vous connecter sur votre routeur WiFi == |
| + | The WLAN network card always boots in WLAN.AP mode, so we must first configure it as a station: |
| + | |
| + | <syntaxhighlight lang="python"> |
| + | from network import WLAN |
| + | wlan = WLAN(mode=WLAN.STA) |
| + | </syntaxhighlight> |
| + | |
| + | Now you can proceed to scan for networks: |
| + | |
| + | <syntaxhighlight lang="python"> |
| + | nets = wlan.scan() |
| + | for net in nets: |
| + | if net.ssid == 'mywifi': |
| + | print('Network found!') |
| + | wlan.connect(net.ssid, auth=(net.sec, 'mywifikey'), timeout=5000) |
| + | while not wlan.isconnected(): |
| + | machine.idle() # save power while waiting |
| + | print('WLAN connection succeeded!') |
| + | break |
| + | </syntaxhighlight> |
| + | |
| + | == Assigner une adresse IP Fixe == |
| + | If you want your WiPy to connect to your home router after boot-up, and with a fixed IP address so that you can access it via telnet or FTP, use the following script as {{fname|/flash/boot.py}}: |
| + | |
| + | <syntaxhighlight lang="python"> |
| + | import machine |
| + | from network import WLAN |
| + | wlan = WLAN() # get current object, without changing the mode |
| + | |
| + | if machine.reset_cause() != machine.SOFT_RESET: |
| + | wlan.init(WLAN.STA) |
| + | # configuration below MUST match your home router settings!! |
| + | wlan.ifconfig(config=('192.168.178.107', '255.255.255.0', '192.168.178.1', '8.8.8.8')) |
| + | |
| + | if not wlan.isconnected(): |
| + | # change the line below to match your network ssid, security and password |
| + | wlan.connect('mywifi', auth=(WLAN.WPA2, 'mywifikey'), timeout=5000) |
| + | while not wlan.isconnected(): |
| + | machine.idle() # save power while waiting |
| + | </syntaxhighlight> |
| + | |
| + | {{ambox|text=Notice how we check for the reset cause and the connection status, this is crucial in order to be able to soft reset the WiPy during a telnet session without breaking the connection.}} |
| | | |
| {{WIPY-TRAILER}} | | {{WIPY-TRAILER}} |