Modifications

Sauter à la navigation Sauter à la recherche
8 427 octets ajoutés ,  9 novembre 2016 à 21:16
aucun résumé de modification
Ligne 2 : Ligne 2 :     
{{traduction}}
 
{{traduction}}
 +
== Activer WebREPL ==
 +
The first step to using the WebREPL is to make sure it is available and enabled on your ESP8266 board.  The easiest way to enable the WebREPL is to load a release build of MicroPython ESP8266 firmware on your board as the release builds come with the WebREPL enabled by default.  The release builds are those [http://micropython.org/download/#esp8266 available from the official download page] and with a simple version number like '''1.8.3''', not a daily build like '''1.8.3-52-gb0e2106'''. 
 +
 +
Check out this [[FEATHER-CHARGER-FICHIER-MICROPYTHON|handy guide on loading MicroPython firmware]] if you aren't sure how to load firmware.
 +
 +
If you're using a daily or development build you can manually enable the WebREPL as [http://docs.micropython.org/en/latest/esp8266/esp8266/quickref.html#webrepl-web-browser-interactive-prompt mentioned in the documentation].  Connect to the board's serial REPL and run the follow commands:
 +
 +
<syntaxhighlight lang="python">
 +
import webrepl
 +
webrepl.start()
 +
</syntaxhighlight>
 +
 +
{{ADFImage|FEATHER-WEBREPL-ACCESS-10.png}}
 +
 +
You should see the WebREPL started and the IP address to access it printed to the terminal.  Note you can't access this IP address directly in your browser, instead you'll need to use a client webpage as described below.
 +
 +
== Accéder à WebREPL ==
 +
Once the WebREPL is running you can connect to it over the ESP8266's WiFi radio.  If the board isn't connected already to a wireless access point then it will create one which you can connect to from your computer.
 +
 +
To connect to the board's WiFi network look for a WiFi network advertised as '''MicroPython-*''':
 +
 +
{{ADFImage|FEATHER-WEBREPL-ACCESS-11.png}}
 +
 +
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 [http://docs.micropython.org/en/latest/esp8266/esp8266/tutorial/intro.html#wifi 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 [http://micropython.org/webrepl/ client webpage from micropython.org] (assuming your computer can be connected to both the internet and your MicroPython board's network) or [https://github.com/micropython/webrepldownload it from its home on GitHub] by clicking the button below and extracting the files:
 +
 +
{{download-box|Télécharger le client WebREPL|https://github.com/micropython/webrepl/archive/master.zip}}
 +
 +
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!):
 +
 +
{{ADFImage|FEATHER-WEBREPL-ACCESS-12.png}}
 +
 +
'''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:
 +
 +
{{ADFImage|FEATHER-WEBREPL-ACCESS-13.png}}
 +
 +
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:
 +
 +
{{ADFImage|FEATHER-WEBREPL-ACCESS-14.png}}
 +
 +
Enter the password and you should be connected to the WebREPL!
 +
 +
{{ADFImage|FEATHER-WEBREPL-ACCESS-15.png}}
 +
 +
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:
 +
 +
{{ADFImage|FEATHER-WEBREPL-ACCESS-16.png}}
 +
 +
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 [https://docs.micropython.org/en/latest/esp8266/esp8266/quickref.html#networking 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:
 +
 +
<syntaxhighlight lang="python">
 +
import network
 +
wlan = network.WLAN(network.STA_IF)
 +
wlan.active(True)
 +
wlan.connect('ssid', 'password')
 +
</syntaxhighlight>
 +
 +
{{ADFImage|FEATHER-WEBREPL-ACCESS-20.png}}
 +
 +
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:
 +
 +
<syntaxhighlight lang="python">
 +
wlan.ifconfig()
 +
</syntaxhighlight>
 +
 +
{{ADFImage|FEATHER-WEBREPL-ACCESS-21.png}}
 +
 +
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:
 +
 +
{{ADFImage|FEATHER-WEBREPL-ACCESS-22.png}}
 +
 +
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:
 +
 +
{{ADFImage|FEATHER-WEBREPL-ACCESS-23.png}}
 +
 +
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 [[FEATHER-CHARGER-FICHIER-MICROPYTHON-DEBUG|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.
    
{{FEATHER-WEBREPL-TRAILER}}
 
{{FEATHER-WEBREPL-TRAILER}}
29 917

modifications

Menu de navigation