Hardware Reference
In-Depth Information
1. Connect to Galileo's command line using Telnet (see “Connecting via
Telnet” on page 61 ) or serial (see Appendix H ).
2. Change to root's home directory:
# cd /home/root/
3. Launch the text editor vi with the filename json-parse.py to create that
file.
# vi json-parse.py
4. Along the left side of the screen, you'll see a column of tildes ( ~ ). Type
the letter i to enter insert mode. An “I” will appear in the lower lefthand
corner of your screen.
5. Enter the code from Example 6-5 into vi.
6. 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.
7. Type :x and press Enter to save the file and exit vi.
8. Test the script by executing the code from the command line:
# python json-parse.py
If you got everything right, you should see the following output on the com-
mand line:
Volume 38 will be released in 1473.0 hours.
Unlike with Arduino code, Python is a bit particular about how
each line of code is indented. As long as you don't add any
leading spaces or tabs before the lines of code in
Example 6-5 , you'll be fine. In Example 6-11 later in this chapter,
you'll see an example where you'll have to be careful with your
leading white space.
As you can see from Example 6-5 , parsing the JSON response from a website
isn't very difficult when you have Python available to you on Galileo. Now you
simply need to connect the response from Python to your Arduino code.
To try that now, first modify json-parse.py :
1. On Galileo's command line, be sure you're still in root's home directory:
# cd /home/root/
2. Open the file for editing in vi:
 
Search WWH ::




Custom Search