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()

{{{2}}}
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écutre, 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-*:

{{{2}}}
Crédit: AdaFruit Industries www.adafruit.com

Where the * is the a set of numbers and letters unique to each ESP8266 board (based on its MAC address).

You will need to enter the password micropythoN to connect to the board's access point (the N is capitalized!). If you have trouble see more details on connecting to the board's WiFi network in the official documentation.

Next you'll need to have available the WebREPL client web page on your machine. You can either access the client webpage from micropython.org (assuming your computer can be connected to both the internet and your MicroPython board's network) or it from its home on GitHub by clicking the button below and extracting the files:

Download-icon.pngTélécharger le client WebREPL

If you download the WebREPL client extract the files and open webrepl.html in your browser (Firefox and Chrome are the officially supported browsers at this time).

Note you can't access the WebREPL client page directly from the ESP8266 board. To save space in flash memory the ESP8266 only provides a websocket interface and not the actual client webpage. You'll need to download the WebREPL client page ahead of time or access it from the internet.

Once the WebREPL client page is loaded you should see something like the following (as of ~August 2016, be aware the WebREPL is under active development and might change how it looks over time!):

{{{2}}}
Crédit: AdaFruit Industries www.adafruit.com

Now make sure your computer is connected to the ESP8266's WiFi network, then click the Connect button (using the default address of ws://192.168.4.1:8266/ next to the button).

The very first time you connect to the WebREPL you should see it prompt to set a password for future access:

{{{2}}}
Crédit: AdaFruit Industries www.adafruit.com

Set a password and remember it as it will be required for future access to the WebREPL. 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:

{{{2}}}
Crédit: AdaFruit Industries www.adafruit.com

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

{{{2}}}
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:

{{{2}}}
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')

{{{2}}}
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()

{{{2}}}
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:

{{{2}}}
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:

{{{2}}}
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