Skip to content

Commit 8faff3b

Browse files
committed
Pushing 2.0.0 for ThingSpeak Communication Library for Particle
1 parent ddb7c4a commit 8faff3b

File tree

2 files changed

+1806
-1588
lines changed

2 files changed

+1806
-1588
lines changed

README.md

Lines changed: 177 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,57 @@ void loop(){
126126
}
127127
```
128128

129+
```
130+
## Read multiple fields from last feed ingested in a Channel
131+
```
132+
#include "ThingSpeak.h"
133+
134+
TCPClient client;
135+
136+
unsigned long weatherStationChannelNumber = 12397;
137+
138+
void setup() {
139+
ThingSpeak.begin(client);
140+
}
141+
142+
void loop(){
143+
144+
// Read latest measurements from the weather station in Natick, MA
145+
// when reading from a private channel, pass the channel ReadApi key
146+
statusCodeRead = ThingSpeak.readMultipleFields(weatherStationChannelNumber);
147+
148+
// Wind Direction (North = 0 degrees)
149+
float windDirection = ThingSpeak.getFieldAsFloat(1);
150+
151+
// Wind Speed (mph)
152+
float windSpeed = ThingSpeak.getFieldAsFloat(2);
153+
154+
// Humidity (%)
155+
float humidity = ThingSpeak.getFieldAsFloat(3);
156+
157+
// Temperature (F)
158+
float temperature = ThingSpeak.getFieldAsFloat(4);
159+
160+
// Rain (Inches/minute)
161+
float rain = ThingSpeak.getFieldAsFloat(5);
162+
163+
// Pressure ("Hg)
164+
float pressure = ThingSpeak.getFieldAsFloat(6);
165+
166+
// Power Level (V)
167+
float powerLevel = ThingSpeak.getFieldAsFloat(7);
168+
169+
// Light Intensity
170+
float pressure = ThingSpeak.getFieldAsFloat(8);
171+
172+
Particle.publish("thingspeak-weather", "Current weather conditions in Natick: ",60,PRIVATE);
173+
Particle.publish("thingspeak-weather", String(temperature) + " degrees F, " + String(humidity) + "% humidity",60,PRIVATE);
174+
175+
delay(60000); // Note that the weather station only updates once a minute
176+
177+
}
178+
```
179+
129180
# <a id="documentation">Documentation</a>
130181
131182
## begin
@@ -437,8 +488,132 @@ Get the status of the previous read.
437488
int getLastReadStatus ()
438489
```
439490
440-
### Returns
441-
See Return Codes below for other possible return values.
491+
## readMultipleFields
492+
Read all the field values, status message, location coordinates, and created-at timestamp associated with the latest feed to a ThingSpeak channel.
493+
The values are stored in a struct, which holds all the 8 fields data, along with status, latitude, longitude, elevation and createdAt associated with the latest field.
494+
To retrieve all the values, invoke these functions in order:
495+
1. readMultipleFields
496+
2. readMultipleFields helper functions
497+
498+
### 1. readMultipleFields
499+
500+
```
501+
int readMultipleFields (channelNumber, readAPIKey)
502+
```
503+
```
504+
int readMultipleFields (channelNumber)
505+
```
506+
507+
| Parameter | Type | Description |
508+
|---------------|:--------------|:-----------------------------------------------------------------------------------------------|
509+
| channelNumber | unsigned long | Channel number |
510+
| readAPIKey | const char * | Read API key associated with the channel. If you share code with others, do not share this key |
511+
512+
#### Returns
513+
HTTP status code of 200 if successful
514+
515+
516+
#### 2. readMultipleFields helper functions
517+
518+
#### a. getFieldAsString
519+
520+
```
521+
String getFieldAsString (field)
522+
```
523+
524+
| Parameter | Type | Description |
525+
|---------------|:--------------|:-----------------------------------------------------------------------------------------------|
526+
| field | unsigned int | Field number (1-8) within the channel to read from.
527+
528+
#### Returns
529+
Value read (UTF8 string), empty string if there is an error, or old value read (UTF8 string) if invoked before readMultipleFields().
530+
531+
532+
#### b. getFieldAsFloat
533+
534+
```
535+
float getFieldAsFloat (field)
536+
```
537+
538+
| Parameter | Type | Description |
539+
|---------------|:--------------|:-----------------------------------------------------------------------------------------------|
540+
| field | unsigned int | Field number (1-8) within the channel to read from.
541+
542+
#### Returns
543+
Value read, 0 if the field is text or there is an error, or old value read if invoked before readMultipleFields().
544+
545+
#### c. getFieldAsLong
546+
547+
```
548+
long getFieldAsLong (field)
549+
```
550+
551+
| Parameter | Type | Description |
552+
|---------------|:--------------|:-----------------------------------------------------------------------------------------------|
553+
| field | unsigned int | Field number (1-8) within the channel to read from.
554+
555+
#### Returns
556+
Value read, 0 if the field is text or there is an error, or old value read if invoked before readMultipleFields().
557+
558+
#### d. getFieldAsInt
559+
560+
```
561+
int getFieldAsInt (field)
562+
```
563+
564+
| Parameter | Type | Description |
565+
|---------------|:--------------|:-----------------------------------------------------------------------------------------------|
566+
| field | unsigned int | Field number (1-8) within the channel to read from.
567+
568+
#### Returns
569+
Value read, 0 if the field is text or there is an error, or old value read if invoked before readMultipleFields().
570+
571+
#### e. getStatus
572+
573+
```
574+
String getStatus ()
575+
```
576+
577+
#### Returns
578+
Value read (UTF8 string). An empty string is returned if there was no status written to the channel or in case of an error.
579+
580+
#### f. getLatitude
581+
582+
```
583+
String getLatitude ()
584+
```
585+
586+
#### Returns
587+
Value read (UTF8 string). An empty string is returned if there was no latitude written to the channel or in case of an error.
588+
589+
#### g. getLongitude
590+
591+
```
592+
String getLongitude ()
593+
```
594+
595+
#### Returns
596+
Value read (UTF8 string). An empty string is returned if there was no longitude written to the channel or in case of an error.
597+
598+
#### h. getElevation
599+
600+
```
601+
String getElevation ()
602+
```
603+
604+
#### Returns
605+
Value read (UTF8 string). An empty string is returned if there was no elevation written to the channel or in case of an error.
606+
607+
#### i. getCreatedAt
608+
609+
```
610+
String getCreatedAt ()
611+
```
612+
613+
#### Returns
614+
Value read (UTF8 string). An empty string is returned if there was no created-at timestamp written to the channel or in case of an error.
615+
616+
442617
443618
## Return Codes
444619
| Value | Meaning |

0 commit comments

Comments
 (0)