Fetching data from thingspeak | ThingSpeak Projects | Forum

Avatar

Please consider registering
Guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —






— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed sp_TopicIcon
Fetching data from thingspeak
No permission to create posts
March 20, 2019
4:52 am
Avatar
dsmsantha
New Member
Members
Forum Posts: 1
Member Since:
March 8, 2019
sp_UserOfflineSmall Offline

I am trying to fetch data from thingspeak using nodejs. This is my code

CODE:
https=require('https');
https.get('https://api.thingspeak.com/channels/XXXXXX/fields/1/last.json?key=XXXXXXXXXXXXXXX', function(res) {
console.log("Got response: " + res.statusCode);
}).on('error', function(e) {
console.log("Got error: " + e.message);
context.done(null, 'FAILURE');
});

The output that i get is
ClientRequest {
_events:
[Object: null prototype] {
response: { [Function: bound onceWrapper] listener: [Function] },
socket:
{ [Function: bound onceWrapper] listener: [Function: onSocket] },
error: [Function] },
_eventsCount: 3,
_maxListeners: undefined,
output:
[ 'GET /channels/XXXXX/fields/1/last.json?key=XXXXXXXXXXXX HTTP/1.1
Host: api.thingspeak.com
Connection: close

' ],
outputEncodings: [ 'latin1' ],
outputCallbacks: [ [Function: bound onFinish] ],
outputSize: 118,
writable: true,
_last: true,
chunkedEncoding: false,
shouldKeepAlive: false,
useChunkedEncodingByDefault: false,
sendDate: false,
_removedConnection: false,
_removedContLen: false,
_removedTE: false,
_contentLength: 0,
_hasBody: true,
_trailer: '',
finished: true,
_headerSent: true,
socket: null,
connection: null,
_header:
'GET /channels/XXXXXX/fields/1/last.json?key=XXXXXXXXXXXX HTTP/1.1
Host: api.thingspeak.com
Connection: close

',
_onPendingData: [Function: noopPendingOutput],
agent:
Agent {
_events: [Object: null prototype] { free: [Function] },
_eventsCount: 1,
_maxListeners: undefined,
defaultPort: 443,
protocol: 'https:',
options: { path: null },
requests: {},
sockets: { 'api.thingspeak.com:443::::::::::::::::': [Array] },
freeSockets: {},
keepAliveMsecs: 1000,
keepAlive: false,
maxSockets: Infinity,
maxFreeSockets: 256,
maxCachedSessions: 100,
_sessionCache: { map: {}, list: [] } },
socketPath: undefined,
timeout: undefined,
method: 'GET',
path: '/channels/XXXXX/fields/1/last.json?key=XXXXXXXXXXX',
_ended: false,
res: null,
aborted: undefined,
timeoutCb: null,
upgradeOrConnect: false,
parser: null,
maxHeadersCount: null,
[Symbol(isCorked)]: false,
[Symbol(outHeadersKey)]:
[Object: null prototype] { host: [ 'Host', 'api.thingspeak.com' ] } }
Got response: 200

I don't get the field value.I believe what I am getting is the http header. How can i get the actual data.
The output that i am expecting is

{"created_at":"2019-03-08T14:12:31Z","entry_id":21,"field1":"0"}

How is it possible to rectify this error?

When I use the url in the browser to fetch data, i receive the apt response. The output doesn't come when fetched through the code.

March 22, 2019
9:47 am
Avatar
cstapels
Moderator
Members


Moderators
Forum Posts: 861
Member Since:
March 7, 2017
sp_UserOfflineSmall Offline

There is a node.js client here
https://www.npmjs.com/package/thingspeakclient

Its not terribly recent, but perhaps it could help.

Forum Timezone: America/New_York

Most Users Ever Online: 166

Currently Online:
10 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 272

Vinod: 240

piajola: 95

turgo: 70

vespapierre: 63

Adarsh_Murthy: 62

Member Stats:

Guest Posters: 1

Members: 8665

Moderators: 1

Admins: 2

Forum Stats:

Groups: 3

Forums: 14

Topics: 1600

Posts: 5760

Newest Members:

khanhNguyen_CT, susyburr, quijano__, meosuckhoe, briskpanda, Dejw0089

Moderators: cstapels: 460

Administrators: Hans: 405, lee: 457