I remote logged into Raspberry Pi and installed the following Python packages:
jdcal
astral
geopy
Module jdcal contains functions that allow conversions between Julian dates and calendar dates.
Astral is a python package for calculating the times of various aspects of the sun and phases of the moon.
Geopy is a Python 2 and 3 client for several popular geocoding web services.
Ran multiple modules on Raspberry Pi using python3:
$ python3 julian.py
$ python3 date_example.py
$ python3 datetime_example.py
$ python3 time_example.py
$ python3 sun.py 'New York'
$ python3 moon.py
$ python3 coordinates.py 'SC Williams Library'
$ python3 address.py '40.7448397, -74.02531776875'
$ python3 system_info.py
Some of the programs were ran by typing 'python3 <moduleName>'. However other modules required system arguments to work correctly. Sys.argv (imported from sys) is a list in Python which contains the command-line arguments passed to the script.
For examplle, when I typed python3 sun.py 'New York' , sys.argv[0] = sun.py & sys.argv[1] = 'New York'.
In the next part of the lab, I ran a socket client and server on the SAME Raspberry Pi by using two terminals.
$ python3 socket_server.py
$ python3 socket_client.py '155.246.x.x'
socket_client.py takes the Raspberry Pi's IP address as sys.argv[1] and uses it to connect to the server.
I used VNC Viewer on my Mac to open two terminals on the Raspberry Pi. I couldn't figure out how to open another terminal within an SSH connection. The results are shown below:
Shown below is the architecture of a simple socket client/server connection.
It's worth noting that displaying IP addresses poses a security risk if posted online. To go around this, I hard coded my Raspberry Pi's IP address in socket_client.py. I also changed the variable 'addr' in socket_server.py so that an arbitrary number displayed.
PyPy is an alternative implementation of the Python programming language, CPython is the standard implementation. PyPy often runs faster than CPython because PyPy is a just-in-time compiler while CPython is an interpreter.
In the first example I used the time linux command to see how long it takes the system to run preprocessed C code. I will also be checking the time it takes to run python modules using pypy, python, and python. The results are shown below.
Real (wall clock time) - is the time from start to finish of the call.
User - amount of CPU time spent in user mode.
System or sys - amount of CPU time spent in kernel mode
Instead of using the time linux command, Python includes a profiler called cProfile. It not only gives the total running time, but also times each function separately, and tells you how many times each function was called, making it easy to determine where you should make optimizations.
To profile a Python module, type the following commands:
$ python -m cProfile <pythonFileName>
Results of this operation with different Python interpreters are shown below.
For part F I will be downloading Doxygen and the python package html2text.
Doxygen is the de facto regular tool for generating documentation from annotated C++ sources, however, it additionally supports different well known programming languages akin to C, objective-C, C#, Hypertext Preprocessor, Java, Python, IDL (Corba, Microsoft, and UNO/OpenOffice flavors), Fortran, VHDL and Tcl.
html2txt converts a page of HTML into clean, easy-to-read plain ASCII text.
The following command was executed:
$ sudo apt install doxygen html2text
I then created a new subdirectoy /demo and copied pyexample.py file from lesson 3 into /demo.
I entered commands:
$ doxygen -g doxygen.config
$ nano doxygen.config
$ doxygen doxygen.config
This created a doxygen configuration file and created documentation for all files within my /demo subdirectory. Two sub directories were created in the process:
~/iot/lesson3/demo/html
~/iot/lesson3/demo/latex
Next I converted the 'annotation.html' to an easy to read ASCII file by using the html2text python. The following command was entered:
$ html2text annotation.html
I didn't like how the file was output on the terminal so I created a python script that takes in system arguments and writes the output of each html file into a text file.
*Insert code here*
*Insert screenshot here*
*Upload to GitHub*