Skip to content

dareid/sparkcore.thingspeak

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

##About

Spark Core library for sending values to a ThingSpeak channel. This library can be used in the Spark IDE.

Getting Started

1. Include the library

Include the library from the Spark IDE or download it to your local machine. Below is an example of including the library within the Spark IDE:

#include "thingspeak/thingspeak.h"

2. Create thingspeak object

To use the library, an instance of the thingspeak class should be instantiated. The constructor requires a channel API key to be provided. This key can be obtained from the thingspeak website, more details available here.

    ThingSpeakLibrary::ThingSpeak thingspeak ("YOUR-CHANNEL-KEY");

3. Set values

There are two steps in sending values to thingspeak. Initially values must be given to some or all of the 9 fields supported by the thingspeak channel. The example below sets a random integer to field 1:

int rand = random(100);
thingspeak.recordValue(1, String(rand, DEC));

4. Send values

After setting, the values must be sent to thingspeak. The sendValues method constructs a GET query to the thingspeak API using any set values. Once the sendValues method has been called all the values are emptied. The example below sends any set values:

bool valsSent = thingspeak.sendValues();
if(valsSent) {
    Serial.println("Value successfully sent to thingspeak");
} else {
    Serial.println("Sending to thingspeak failed");
}

Note: Values will be emptied after each send, if you want to maintain a value this should be set before each sendValues call.

Configuration

Set connection timeout

After sending values to thingspeak, the library will wait up to a specified timeout for a response. Once a response is received or the timeout is met, the connection is closed. Waiting for a response before closing the connection ensures that the data was successfully sent. The value of the timeout can be set using the setConnectionTimeout method. The default is 1500 ms.

    thingspeak.setConnectionTimeout(1500);

Examples

A full example can be found in firmware/examples which can be run within the Spark IDE.

Contributing

Please feel free to suggest new features or contribute code

About

Spark Core library for sending values to a ThingSpeak channel

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages