thingSpeakRead
读取ThingSpeak通道中存储的数据
语法
说明
读取ThingSpeak.com上指定公共通道所有字段的最新数据,并以数值类型返回。data
= thingSpeakRead(channelID
)
使用由一个或多个 data
= thingSpeakRead(channelID
,Name=Value
)Name=Value
对参数指定的附加选项。要读取非数值数据,必须指定 'OutputFormat'
。
[
还返回 ThingSpeak.com 上指定通道的时间戳,并且可以包含先前语法中的任何输入参数。data
,timestamps
] = thingSpeakRead(___)
[
还返回通道信息。data
,timestamps
,channelInfo
] = thingSpeakRead(___)
示例
将通道中的三点数据检索到时间表中
从公共通道的字段1和字段4中读取最后三点数据,并将数据返回到时间表中。
data = thingSpeakRead(12397,'Fields',[1,4],NumPoints=3,OutputFormat='TimeTable')
data = 3×2 timetable Timestamps WindDirectionNorth0Degrees TemperatureF ____________________ __________________________ ____________ 18-Nov-2021 13:42:57 34 70.4 18-Nov-2021 13:43:57 50 70.4 18-Nov-2021 13:44:57 54 70.6
将通道中五分钟的数据检索到时间表中
读取公共通道的字段1和字段4的最后五分钟的数据,并将数据返回到表中。
data = thingSpeakRead(12397,Fields=[1,4],NumMinutes=5,OutputFormat='TimeTable')
data = 11×2 timetable Timestamps WindDirectionNorth0Degrees TemperatureF ____________________ __________________________ ____________ 18-Nov-2021 13:34:57 38 70.6 18-Nov-2021 13:35:57 42 70.6 18-Nov-2021 13:36:57 41 70.6 18-Nov-2021 13:37:57 46 70.8 18-Nov-2021 13:38:57 44 70.8 18-Nov-2021 13:39:57 37 70.8 18-Nov-2021 13:40:57 42 70.6 18-Nov-2021 13:41:57 43 70.4 18-Nov-2021 13:42:57 34 70.4 18-Nov-2021 13:43:57 50 70.4 18-Nov-2021 13:44:57 54 70.6 18-Nov-2021 13:45:57 52 70.
检索最近的数据及其时间戳
读取公共通道所有字段的最新结果,包括时间戳。
[data,timestamps] = thingSpeakRead(12397)
data = 52.0000 7.6000 58.0000 70.8000 0 29.6700 4.1360 0 timestamps = datetime 18-Nov-2021 13:45:57
检索带有时间戳和通道信息的五分钟数据
读取公共通道的字段1和字段4的最后五分钟的数据,包括时间戳和通道信息。
[data,timestamps,channelInfo] = thingSpeakRead(12397,Fields=[1,4],NumMinutes=5)
data = 41.0000 70.6000 46.0000 70.8000 44.0000 70.8000 37.0000 70.8000 42.0000 70.6000 43.0000 70.4000 34.0000 70.4000 50.0000 70.4000 54.0000 70.6000 52.0000 70.8000 39.0000 71.0000 timestamps = 11×1 datetime array 18-Nov-2021 13:36:57 18-Nov-2021 13:37:57 18-Nov-2021 13:38:57 18-Nov-2021 13:39:57 18-Nov-2021 13:40:57 18-Nov-2021 13:41:57 18-Nov-2021 13:42:57 18-Nov-2021 13:43:57 18-Nov-2021 13:44:57 18-Nov-2021 13:45:57 18-Nov-2021 13:46:57 channelInfo = struct with fields: ChannelID: 12397 Name: 'WeatherStation' Description: 'MathWorks Weather Station, West Garage, Natick, MA 01760, USA' Latitude: 42.2997 Longitude: -71.3505 Altitude: 60 Created: 20-May-2014 17:50:32 Updated: 18-Nov-2021 13:40:31 LastEntryID: 3638608 FieldDescriptions: {1×8 cell} FieldIDs: [1 2 3 4 5 6 7 8] URL: 'https://api.thingspeak.com/channels/12397/feed.json?'
检索特定日期范围内的数据
读取2018年8月9日11:59:01到2018年8月10日12:02:52的公共通道1和4字段的数据,包括时间戳和通道信息。
[data,timestamps,channelInfo] = thingSpeakRead(12397,Fields=[1 4],...
DateRange=[datetime(2018,8,9,23,59,01),datetime(2018,8,10,0,02,52)])
data = 202.0000 83.3000 184.0000 83.2000 185.0000 83.1000 155.0000 83.1000 timestamps = 4×1 datetime array 09-Aug-2018 23:59:17 10-Aug-2018 00:00:20 10-Aug-2018 00:01:21 10-Aug-2018 00:02:22 channelInfo = struct with fields: ChannelID: 12397 Name: 'WeatherStation' Description: 'MathWorks Weather Station, West Garage, Natick, MA 01760, USA' Latitude: 42.2997 Longitude: -71.3505 Altitude: 60 Created: 20-May-2014 17:50:32 Updated: 14-May-2020 10:31:40 LastEntryID: 2853000 FieldDescriptions: {'Wind Direction (North = 0 degrees)' 'Wind Speed (mph)' '% Humidity' 'Temperature (F)' 'Rain (Inches/minute)' 'Pressure ("Hg)' 'Power Level (V)' 'Light Intensity'} FieldIDs: [1 2 3 4 5 6 7 8] URL: 'https://api.thingspeak.com/channels/12397/feed.json?'
输入参数
channelID
— 通道识别号
数值
通道标识号,指定为正整数。对于私有通道,您还必须指定 ReadKey
参数。
数据类型: double
名称-值参数
将可选参数对指定为 Name1=Value1,...,NameN=ValueN
,其中 Name
是参数名称,Value
是相应的值。名称-值参数必须出现在其他参数之后,但参数对的顺序并不重要。
在 R2021a 之前,使用逗号分隔每个名称和值,并将 Name
括在引号中。
示例: thingSpeakRead(12397,Location=true);
thingSpeakRead(12397,'Location',true);
DateRange
— 收集数据的时间范围
日期时间向量
收集的数据返回的时间范围,指定为名称-值对,其中包含 'DateRange'
以及 [startdate,enddate]
中 $ 的值数组$ datetime
(MATLAB) 值。ThingSpeak 服务器限制返回的点数最多为 8000。如果您需要超过 8000 个数据点,请调整您的范围或进行多次调用。
注意
您不能将 DateRange
与 NumDays
或 NumMinutes
一起使用。
示例: thingSpeakRead(12397,DateRange=[datetime('Aug 8, 2014'),datetime('Aug 12, 2014')]);
Fields
— 通道字段
正数值标量
通道字段 ID,指定为名称-值对,其中包含 Fields
和要从中检索数据的通道字段 ID 的数值。
示例: thingSpeakRead(12397,Fields=[1,3,4]);
Location
— 数据的位置信息
逻辑值
显示通道数据位置信息的指示器,指定为由 Location
和逻辑值组成的名称-值对。位置信息包括纬度、经度和海拔。
示例: thingSpeakRead(12397,Location=true);
NumDays
— 数据天数
正数值标量
要从中提取数据的数据天数,指定为由 'NumDays'
和数值组成的名称/值对。天数以 24 小时为单位计算。ThingSpeak 服务器将返回的点数限制为最大 8000。如果您需要超过 8000 点数据,请调整您的天数或拨打多个电话。
注意
您不能将 NumDays
与 DateRange
或 NumMinutes
一起使用。
示例: thingSpeakRead(12397,NumDays=2);
NumMinutes
— 数据分钟数
正数值标量
要从中提取数据的数据分钟数,指定为由 'NumMinutes'
和数值组成的名称/值对。要检索的数据的分钟数是从发出命令的时间开始计算的。ThingSpeak 服务器将返回的点数限制为最大 8000。如果您需要超过 8000 个数据点,请调整分钟数或拨打多个电话。
注意
您不能将 NumMinutes
与 DateRange
或 NumDays
一起使用。
示例: thingSpeakRead(12397,NumMinutes=20);
数据类型: double
NumPoints
— 数据点数量
正数值标量
要提取的数据点的数量,指定为由 'NumPoints'
和数值组成的名称/值对。数据点或行数从发出命令时开始计算。ThingSpeak 服务器将返回的点数限制为最大 8000。
示例: thingSpeakRead(12397,NumPoints=200);
OutputFormat
— 输出数据的类别
矩阵 (默认) | 表 | 时间表
输出数据的类,指定为由 'OutputFormat'
和文本值组成的逗号分隔对。有效值为 'matrix'
、'table'
和 'timetable'
。对于数值数据,请使用 'matrix'
格式。对于任何非数值数据,您可以使用 'timetable'
或 'table'
。'table'
格式输出 [data,channelInfo]
,其中 data
包含时间戳和通道字段中的数据。'timetable'
格式输出 [data,channelInfo]
,其中 data
是一个时间表,包含与请求的 数量一样多的变量$$。
示例: thingSpeakRead(12397,OutputFormat='table');
示例: thingSpeakRead(12397,OutputFormat='timetable');
ReadKey
— 读取通道的API密钥
API密钥的特征向量 | API 密钥的字符串标量
读取通道的 API 密钥,指定为名称-值对,其中包含 'ReadKey'
和表示通道读取 API 密钥的字符向量。读取 API 密钥允许您从专用通道读取数据。您可以在 ThingSpeak通道视图的 API 密钥选项卡上找到通道的读取 API 密钥。如果您从公共通道读取数据,则不需要读取 API 密钥。为了方便起见,将您的通道读取 API 密钥保存在变量中。
示例: thingSpeakRead(12397,ReadKey='F6CSCVKX42WFZN9Y');
数据类型: char
Timeout
— 服务器连接超时时间
10 (默认) | 正数值标量
服务器连接超时时间,指定为由 'Timeout'
和数值组成的名称-值对。该值是允许 thingSpeakRead
连接到服务器的秒数。
示例: thingSpeakRead(12397,Timeout=15);
输出参数
data
— 来自通道的数据
数组 (默认) | 表 | 时间表
来自通道的数据,以数组、表或时间表的形式返回。
timestamps
— 每个数据元素的时间戳
数组 (默认)
每个数据元素的时间戳,以 datetime
值的数组形式返回。
数据类型: datetime
channelInfo
— 通道信息
结构体
通道信息,以结构形式返回,其中字段按表中所示的顺序排列。
字段 | 描述 |
---|---|
ChannelID | 通道识别号 |
Name | 通道名称 |
Description | 通道说明 |
Latitude | 通道设置中提供的通道纬度 |
Longitude | 通道设置中提供的通道经度 |
Altitude | 通道设置中提供的通道标高 |
Created | 通道创建日期的日期时间 |
Updated | 上次更改通道设置的日期时间 |
Last EntryID | 最近通道更新的条目 ID |
Field Descriptions | 字段名称列表 |
Field IDs | 启用字段列表 |
URL | 源数据的 URL |
详细信息
ThingSpeak
ThingSpeak 是一项 IoT 分析平台服务,可让您在云中聚合、可视化和分析实时数据流。有关详细信息,请参阅 License Options 和 Commercial Use。
版本历史记录
在 R2019a 中推出
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)