create customized thingspeak channel view -凯发k8网页登录
this example shows how to turn the thingspeak channel view into a live data console. the example uses environmental data collected through the things network, but you can adapt the procedure to your own data. thingspeak is a public channel showing the data from a three-sensor probe with sensors for soil moisture, temperature, and gps location. the example details how to build a device that posts sensor data to this channel. you can add a field value display to show a counter, and then add the channel location map. use time-dependent reading to filter sensor data and make it easier to visualize the underlying trends. finally, you can plot a map of the location data in the channel with colors and point areas that represent the channel data.
add numeric display widget
field 1 on this channel is a counter value that demonstrates the device is live and incrementing measurements. showing the latest value of the counter on the channel view provides a quick update on the activity of the sensor. you can add a for your channel using the add widgets button in your private channel view. note that you need data in your channel to see the field value on a numeric display widget.
add channel location map
you can store location information for a channel and for individual updates to the channel data. for this example, first add a channel location map, which is different from the feed data location information. select the channel settings tab on your channel view.
select show channel location and enter the latitude and longitude information for your channel location.
click save channel to update the settings.
now both your private and public channel views include the channel map.
add a two-series plot to channel view
matlab visualizations provide more control of the analysis and plots compared to the default thingspeak plots shown in your channel view. certain license types also allow automatic updates of the visualizations. you can use both time and threshold filtering to improve the data visualization. for this example, visualize the relationship between temperature and soil moisture. start by clicking the matlab visualization button on your channel view.
select a custom code template. enter the code below into the matlab code window. because the data of interest is from a previous experiment, use time filtering to read the older data from the channel. set the start and end times with . then read the data into a timetable using .
starttime = datetime(2019,8,23,09,15,00); endtime= starttime days(2); sensordata = thingspeakread(876466,'location',1,'daterange',[starttime endtime],... 'location',1,'outputformat','timetable');
the temperature data in column three has some bad measurements that must be filtered out before plotting. delete all rows where the temperature reading is larger than 100.
sensordata(sensordata{:,3}>100,:)=[];
now complete the plot. use to make sure the plots are in the same figure and to plot the soil moisture on the right axis. add a on each side for clarity, and set the scale with .
plot (sensordata.timestamps,sensordata.temperaturef)
ylabel('^0f');
hold;
current plot held
yyaxis right plot(sensordata.timestamps,sensordata.soilmoisture); ylabel('soil conductivity'); ylim([700 900]); hold off;
the soil moisture probe measures conductivity in the soil, so wetter, more conductive measurements have lower values on the plot. the plot shows that cooler temperatures are correlated with wetter soil.
visualize measurements with location data on the channel view
for this channel, the prototype sends position data along with the sensor measurements. one application is to survey a large area with temperature and moisture measurements and visualize the data with location.
as in the previous example, add a new matlab visualization using the button on your channel view. read the most recent points with , and plot the location data with . use to select satelite map data.
mapdata = thingspeakread(876466,'readkey','r14rsdimcqhdw1a8','location',... 1,'numpoints',37,'location',1,'outputformat','timetable'); geoscatter(mapdata.latitude,mapdata.longitude,'r'); geobasemap('satellite');
the map provides a good visualization of the positions. include temperature and moisture data in the map to improve the visualization. when the measurement device is moved from one location to another it can make an inaccurate moisture measurement before the probe is replaced in the ground. remove any data with values less than 500 in the soil moisture data in column two. then rescale the data for visibility. add the moisture data to the function to determine the size of the circles, and the temperature data to determine the color. use the ‘filled’
option to fill the circles.
mapdata(mapdata{:,2}<500,:)=[]; mapdata.soilmoisture=mapdata.soilmoisture-min(mapdata.soilmoisture) 1; geoscatter(mapdata.latitude,mapdata.longitude,mapdata.soilmoisture,mapdata.temperaturef,'filled'); geobasemap('satellite');
the subtle effect of warmer locations in front of the building leads to some smaller circles indicating drier soil, except on the right where the sprinklers had just finished.
you can add saved visualizations to the public and private views of your channel. in display settings, use the plus sign next to add/edit this visualization to a channel to expand the channels list.
select the check box that corresponds to the channel you want to add the visualization to. to add private visualizations, select private view. to share the url and add the visualization to the public view, click create a public url. to update your selections, click save display settings.