Hardware Reference
In-Depth Information
Create a flag to indicate when there's a blank line in the request from
the client.
If data from the client's request is available, execute the code that
follows.
Read in the request from the client.
Echo the request to the serial monitor.
When we receive two blank lines in a row, the client is ready to receive
data.
Start sending the HTTP headers.
Start sending HTML.
If the button is pressed, send a piece of HTML that indicates that this
is the case.
If the button is not pressed, send the alternate piece of HTML.
Serving a Web Page with Python
Even without Arduino code, you can have Python read from and write to Gal-
ileo's pins. You can therefore use Python alone to do the same thing that
Example 6-10 does. These instructions show you how.
1. Just as you did in Figure 4-2 , wire up a button to pin 2 of the Galileo.
2. Connect to Galileo's command line using Telnet (see “Connecting via
Telnet” on page 61 ) or serial (see Appendix H ).
3. Change to root's home directory:
# cd /home/root/
4. Launch the text editor vi with the filename server.py to create that file.
# vi server.py
5. Along the left side of the screen, you'll see a column of tildes ( ~ ). Type
the letter i to enter insert mode.
6. Enter the code from Example 6-11 into vi.
7. Hit the escape key to switch from insert mode to command mode. The
“I” in the lower-left corner will disappear and you'll see a dash instead.
8. Type :x and press Enter to save the file and exit vi.
9. From the command line, execute the script:
# python server.py
Search WWH ::




Custom Search