FEATHER-WEBREPL-ACCESS

De MCHobby - Wiki
Sauter à la navigation Sauter à la recherche


MCHobby investit du temps et de l'argent dans la réalisation de traduction et/ou documentation. C'est un travail long et fastidieux réalisé dans l'esprit Open-Source... donc gratuit et librement accessible.
SI vous aimez nos traductions et documentations ALORS aidez nous à en produire plus en achetant vos produits chez MCHobby.

Activer WebREPL

La première étape pour utiliser WebREPL est de vous assurer qu'il est activé sur votre carte ESP8266. La façon la plus simple d'activer WebREPL est de charger le "Build Officiel di Firmware MicroPython ESP8266" sur votre carte. Le build officiel dispose de WebREPL activé par défaut. Les builds officiels sont disponibles sur la page de téléchargement de MicroPython. Sélectionnez une version stable disposant proposant un numéro comme 1.8.3 (laissez de côté les builds journaliers qui portent un numéro comme 1.8.3-52-gb0e2106).

Voyez notre guide décrivant comment flasher le Firmware MicroPython sur une carte si vous ne savez pas encore comment faire.

Si vous utilisez un build journalier ou build de développement vous devez activer manuellement WebREPL comme mentionné dans la documentation (micropython.org). Connectez vous à votre carte en REPL via une connexion série et exécutez les commandes suivantes:

import webrepl
webrepl.start()

 
Crédit: AdaFruit Industries www.adafruit.com

Vous devriez-vous voir le WebREPL démarrer et afficher une adresse IP affichée dans le terminal. Vous pourrez utiliser cette adresse IP pour vous connecter sur WebREPL. Vous ne pouvez pas accéder à WebREPL directement depuis votre navigateur Internet. A la place, vous devez charger une page "WebREPL.html" dans votre navigateur Internet, cette page vous permettra alors d'accéder à la console WebREPL de votre ESP8266.

La procédure est décrite dans ce tuto.

Accéder à WebREPL

Une fois que WebREPL s'exécuter, vous pourrez vous connecter dessus via l'interface WiFi de votre ESP8266. Si la carte n'est pas déjà connectée sur un point d'accès WiFi alors WebREPL en créera un sur lequel vous pourrez vous connecter depuis votre ordinateur.

Pour vous connecter sur le Réseau WiFi créé par la carte cherchez après un réseau WiFi qui s'annonce avec le préfix MicroPython-*:

 
Crédit: AdaFruit Industries www.adafruit.com

Où le caractère * est une suite de numéro et lettre unique pour chaque carte ESP8266 (basé sur son adresse MAC).

Vous aurez besoin de saisir le mot de passe micropythoN pour vous connecter sur le point d'accès de la carte (le N est en capital!). Si vous rencontrez des problèmes, vous pouvez trouver plus de détails sur la page "connecting to the board's WiFi network" de la documentation officielle.

Ensuite, vous aurez besoin d'un client web REPL actif sur votre ordinateur (dans un navigateur Internet). Vous pouvez soit utiliser la page WebREPL client depuis micropython.org (assurez-vous, dans ce cas, que votre ordinateur est connecté à la fois sur Internet et votre réseau local) ou en téléchargeant le client WebREPL depuis GitHub en cliquant sur le bouton suivant et faisant une extraction des fichiers contenu dans l'archive:

Si vous avez téléchargé le client WebREPL, vous disposerez d'un fichier webrepl.html que vous pourrez ouvrir dans votre navigateur (Firefox et Chrome sont officiellement supportés).

Note: Vous ne pouvez pas accéder à la page WebREPL client directement depuis la carte ESP8266. Cela permet d'économiser de la mémoire flash sur l'ESP8266. Seul l'interface websocket WebREPL est disponible sur L'ESP8266. Vous aurez besoin de télécharger le client WebREPL séparément sur votre ordinateur ou de l'utiliser depuis Internet.

