ThingSpeak

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

thingSpeakRead

Read data stored in ThingSpeak channel

Syntax

  • data = thingSpeakRead(chId)
    example
  • data = thingSpeakRead(chId,Name,Value)
    example
  • [data,timestamps] = thingSpeakRead(___)
    example
  • [data,timestamps,chInfo] = thingSpeakRead(___)
    example

Description

example

data = thingSpeakRead(chId) reads the most recent data from all fields of the specified public channel on ThingSpeak.com and returns the data.

example

data = thingSpeakRead(chId,Name,Value) uses additional options specified by one or more Name,Value pair arguments.

example

[data,timestamps] = thingSpeakRead(___) reads the most recent data containing timestamps from all fields of the specified public channel on ThingSpeak.com and can include any of the input arguments in previous syntaxes.

example

[data,timestamps,chInfo] = thingSpeakRead(___) reads the most recent data containing timestamps from all fields of the specified public channel along with channel information on ThingSpeak.com and can include any of the input arguments in previous syntaxes.

Examples

Retrieve Data from a Channel

Retrieve the last five minutes of data from fields 1 and 4 of a public channel. Return only the data.

data = thingSpeakRead(12397,'Fields',[1,4],'NumMinutes',5,'OutputFormat','table');

Read the last two days of data from fields 1 and 4 of a public channel. Return only the data.

data = thingSpeakRead(12397,'Fields',[1,4],'NumDays',2,'OutputFormat','table');

Retrieve the most recent result for all fields of a private channel.

data = thingSpeakRead(chId,'ReadKey','Your.Read.API.Key','OutputFormat','table')

Retrieve latitude, longitude and altitude data along with the last 10 channel updates for all fields in a public channel and return the data as a table.

data = thingSpeakRead(chId,'NumPoints',10,'Location',true,'OutputFormat','table')

Set the timeout for reading 8000 data points from field 1 of a public channel.

data = thingSpeakRead(12397,'Fields',1,'NumPoints',8000,'Timeout',10,'OutputFormat','table')

Retrieve Data Along With Timestamp

Retrieve the most recent result for all fields of a public channel including the timestamp.

   [data,time] = thingSpeakRead(12397)

Retrieve the last 10 points of data from fields 1 and 4 of a public channel. Return the data and timestamps in a table, including channel information.

[data,chInfo] = thingSpeakRead(12397,'Fields',[1 4],'NumPoints',10,'OutputFormat','table');

Retrieve the last 10 points of data from fields 1 and 4 of a public channel. Return the data as a timetable, including channel information.

[data,chInfo] = thingSpeakRead(12397,'Fields',[1 4],'NumPoints',10,'OutputFormat','timetable');

Retrieve the last 10 points for all three fields of a public channel on a private ThingSpeak™ server installation.

myURL = serverURL % Enter URL
[data,time] = thingSpeakRead(6,'NumPoints',10,'URL',myURL);

Retrieve Data Along with Timestamp and Channel Information

Retrieve the last five minutes of data from fields 1 and 4 of a public channel, including the timestamp, and channel information.

[data,time,channelInfo] = thingSpeakRead(12397,'Fields',[1,4],'NumMinutes',5);

Retrieve the data for August 8, 2014 through August 12, 2014 for fields 1 and 4 of a public channel, including the timestamp, and channel information.

[data,time,channelInfo] = thingSpeakRead(12397,'Fields',[1 4],'DateRange',[datetime('Aug 8, 2014'),datetime('Aug 12, 2014')]);

Related Examples

Input Arguments

collapse all

The channel identification number specified as a positive integer.

Data Types: double

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: thingSpeakRead(12397,'url','https://api.thingspeak.com');

collapse all

Range of data to be returned, specified as a comma-separated pair consisting of 'DateRange' and the value must have [startdate,enddate], in MATLAB® datetime values. ThingSpeak server limits the number of points returned to a maximum of 8000. Adjust your ranges or make multiple calls if you need more than 8000 points of data.

    Note:   You cannot use DateRange with NumDays or NumMinutes.

Example: thingSpeakRead(12397,'DateRange',[datetime('Aug 8, 2014'),datetime('Aug 12, 2014')]);

