Activity. Streaming Sensor Data
Activity. Streaming Sensor Data
Learning Goals:
Instructions:
Step 1. Open a terminal shell. Open a terminal shell as shown below:
Step 2. Download the resources. Download the resources to any of folders, e.g. the Downloads
folder. Ensure the Python scripts are executable files and have the right privileges so that they can
be used.
Step 3a. View weather station data. Twenty-four hours of weather station data is in the file wx-
data.txt . View this data by running more wx-data.txt.
Each line in the file contains a timestamp in the first column and a set of measurements in the
second column. These columns are separated by a tab. The measurements are also a set of columns
separated by commas.
The timestamp is the number of seconds since January 1, 1970. By looking at the successive
timestamps in the file, we can see that the measurements arrive about every second.
The measurements are prefixed with R0, R1, R2 , etc. Each R-value holds a different set of
measurements. For example, R1 has Dn, Dm, Dx , etc. Additionally, the different types are measured
at different frequencies. R1 is measured every second, but R0 and R2 are much less frequent.
Step 3b. Look at key for measurements. We can learn what the measurement fields mean by
looking at the measurements key file. You can do this in a second terminal shell if you want to keep
both at the same time.
Step 3c. Plot data. Plot the air temperature by running the command:
./plot-data.py wx-data.txt Ta
Notice that this time your python script, instead of saving the plot as a file is opening a plot. That is
thanks to the libraries we installed at the beginning of this activity:
Step 4. View streaming weather station data. Run stream-data.py to see streaming data from
the weather station:
./stream-data.py
Note: Here, we are connecting to Weather Sensors - HPwren - University of California San Diego.
https://hpwren.ucsd.edu/Sensors/. I encourage you to look at the python script to discover a bit
more about how to do this.
The measurements are appearing as they are produced by the weather station. By looking at the
timestamp, we can see that they arrive about every second. Additionally, different measurement
types are produced at different frequencies. For example, R1 is measured every second, but R2 is
less frequent.
Step 5. Create plot of streaming data. We can plot the streaming data by running stream-plot-
data.py:
./stream-plot-data.py Sm
… and continues.
This plot is updated less frequently than the first plot since air temperature measurements are
produced less frequently.