Différences entre versions de « Hack-wipy-wlan »
Ligne 4 : | Ligne 4 : | ||
== Configuration WLAN étape par étape == | == Configuration WLAN étape par étape == | ||
− | + | Le système WLAN (WiFi) est une fonctionnalité du WiPy, elle est par conséquent toujours activée, même durant un {{fname|machine.SLEEP}}. Le seul moment où le WLAN est indisponible c'est quand le WiPy est en mode ''deepsleep'' (hibernation). | |
− | + | Si vous avez besoin d'obtenir l'instance WLAN en cours d'utilisation, faites: | |
<syntaxhighlight lang="python"> | <syntaxhighlight lang="python"> | ||
>>> from network import WLAN | >>> from network import WLAN | ||
− | >>> wlan = WLAN() # | + | >>> wlan = WLAN() # nous appelons le constructeur dans paramètres. |
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | Vous pouvez vérifier le mode de fonctionnement actuel du WLAN comme suit: | |
<syntaxhighlight lang="python"> | <syntaxhighlight lang="python"> | ||
Ligne 19 : | Ligne 19 : | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | {{ | + | Note: Après une mise sous tension, le mode est toujours {{fname|WLAN.AP}} (soit en ''Access Point''/point d'accès) |
− | + | {{ambox-stop|text=Lorsque vous modifiez le mode WLAN en suivant les instructions ci-desssous, votre connexion WLAN avec le WiPy sera interrompue! Cela signifie que vous ne serez pas capable d'exécuter les commandes en mode interactif via une connexion WLAN. | |
− | * | + | |
− | * [[Hack-wipy-repl#Obtenir_une_ligne_de_commande_REPL| | + | Il y a deux solutions pour contourner cette difficultés: |
+ | * Vous placez cette configuration dans votre fichier [https://micropython.org/resources/docs/en/latest/wipy/wipy/general.html#wipy-filesystem boot.py] qui est automatiquement exécuté après une réinitialisation/Reset. | ||
+ | * Vous [[Hack-wipy-repl#Obtenir_une_ligne_de_commande_REPL|dupliquez l'invite REPL sur le port série/UART]] de sorte qu'il est possible d'exécuter toutes les commandes via USB. | ||
}} | }} | ||
− | |||
== Vous connecter sur votre routeur WiFi == | == Vous connecter sur votre routeur WiFi == |
Version du 1 juin 2016 à 15:00
En cours de traduction/élaboration. |
Configuration WLAN étape par étape
Le système WLAN (WiFi) est une fonctionnalité du WiPy, elle est par conséquent toujours activée, même durant un machine.SLEEP. Le seul moment où le WLAN est indisponible c'est quand le WiPy est en mode deepsleep (hibernation).
Si vous avez besoin d'obtenir l'instance WLAN en cours d'utilisation, faites:
>>> from network import WLAN
>>> wlan = WLAN() # nous appelons le constructeur dans paramètres.
Vous pouvez vérifier le mode de fonctionnement actuel du WLAN comme suit:
>>> wlan.mode()
Note: Après une mise sous tension, le mode est toujours WLAN.AP (soit en Access Point/point d'accès)
Lorsque vous modifiez le mode WLAN en suivant les instructions ci-desssous, votre connexion WLAN avec le WiPy sera interrompue! Cela signifie que vous ne serez pas capable d'exécuter les commandes en mode interactif via une connexion WLAN.
Il y a deux solutions pour contourner cette difficultés:
|
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:
from network import WLAN
wlan = WLAN(mode=WLAN.STA)
Now you can proceed to scan for networks:
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
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 /flash/boot.py:
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
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. |
Tutoriel WiPy tutorials and examples & general information about WiPy sous copyright de Damien George et contributeurs en ce qui concerne MicroPython et/ou PyCom en ce qui concerne les informations relatives a WiPy et LoPy.
Tutoriel traduit par Meurisse D. pour MCHobby.be
Traduit avec l'autorisation de micropython.org - Translated with the authorisation of micropython.org également avec l'accord de Daniel Compara (créateur de WiPy).
Toute référence, mention ou extrait de cette traduction doit être explicitement accompagné du texte suivant : « Traduction par MCHobby (www.MCHobby.be) - Vente de kit et composants » avec un lien vers la source (donc cette page) et ce quelque soit le média utilisé.
L'utilisation commercial de la traduction (texte) et/ou réalisation, même partielle, pourrait être soumis à redevance. Dans tous les cas de figures, vous devez également obtenir l'accord du(des) détenteur initial des droits. Celui de MC Hobby s'arrêtant au travail de traduction proprement dit.