Une fois la page client de WebREPL chargée, vous devriez voir une interface similaire à celle ci-dessous (comme connu en Août 2016, notez que WebREPL reste activement en développement et pourrait changer d'apparence avec le temps!):

 
Crédit: AdaFruit Industries www.adafruit.com

Assurez-vous maintenant que votre ordinateur est bien connecté sur le réseau WiFi de l'ESP8266, cliquez ensuite sur le bouton Connect (en utilisant l'adresse par défaut de l'ESP8266 ws://192.168.4.1:8266/ juste à côté du bouton).

La toute première fois que vous vous connectez sur WebREPL, vous verrez une invite vous demandant de saisir un nouveau mot de passe (New Password) pour protéger l'accès à l'ESP8266:

 
Crédit: AdaFruit Industries www.adafruit.com

Initialisez le nouveau mot de passe et souvenez vous en car vous en aurez besoin pour vos futurs accès à WebREPL.

Si vous oubliez votre mot de passe (ou si vous avez besoin de le modifier Should you ever forget the password or wish to change it you'll need to erase the flash memory and reload MicroPython firmware!

Once the password is set the board will disconnect from the WebREPL and reset itself. Note if you're using daily or development firmware you'll need to connect to the board's serial REPL and enable the WebREPL again after the restart!

After the board restarts click the Connect button again to connect to the board. Now you should be prompted for the password that was set earlier:

 
Crédit: AdaFruit Industries www.adafruit.com

Enter the password and you should be connected to the WebREPL!

 
Crédit: AdaFruit Industries www.adafruit.com

Try entering Python code at the REPL to see the output of it running. The WebREPL should function just like the serial REPL so you can use it to experiment with MicroPython, run code you've loaded on the board, and more:

 
Crédit: AdaFruit Industries www.adafruit.com

That's all there is to accessing the WebREPL from the ESP8266's WiFi network!

Accéder WebREPL depuis d'autres réseaux WiFi

Accessing the WebREPL over the ESP8266's own WiFi access point like above is handy if there's no router or other WiFi network available. However if you do have access to a WiFi network you can instead connect the ESP8266 to this network and access the WebREPL from any other machine on the network. This makes it easier to use the WebREPL without losing access to the internet or your own WiFi network on a laptop that can only be connected to one WiFi network at a time.

To use the WebREPL on another WiFi network you'll first need to connect the ESP8266 to the WiFi network. The MicroPython ESP8266 documentation shows a few simple commands to connect to a network. From the serial REPL (don't use the WebREPL since you'll lose access when the commands change to a different WiFi network!) run the following commands:

import network
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect('ssid', 'password')

 
Crédit: AdaFruit Industries www.adafruit.com

Where ssid is the name of the WiFi access point SSID, and password is the password required to use the access point (try an empty string if no password is required).

After a moment the ESP8266 should connect to the WiFi network. You can run the ifconfig function to check that the board has been assigned an IP address and is on the network:

wlan.ifconfig()

 
Crédit: AdaFruit Industries www.adafruit.com

Notice the first result from the ifconfig call is the IP address assigned to the ESP8266 (192.168.1.207 in this example, but it will differ depending on your WiFi network). If you don't see an IP address then something is wrong with the WiFi configuration or connection to the network. Double check the SSID and password are correct and try the connect call again.

One important thing to note is that the ESP8266 will always remember the last WiFi network it used and attempt to connect automatically on reboot. This is handy since it means when the ESP8266 boots up it will automatically connect to the last network without you having to run the commands above again. The board will only remember the last network though and not an entire history of older networks.

Once the board is connected to the WiFi network enable the WebREPL (as described in the previous section) and notice it prints two IP addresses that it's listening on:

 
Crédit: AdaFruit Industries www.adafruit.com

In this case the WebREPL is listening on 192.168.4.1 which is the ESP8266's access point, and 192.168.1.207 which is the IP address of the ESP8266 on a WiFi network.

Now open the WebREPL and use the IP address of the board on your network instead of the 192.168.4.1 default:

 
Crédit: AdaFruit Industries www.adafruit.com

Once connected you can use the WebREPL just as you were using it on the ESP8266's WiFi network!

Note if you're connecting the board to a WiFi network it is a very smart idea to disable debug output since connecting and disconnecting WiFi network and can spew debug output to the serial REPL. If the board can't connect to the WiFi network, like if you move it to a different location away from the network, you'll see a constant stream of debug output as the board tries and fails to reconnect to the network. This debug output can cause problems with tools like ampy that try to use the board's serial REPL and don't expect the debug output.


Source: MicroPython Basics: ESP8266 WebREPL
Créé par Tony DiCola pour AdaFruit Industries.

Traduit par Meurisse D. pour MCHobby

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.

Traduit avec l'autorisation d'AdaFruit Industries - Translated with the permission from Adafruit Industries - www.adafruit.com