このページの翻訳は最新ではありません。ここをクリックして、英語の最新版を参照してください。
thingSpeakRead
ThingSpeak チャネルに保存されたデータの読み取り
構文
説明
は、ThingSpeak.com 上にある指定された公開チャネルのすべてのフィールドから最新のデータを読み取り、データを数値型として返します。数値以外のデータを読み取るには、'data
= thingSpeakRead(chId
)OutputFormat
' を指定しなければなりません。
は、1 つ以上の data
= thingSpeakRead(chId
,Name,Value
)Name
と Value
のペアの引数によって指定された追加オプションを使用します。
[
は、ThingSpeak.com 上の指定したチャネルからのタイムスタンプも返し、上記構文の任意の入力引数を含めることができます。data
,timestamps
]
= thingSpeakRead(___)
[
はチャネル情報も返します。data
,timestamps
,chInfo
]
= thingSpeakRead(___)
例
チャネルからのデータの取得
公開チャネルの Field 1 と 4 から最後の 5 分間のデータを取得し、データを table に返します。
data = thingSpeakRead(12397,'Fields',[1,4],'NumMinutes',3,'OutputFormat','table')
data = 5×3 table Timestamps WindDirectionNorth0Degrees TemperatureF ____________________ __________________________ ____________ 20-Jun-2017 10:00:32 206 78.9 20-Jun-2017 10:01:34 216 78.9 20-Jun-2017 10:02:35 227 78.8
公開チャネルの Field 1 と 4 から最後の 2 日間のデータを読み取り、データを table に返します。
data = thingSpeakRead(12397,'Fields',[1,4],'NumDays',2,'OutputFormat','table');
プライベート チャネルの全フィールドの最新結果を取得し、データを table に返します。
data = thingSpeakRead(chId,'ReadKey','Your.Read.API.Key','OutputFormat','table')
緯度、経度、高度を、公開チャネルの全フィールドの最後の 10 件のチャネル更新と共に取得します。データを table として返します。
data = thingSpeakRead(chId,'NumPoints',10,'Location',true,'OutputFormat','table')
公開チャネルの Field 1 から 8000 データ点を読み取る際のタイムアウトを設定します。データを table として返します。
data = thingSpeakRead(12397,'Fields',1,'NumPoints',8000,'Timeout',10,'OutputFormat','table');
データをタイムスタンプと共に取得
タイムスタンプを含む、公開チャネルの全フィールドの最新結果を取得します。
[data,timestamps] = thingSpeakRead(12397)
data = 201.0000 3.1000 71.0000 77.5000 0 29.6000 3.9000 51.0000 time = datetime 23-Jun-2017 08:45:28
公開チャネルの Field 1 と 4 から最後の 10 点のデータを取得します。データとタイムスタンプをチャネル情報を含めて table で返します。
[data,chInfo] = thingSpeakRead(12397,'Fields',[1 4],'NumPoints',10,'OutputFormat','table');
公開チャネルの Field 1 と 4 から最後の 10 点のデータを取得します。データを、チャネル情報を含む timetable として返します。
[data,chInfo] = thingSpeakRead(12397,'Fields',[1 4],'NumPoints',10,'OutputFormat','timetable');
プライベートの ThingSpeak サーバー インストール上にある公開チャネルの 3 つのフィールドすべてについて、タイムスタンプを含めた最後の 10 点を取得します。
myURL = serverURL % Enter URL [data,timestamps] = thingSpeakRead(6,'NumPoints',10,'URL',myURL);
データをタイムスタンプおよびチャネル情報と共に取得
公開チャネルの Field 1 と 4 から最後の 5 分間のデータを、タイムスタンプとチャネル情報を含めて取得します。
[data,timestamps,chInfo] = thingSpeakRead(12397,'Fields',[1,4],'NumMinutes',5)
data = 221.0000 92.7000 224.0000 92.7000 226.0000 92.7000 315.0000 92.7000 315.0000 92.8000 timestamps = 5×1 datetime array 28-Jul-2017 16:46:33 28-Jul-2017 16:47:33 28-Jul-2017 16:48:35 28-Jul-2017 16:49:36 28-Jul-2017 16:50:36 chInfo = 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: 28-Jul-2017 16:50:36 LastEntryID: 1459866 FieldDescriptions: {1×8 cell} FieldIDs: [1 2 3 4 5 6 7 8] URL: 'https://api.thingspeak.com/channels/12397/feed.json?'
公開チャネルの 2014 年 8 月 8 日から 2014 年 8 月 12 日までの Field 1 と 4 のデータを、タイムスタンプとチャネル情報を含めて取得します。
[data,timestamps,channelInfo] = thingSpeakRead(12397,'Fields',[1 4],'DateRange',[datetime('Aug 8, 2014'),datetime('Aug 12, 2014')]);