This video will
demonstrate how to explore ThingSpeak data using a
custom built MATLAB app and then go into more
detail on how the app was built using app designer. ThingSpeak speak is an IoT
analytics platform service that allows you to aggregate,
visualize, and analyze live data streams in the cloud. You can send data to
ThingSpeak from your devices, create instant visualizations
of live data, and send alerts. ThingSpeak channel
views provide a snapshot of your streaming data. This traffic monitor channel
is observing live traffic data for [? eastern ?]
[? westbound ?] traffic on the main road outside
the MathWorks headquarters. You can use MATLAB to
create custom visualizations to your data, such as this
week over week comparison or the 48-hour summary. However, exploratory
data analysis can be somewhat tedious
without graphic controls to quickly modify your
data visualizations. The IoT data explorer
for ThingSpeak provides an easy to
use graphical interface to explore data read
in from ThingSpeak. The app and its code
are publicly available on file exchange and at
the ThingSpeak GitHub site. We will use it to
look at the effect the recent quarantine
on pollution and traffic levels around the
MathWorks headquarters. After it is installed,
this MATLAB app can be opened from the
MATLAB app gallery. We'll look at some features
specific to this app and afterwards
demonstrate how you can make a similar app on your own. This channel shows measurements
from an air quality monitor made by PurpleAir
that is installed in one of the parking garages
at MathWorks headquarters. As more people have
started working from home, fewer people are driving to
work and using the garage. So perhaps we
should expect to see an improvement in air quality. First. As sort of a control
let's compare air quality from two dates
during quarantine. We'll look at April
28th and compare it with one week before. Fill in the channel ID
and set the date here, then specify the
width in time which goes forward from midnight
on the indicated date. To compare it with
one week prior, we set this field to one week. Even though both dates occurred
during the quarantine, , we see a significant
difference in air quality, blue for the indicated date,
orange for the week before. Perhaps temperature
changes throughout the day affect the sensor readings. Field six of our channel
contains this data so we can check it Literally. A cursory glance for
the two visualizations suggests there
could be an effect, but it's not immediately clear. Now let's compare data
from the current date to pre-quarantine times. We'll compare this data with
data from seven weeks prior when there was no quarantine. As we might expect,
the air quality is worse as indicated
by the higher numbers. However, the temperature
was also much higher. Let's see if the trend
continues over several days. Since we can get up to 8,000
data points with each read, we can visualize nearly three
consecutive days worth of data. We see similar air quality
levels at these times despite quarantine versus
non-quarantine and note that both data ranges
do not contain weekends. Since we also see
temperature become similar around those times. This seems to indicate that
temperature might affect air quality more than the number
of cars utilized in the garage. Note that if the raw data
across your time range is very cluttered, this
app lets you quickly apply the MATLAB retime
function to see things like hourly averages instead. Hopefully, you've seen how
interactive graphical tools make it much easier to perform
exploratory data analysis. Let's talk about how you
can make your own IoT data explorer in MATLAB. As mentioned before, the app
you're seeing in this video is available from file exchange
and the ThingSpeak's GitHub site, and you're highly
encouraged to download it and leverage it
as a starting point. MATLAB app designer enables
you to create your own apps from scratch or edit
an existing one. Simply type app designer
in the MATLAB command line. For context, the
ThingSpeak explorer app is a two panel app
with auto-reflow. Let's find the app and
open in new app designer. While you can certainly make an
app that automatically updates visualizations every time one
of these inputs are changed. This app keeps things simple
by allowing you to set up parameters at your own pace
then use the update button when you're ready. Here on the left, you can
see some of the controls used to provide input a date
picker, dropdowns, and switches to select the time. Simply drag and drop
controls under the interface and click on them
to edit and rename. Right-click on any element
to create a callback. These callbacks
activate whenever the element is triggered
in some relevant manner. One great use for callbacks
is input validation. Communicating to
the user on things like if a field
requires an integer or if a date needs to be set in
the past relative to another. Let's take a look at
the callback function. There are three main
parts of this function. First, we get all the
inputs from the UI and perform input validation. Next, we use that input to
gather data from ThingSpeak. First from the selected date,
then from the data in the past. And finally, we plot
the data visualizations. Let's look at the
key functionality, reading data from ThingSpeak. You can navigate to
the function definition by right-clicking
on the function name and clicking open. While it looks like there's a
lot of code here, most of it is just to make the app a little
more robust because reading data from ThingSpeak speak
is entirely contained in this one line of code. ThingSpeak read needs to know
a few pieces of information, particularly the
channel ID, then you can specify additional
data using name value pairs such as date range
with a start and end date, selected fields as
indicated by which checkboxes were checked, an API key
if the channel was private and the output format
for the results. Note that timetables
are a great output format as they make it easy
to plot and return data. This next section helps
our app run more smoothly by ensuring we actually receive
data from ThingSpeak read, and it notifies the user
if something goes wrong. The final section
performs re-timing if that option was selected. That concludes the
process of getting data for the present and past
dates, and the update callback function will proceed
to the next step. I hope you've been
able to see how easy it is to get data from ThingSpeak
and to use the MATLAB app designer to build and
modify custom apps so that you and your colleagues
can analyze and visualize data in an interactive manner. Use the links below to find
the entry on GitHub where you can download the app,
try it out for yourself, and also leave
comments and feedback.