Data Types: datetime

Channel field IDs specified as a comma-separated pair consisting of 'Fields' and numeric value. Specify the channel ID from which you need to retrieve data.

Example: thingSpeakRead(12397,'Fields',[1,3,4]);

Data Types: double

Positional information of data from the channel, specified as a comma-separated pair consisting of 'Location' and a logical value. Location information includes latitude, longitude, and altitude.

Example: thingSpeakRead(12397,'Location',true);

Data Types: logical

Number of days of data, specified as a comma-separated pair consisting of 'NumDays' and a numeric value, to extract data from. Number of days is measured in 24-hour periods. ThingSpeak server limits the number of points returned to a maximum of 8000. Adjust your number of days or make multiple calls if you need more than 8000 points of data.

    Note:   You cannot use NumDays with DateRange or NumMinutes.

Example: thingSpeakRead(12397,'NumDays',2);

Data Types: double

Number of minutes of data, specified as a comma-separated pair consisting of 'NumMinutes' and a value, to extract data from. Number of minutes of data to retrieve is measured from the current time, (time the command is issued). ThingSpeak server limits the number of points returned to a maximum of 8000. Adjust your number minutes or make multiple calls if you need more than 8000 points of data.

    Note:   You cannot use NumMinutes with DateRange or NumDays.

Example: thingSpeakRead(12397,'NumMinutes',20);

Data Types: double

Number of data points, specified as a comma-separated pair consisting of 'NumPoints' numeric value, to extract data from. The number of points or rows of data is counted from the current time (time the command is issued). ThingSpeak server limits the number of points returned to a maximum of 8000.

Example: thingSpeakRead(12397,'NumPoints',200);

Data Types: double

Class of the output data, specified as a comma-separated pair consisting of 'OutputFormat' and a string value. Valid values are 'matrix', 'table', and 'timetable'. Use 'matrix' format for numeric data. You can use 'timetable' or 'table' for any nonnumeric data. The 'table' format outputs [data,channelInfo] where data contains the timestamps and the data from the fields of the channel. The 'timetable' format outputs [data,channelInfo] where data will be a timetable and contains as many variables as the number of requested 'fields'.

Example: thingSpeakRead(12397,'OutputFormat','table');

Example: thingSpeakRead(12397,'OutputFormat','timetable');

Data Types: table

Read API key of the channel, specified as a comma-separated pair consisting of 'ReadKey' and a string value representing the channel read API key. The Read API key allows you to read data from a private channel. You do not need a Read API key if you are reading data from a public channel. Save your Read API key in a variable for convenience.

Example: thingSpeakRead(12397,'ReadKey','F6CSCVKX42WFZN9Y');

Example: thingSpeakRead(12397,'ReadKey',string('F6CSCVKX42WFZN9Y'));

Data Types: string | char

Server connection timeout period, specified as a comma-seperated pair consisting of 'Timeout' and a numeric value. The value must be the number of seconds for thingSpeakRead to connect to the server.

Example: thingSpeakRead(12397,'Timeout',15);

Data Types: double

URL of a private ThingSpeak server, specified as a comma-seperated pair consisting of 'URL' and a string value. The value must be a valid URL address.

Example: thingSpeakRead(12397,'URL','http://private.server.url');

Example: thingSpeakRead(12397,'URL',string('http://private.server.url'));

Data Types: string | char

Output Arguments

collapse all

Data from the channel, returned as an array, table, or a timetable.

Data Types: table

Timestamp of each data element, returned as an array of datetime.

Data Types: datetime

Channel information returned as a structure.

        ChannelID: 12397
             Name: 'WeatherStation'
      Description: 'MathWorks Weather Station, West Garage, Natick, MA 01760, USA'
         Latitude: 42.2997
        Longitude: -71.3505
         Altitude: 60
          Created: [1x1 datetime]
          Updated: [1x1 datetime]
        LastEntry: 188212
FieldDescriptions: {1x8 cell}
         FieldIDs: [1 2 3 4 5 6 7 8]
              URL: 'https://api.thingspeak.com/channels/12397/feed.json?'

Data Types: struct

See Also

Functions

Was this topic helpful?