57 #if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM) 61 #error Only Arduino MKR1000, Yun, Uno/Mega/Due with either WiFi101 or Ethernet shield. ESP8266 also supported. 65 #define THINGSPEAK_URL "api.thingspeak.com" 66 #define THINGSPEAK_IPADDRESS IPAddress(184,106,153,149) 67 #define THINGSPEAK_PORT_NUMBER 80 69 #ifdef ARDUINO_ARCH_AVR 70 #ifdef ARDUINO_AVR_YUN 71 #define TS_USER_AGENT "tslib-arduino/1.3 (arduino yun)" 73 #define TS_USER_AGENT "tslib-arduino/1.3 (arduino uno or mega)" 75 #elif defined(ARDUINO_ARCH_ESP8266) 76 #define TS_USER_AGENT "tslib-arduino/1.3 (ESP8266)" 77 #elif defined(ARDUINO_SAMD_MKR1000) 78 #define TS_USER_AGENT "tslib-arduino/1.3 (arduino mkr1000)" 79 #elif defined(ARDUINO_SAM_DUE) 80 #define TS_USER_AGENT "tslib-arduino/1.3 (arduino due)" 81 #elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM) 82 #define TS_USER_AGENT "tslib-arduino/1.3 (arduino unknown sam or samd)" 84 #error "Platform not supported" 87 #define FIELDNUM_MIN 1 88 #define FIELDNUM_MAX 8 89 #define FIELDLENGTH_MAX 255 // Max length for a field in ThingSpeak is 255 bytes (UTF-8) 91 #define TIMEOUT_MS_SERVERRESPONSE 5000 // Wait up to five seconds for server to respond 93 #define OK_SUCCESS 200 // OK / Success 94 #define ERR_BADAPIKEY 400 // Incorrect API key (or invalid ThingSpeak server address) 95 #define ERR_BADURL 404 // Incorrect API key (or invalid ThingSpeak server address) 96 #define ERR_OUT_OF_RANGE -101 // Value is out of range or string is too long (> 255 bytes) 97 #define ERR_INVALID_FIELD_NUM -201 // Invalid field number specified 98 #define ERR_SETFIELD_NOT_CALLED -210 // setField() was not called before writeFields() 99 #define ERR_CONNECT_FAILED -301 // Failed to connect to ThingSpeak 100 #define ERR_UNEXPECTED_FAIL -302 // Unexpected failure during write to ThingSpeak 101 #define ERR_BAD_RESPONSE -303 // Unable to parse response 102 #define ERR_TIMEOUT -304 // Timeout waiting for server to respond 103 #define ERR_NOT_INSERTED -401 // Point was not inserted (most probable cause is the rate limit of once every 15 seconds) 114 this->lastReadStatus = OK_SUCCESS;
138 bool begin(Client & client,
const char * customHostName,
unsigned int port)
140 #ifdef PRINT_DEBUG_MESSAGES 141 Serial.print(
"ts::tsBegin (client: Client URL: "); Serial.print(customHostName); Serial.println(
")");
143 this->setClient(&client);
144 this->setServer(customHostName, port);
146 this->lastReadStatus = OK_SUCCESS;
171 bool begin(Client & client, IPAddress customIP,
unsigned int port)
173 #ifdef PRINT_DEBUG_MESSAGES 174 Serial.print(
"ts::tsBegin (client: Client IP: "); Serial.print(customIP); Serial.println(
")");
176 this->setClient(&client);
177 this->setServer(customIP, port);
179 this->lastReadStatus = OK_SUCCESS;
204 #ifdef PRINT_DEBUG_MESSAGES 205 Serial.print(
"ts::tsBegin");
207 this->setClient(&client);
210 this->lastReadStatus = OK_SUCCESS;
230 int writeField(
unsigned long channelNumber,
unsigned int field,
int value,
const char * writeAPIKey)
232 char valueString[10];
233 itoa(value, valueString, 10);
234 return writeField(channelNumber, field, valueString, writeAPIKey);
253 int writeField(
unsigned long channelNumber,
unsigned int field,
long value,
const char * writeAPIKey)
255 char valueString[15];
256 ltoa(value, valueString, 10);
257 return writeField(channelNumber, field, valueString, writeAPIKey);
277 int writeField(
unsigned long channelNumber,
unsigned int field,
float value,
const char * writeAPIKey)
279 #ifdef PRINT_DEBUG_MESSAGES 280 Serial.print(
"ts::writeField (channelNumber: "); Serial.print(channelNumber); Serial.print(
" writeAPIKey: "); Serial.print(writeAPIKey); Serial.print(
" field: "); Serial.print(field); Serial.print(
" value: "); Serial.print(value,5); Serial.println(
")");
282 char valueString[20];
283 int status = convertFloatToChar(value, valueString);
284 if(status != OK_SUCCESS)
return status;
286 return writeField(channelNumber, field, valueString, writeAPIKey);
310 int writeField(
unsigned long channelNumber,
unsigned int field,
const char * value,
const char * writeAPIKey)
312 return writeField(channelNumber, field, String(value), writeAPIKey);
339 int writeField(
unsigned long channelNumber,
unsigned int field, String value,
const char * writeAPIKey)
342 if(field < FIELDNUM_MIN || field > FIELDNUM_MAX)
return ERR_INVALID_FIELD_NUM;
344 if(value.length() > FIELDLENGTH_MAX)
return ERR_OUT_OF_RANGE;
346 #ifdef PRINT_DEBUG_MESSAGES 347 Serial.print(
"ts::writeField (channelNumber: "); Serial.print(channelNumber); Serial.print(
" writeAPIKey: "); Serial.print(writeAPIKey); Serial.print(
" field: "); Serial.print(field); Serial.print(
" value: \""); Serial.print(value); Serial.println(
"\")");
349 String postMessage = String(
"field") + String(field) +
"=" + value;
350 return writeRaw(channelNumber, postMessage, writeAPIKey);
388 char valueString[10];
389 itoa(value, valueString, 10);
391 return setField(field, valueString);
428 char valueString[15];
429 ltoa(value, valueString, 10);
430 return setField(field, valueString);
467 char valueString[20];
468 int status = convertFloatToChar(value, valueString);
469 if(status != OK_SUCCESS)
return status;
471 return setField(field, valueString);
505 int setField(
unsigned int field,
const char * value)
507 return setField(field, String(value));
543 #ifdef PRINT_DEBUG_MESSAGES 544 Serial.print(
"ts::setField (field: "); Serial.print(field); Serial.print(
" value: \""); Serial.print(value); Serial.println(
"\")");
546 if(field < FIELDNUM_MIN || field > FIELDNUM_MAX)
return ERR_INVALID_FIELD_NUM;
548 if(value.length() > FIELDLENGTH_MAX)
return ERR_OUT_OF_RANGE;
549 this->nextWriteField[field - 1] = value;
589 #ifdef PRINT_DEBUG_MESSAGES 590 Serial.print(
"ts::setLatitude(latitude: "); Serial.print(latitude,3); Serial.println(
"\")");
592 this->nextWriteLatitude = latitude;
632 #ifdef PRINT_DEBUG_MESSAGES 633 Serial.print(
"ts::setLongitude(longitude: "); Serial.print(longitude,3); Serial.println(
"\")");
635 this->nextWriteLongitude = longitude;
675 #ifdef PRINT_DEBUG_MESSAGES 676 Serial.print(
"ts::setElevation(elevation: "); Serial.print(elevation,3); Serial.println(
"\")");
678 this->nextWriteElevation = elevation;
754 #ifdef PRINT_DEBUG_MESSAGES 755 Serial.print(
"ts::setStatus(status: "); Serial.print(status); Serial.println(
"\")");
758 if(status.length() > FIELDLENGTH_MAX)
return ERR_OUT_OF_RANGE;
759 this->nextWriteStatus = status;
907 #ifdef PRINT_DEBUG_MESSAGES 908 Serial.print(
"ts::setTwitterTweet(twitter: "); Serial.print(twitter); Serial.print(
", tweet: "); Serial.print(tweet); Serial.println(
"\")");
911 if((twitter.length() > FIELDLENGTH_MAX) || (tweet.length() > FIELDLENGTH_MAX))
return ERR_OUT_OF_RANGE;
913 this->nextWriteTwitter = twitter;
914 this->nextWriteTweet = tweet;
990 #ifdef PRINT_DEBUG_MESSAGES 991 Serial.print(
"ts::setCreatedAt(createdAt: "); Serial.print(createdAt); Serial.println(
"\")");
997 if(createdAt.length() > FIELDLENGTH_MAX)
return ERR_OUT_OF_RANGE;
998 this->nextWriteCreatedAt = createdAt;
1038 int writeFields(
unsigned long channelNumber,
const char * writeAPIKey)
1040 String postMessage = String(
"");
1041 bool fFirstItem =
true;
1042 for(
size_t iField = 0; iField < 8; iField++)
1044 if(this->nextWriteField[iField].length() > 0)
1048 postMessage = postMessage + String(
"&");
1050 postMessage = postMessage + String(
"field") + String(iField + 1) + String(
"=") + this->nextWriteField[iField];
1052 this->nextWriteField[iField] =
"";
1056 if(!isnan(nextWriteLatitude))
1060 postMessage = postMessage + String(
"&");
1062 postMessage = postMessage + String(
"lat=") + String(this->nextWriteLatitude);
1064 this->nextWriteLatitude = NAN;
1067 if(!isnan(this->nextWriteLongitude))
1071 postMessage = postMessage + String(
"&");
1073 postMessage = postMessage + String(
"long=") + String(this->nextWriteLongitude);
1075 this->nextWriteLongitude = NAN;
1079 if(!isnan(this->nextWriteElevation))
1083 postMessage = postMessage + String(
"&");
1085 postMessage = postMessage + String(
"elevation=") + String(this->nextWriteElevation);
1087 this->nextWriteElevation = NAN;
1090 if(this->nextWriteStatus.length() > 0)
1094 postMessage = postMessage + String(
"&");
1096 postMessage = postMessage + String(
"status=") + String(this->nextWriteStatus);
1098 this->nextWriteStatus =
"";
1101 if(this->nextWriteTwitter.length() > 0)
1105 postMessage = postMessage + String(
"&");
1107 postMessage = postMessage + String(
"twitter=") + String(this->nextWriteTwitter);
1109 this->nextWriteTwitter =
"";
1112 if(this->nextWriteTweet.length() > 0)
1116 postMessage = postMessage + String(
"&");
1118 postMessage = postMessage + String(
"tweet=") + String(this->nextWriteTweet);
1120 this->nextWriteTweet =
"";
1123 if(this->nextWriteCreatedAt.length() > 0)
1127 postMessage = postMessage + String(
"&");
1129 postMessage = postMessage + String(
"created_at=") + String(this->nextWriteCreatedAt);
1131 this->nextWriteCreatedAt =
"";
1138 return ERR_SETFIELD_NOT_CALLED;
1141 return writeRaw(channelNumber, postMessage, writeAPIKey);
1165 int writeRaw(
unsigned long channelNumber,
const char * postMessage,
const char * writeAPIKey)
1167 return writeRaw(channelNumber, String(postMessage), writeAPIKey);
1186 int writeRaw(
unsigned long channelNumber, String postMessage,
const char * writeAPIKey)
1188 #ifdef PRINT_DEBUG_MESSAGES 1189 Serial.print(
"ts::writeRaw (channelNumber: "); Serial.print(channelNumber); Serial.print(
" writeAPIKey: "); Serial.print(writeAPIKey); Serial.print(
" postMessage: \""); Serial.print(postMessage); Serial.println(
"\")");
1192 if(!connectThingSpeak())
1195 return ERR_CONNECT_FAILED;
1198 postMessage = postMessage + String(
"&headers=false");
1200 #ifdef PRINT_DEBUG_MESSAGES 1201 Serial.print(
" POST \"");Serial.print(postMessage);Serial.println(
"\"");
1204 postMessage = postMessage + String(
"\n");
1207 if(!this->client->print(
"POST /update HTTP/1.1\r\n"))
return abortWriteRaw();
1208 if(!writeHTTPHeader(writeAPIKey))
return abortWriteRaw();
1209 if(!this->client->print(
"Content-Type: application/x-www-form-urlencoded\r\n"))
return abortWriteRaw();
1210 if(!this->client->print(
"Content-Length: "))
return abortWriteRaw();
1211 if(!this->client->print(postMessage.length()))
return abortWriteRaw();
1212 if(!this->client->print(
"\r\n\r\n"))
return abortWriteRaw();
1213 if(!this->client->print(postMessage))
return abortWriteRaw();
1215 String entryIDText = String();
1216 int status = getHTTPResponse(entryIDText);
1217 if(status != OK_SUCCESS)
1222 long entryID = entryIDText.toInt();
1224 #ifdef PRINT_DEBUG_MESSAGES 1225 Serial.print(
" Entry ID \"");Serial.print(entryIDText);Serial.print(
"\" (");Serial.print(entryID);Serial.println(
")");
1230 #ifdef PRINT_DEBUG_MESSAGES 1231 Serial.println(
"disconnected.");
1236 status = ERR_NOT_INSERTED;
1256 String
readStringField(
unsigned long channelNumber,
unsigned int field,
const char * readAPIKey)
1258 if(field < FIELDNUM_MIN || field > FIELDNUM_MAX)
1260 this->lastReadStatus = ERR_INVALID_FIELD_NUM;
1263 #ifdef PRINT_DEBUG_MESSAGES 1264 Serial.print(
"ts::readStringField(channelNumber: "); Serial.print(channelNumber);
1265 if(NULL != readAPIKey)
1267 Serial.print(
" readAPIKey: "); Serial.print(readAPIKey);
1269 Serial.print(
" field: "); Serial.print(field); Serial.println(
")");
1271 return readRaw(channelNumber, String(String(
"/fields/") + String(field) + String(
"/last")), readAPIKey);
1311 float readFloatField(
unsigned long channelNumber,
unsigned int field,
const char * readAPIKey)
1313 return convertStringToFloat(
readStringField(channelNumber, field, readAPIKey));
1353 long readLongField(
unsigned long channelNumber,
unsigned int field,
const char * readAPIKey)
1396 int readIntField(
unsigned long channelNumber,
unsigned int field,
const char * readAPIKey)
1436 String
readStatus(
unsigned long channelNumber,
const char * readAPIKey)
1438 String content =
readRaw(channelNumber,
"/feeds/last.txt?status=true", readAPIKey);
1444 return getJSONValueByKey(content,
"status");
1481 String content =
readRaw(channelNumber,
"/feeds/last.txt", readAPIKey);
1487 return getJSONValueByKey(content,
"created_at");
1523 String
readRaw(
unsigned long channelNumber, String URLSuffix)
1525 return readRaw(channelNumber, URLSuffix, NULL);
1544 String
readRaw(
unsigned long channelNumber, String URLSuffix,
const char * readAPIKey)
1546 #ifdef PRINT_DEBUG_MESSAGES 1547 Serial.print(
"ts::readRaw (channelNumber: "); Serial.print(channelNumber);
1548 if(NULL != readAPIKey)
1550 Serial.print(
" readAPIKey: "); Serial.print(readAPIKey);
1552 Serial.print(
" URLSuffix: \""); Serial.print(URLSuffix); Serial.println(
"\")");
1555 if(!connectThingSpeak())
1557 this->lastReadStatus = ERR_CONNECT_FAILED;
1561 String URL = String(
"/channels/") + String(channelNumber) + URLSuffix;
1563 #ifdef PRINT_DEBUG_MESSAGES 1564 Serial.print(
" GET \"");Serial.print(URL);Serial.println(
"\"");
1568 if(!this->client->print(
"GET "))
return abortReadRaw();
1569 if(!this->client->print(URL))
return abortReadRaw();
1570 if(!this->client->print(
" HTTP/1.1\r\n"))
return abortReadRaw();
1571 if(!writeHTTPHeader(readAPIKey))
return abortReadRaw();
1572 if(!this->client->print(
"\r\n"))
return abortReadRaw();
1574 String content = String();
1575 int status = getHTTPResponse(content);
1577 this->lastReadStatus = status;
1580 #ifdef PRINT_DEBUG_MESSAGES 1581 if(status == OK_SUCCESS)
1583 Serial.print(
"Read: \""); Serial.print(content); Serial.println(
"\"");
1588 #ifdef PRINT_DEBUG_MESSAGES 1589 Serial.println(
"disconnected.");
1592 if(status != OK_SUCCESS)
1599 return String(
"") + content;
1637 return this->lastReadStatus;
1641 String getJSONValueByKey(String textToSearch, String key)
1643 if(textToSearch.length() == 0){
1647 String searchPhrase = String(
"\"") + key + String(
"\":\"");
1649 int fromPosition = textToSearch.indexOf(searchPhrase,0);
1651 if(fromPosition == -1){
1656 fromPosition = fromPosition + searchPhrase.length();
1658 int toPosition = textToSearch.indexOf(
"\"", fromPosition);
1661 if(toPosition == -1){
1666 textToSearch.remove(toPosition);
1668 return textToSearch.substring(fromPosition);
1673 this->client->stop();
1674 return ERR_UNEXPECTED_FAIL;
1677 String abortReadRaw()
1679 this->client->stop();
1680 #ifdef PRINT_DEBUG_MESSAGES 1681 Serial.println(
"ReadRaw abort - disconnected.");
1683 this->lastReadStatus = ERR_UNEXPECTED_FAIL;
1687 void setServer(
const char * customHostName,
unsigned int port)
1689 #ifdef PRINT_DEBUG_MESSAGES 1690 Serial.print(
"ts::setServer (URL: \""); Serial.print(customHostName); Serial.println(
"\")");
1692 this->customIP = INADDR_NONE;
1693 this->customHostName = customHostName;
1697 void setServer(IPAddress customIP,
unsigned int port)
1699 #ifdef PRINT_DEBUG_MESSAGES 1700 Serial.print(
"ts::setServer (IP: \""); Serial.print(customIP); Serial.println(
"\")");
1702 this->customIP = customIP;
1703 this->customHostName = NULL;
1709 #ifdef PRINT_DEBUG_MESSAGES 1710 Serial.print(
"ts::setServer (default)");
1712 this->customIP = INADDR_NONE;
1713 this->customHostName = NULL;
1714 this->port = THINGSPEAK_PORT_NUMBER;
1717 void setClient(Client * client) {this->client = client;};
1719 Client * client = NULL;
1720 const char * customHostName = NULL;
1721 IPAddress customIP = INADDR_NONE;
1722 unsigned int port = THINGSPEAK_PORT_NUMBER;
1723 String nextWriteField[8];
1724 float nextWriteLatitude;
1725 float nextWriteLongitude;
1726 float nextWriteElevation;
1728 String nextWriteStatus;
1729 String nextWriteTwitter;
1730 String nextWriteTweet;
1731 String nextWriteCreatedAt;
1733 bool connectThingSpeak()
1735 bool connectSuccess =
false;
1736 if(this->customIP == INADDR_NONE && NULL == this->customHostName)
1738 #ifdef PRINT_DEBUG_MESSAGES 1739 Serial.print(
" Connect to default ThingSpeak URL...");
1741 connectSuccess = client->connect(THINGSPEAK_URL,THINGSPEAK_PORT_NUMBER);
1744 #ifdef PRINT_DEBUG_MESSAGES 1745 Serial.print(
"Failed. Try default IP...");
1747 connectSuccess = client->connect(THINGSPEAK_IPADDRESS,THINGSPEAK_PORT_NUMBER);
1752 if(!(this->customIP == INADDR_NONE))
1755 #ifdef PRINT_DEBUG_MESSAGES 1756 Serial.print(
" Connect to ");Serial.print(this->customIP);Serial.print(
"...");
1758 connectSuccess = client->connect(this->customIP,this->port);
1760 if(NULL != this->customHostName)
1763 #ifdef PRINT_DEBUG_MESSAGES 1764 Serial.print(
" Connect to ");Serial.print(this->customHostName);Serial.print(
" ...");
1766 connectSuccess = client->connect(customHostName,this->port);
1770 #ifdef PRINT_DEBUG_MESSAGES 1773 Serial.println(
"Success.");
1777 Serial.println(
"Failed.");
1780 return connectSuccess;
1783 bool writeHTTPHeader(
const char * APIKey)
1785 if(NULL != this->customHostName)
1787 if (!this->client->print(
"Host: "))
return false;
1788 if (!this->client->print(this->customHostName))
return false;
1789 if (!this->client->print(
"\r\n"))
return false;
1793 if (!this->client->print(
"Host: api.thingspeak.com\r\n"))
return false;
1795 if (!this->client->print(
"Connection: close\r\n"))
return false;
1796 if (!this->client->print(
"User-Agent: "))
return false;
1797 if (!this->client->print(TS_USER_AGENT))
return false;
1798 if (!this->client->print(
"\r\n"))
return false;
1801 if (!this->client->print(
"X-THINGSPEAKAPIKEY: "))
return false;
1802 if (!this->client->print(APIKey))
return false;
1803 if (!this->client->print(
"\r\n"))
return false;
1808 int getHTTPResponse(String & response)
1810 long startWaitForResponseAt = millis();
1811 while(client->available() == 0 && millis() - startWaitForResponseAt < TIMEOUT_MS_SERVERRESPONSE)
1815 if(client->available() == 0)
1820 if(!client->find(const_cast<char *>(
"HTTP/1.1")))
1823 Serial.println(
"ERROR: Didn't find HTTP/1.1");
1825 return ERR_BAD_RESPONSE;
1827 int status = client->parseInt();
1829 Serial.print(
"Got Status of ");Serial.println(status);
1831 if(status != OK_SUCCESS)
1836 if(!client->find(const_cast<char *>(
"\r\n")))
1839 Serial.println(
"ERROR: Didn't find end of status line");
1841 return ERR_BAD_RESPONSE;
1844 Serial.println(
"Found end of status line");
1847 if(!client->find(const_cast<char *>(
"\n\r\n")))
1850 Serial.println(
"ERROR: Didn't find end of header");
1852 return ERR_BAD_RESPONSE;
1855 Serial.println(
"Found end of header");
1858 String tempString = client->readString();
1859 response = tempString;
1861 Serial.print(
"Response: \"");Serial.print(response);Serial.println(
"\"");
1866 int convertFloatToChar(
float value,
char *valueString)
1869 if(0 == isinf(value) && (value > 999999000000 || value < -999999000000))
1872 return ERR_OUT_OF_RANGE;
1876 #if defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM) 1877 sprintf(valueString,
"%.5f", value);
1879 dtostrf(value,1,5, valueString);
1884 float convertStringToFloat(String value)
1887 float result = value.toFloat();
1889 if(1 == isinf(result) && *value.c_str() ==
'-')
1891 result = (float)-INFINITY;
1896 void resetWriteFields()
1898 for(
size_t iField = 0; iField < 8; iField++)
1900 this->nextWriteField[iField] =
"";
1902 this->nextWriteLatitude = NAN;
1903 this->nextWriteLongitude = NAN;
1904 this->nextWriteElevation = NAN;
1905 this->nextWriteStatus =
"";
1906 this->nextWriteTwitter =
"";
1907 this->nextWriteTweet =
"";
1908 this->nextWriteCreatedAt =
"";
1914 #endif //ThingSpeak_h int writeRaw(unsigned long channelNumber, const char *postMessage, const char *writeAPIKey)
Write a raw POST to a ThingSpeak channel.
Definition: ThingSpeak.h:1165
int setTwitterTweet(const char *twitter, const char *tweet)
Set the Twitter account and message to use for an update to be tweeted. To send a message to twitter ...
Definition: ThingSpeak.h:795
String readStringField(unsigned long channelNumber, unsigned int field, const char *readAPIKey)
Read the latest string from a private ThingSpeak channel.
Definition: ThingSpeak.h:1256
String readStringField(unsigned long channelNumber, unsigned int field)
Read the latest string from a public ThingSpeak channel.
Definition: ThingSpeak.h:1289
int setField(unsigned int field, long value)
Set the value of a single field that will be part of a multi-field update. To write multiple fields a...
Definition: ThingSpeak.h:426
String readCreatedAt(unsigned long channelNumber)
Read the created-at timestamp associated with the latest update to a private ThingSpeak channel...
Definition: ThingSpeak.h:1503
int writeRaw(unsigned long channelNumber, String postMessage, const char *writeAPIKey)
Write a raw POST to a ThingSpeak channel.
Definition: ThingSpeak.h:1186
bool begin(Client &client, IPAddress customIP, unsigned int port)
Initializes the ThingSpeak library and network settings using a custom installation of ThingSpeak...
Definition: ThingSpeak.h:171
int writeFields(unsigned long channelNumber, const char *writeAPIKey)
Write a multi-field update. Call setField() for each of the fields you want to write, setLatitude() / setLongitude() / setElevation(), and then call writeFields()
Definition: ThingSpeak.h:1038
int setField(unsigned int field, int value)
Set the value of a single field that will be part of a multi-field update. To write multiple fields a...
Definition: ThingSpeak.h:385
int setTwitterTweet(const char *twitter, String tweet)
Set the Twitter account and message to use for an update to be tweeted. To send a message to twitter ...
Definition: ThingSpeak.h:869
int setTwitterTweet(String twitter, const char *tweet)
Set the Twitter account and message to use for an update to be tweeted. To send a message to twitter ...
Definition: ThingSpeak.h:832
int setLatitude(float latitude)
Set the latitude of a multi-field update. To record latitude, longitude and elevation of a write...
Definition: ThingSpeak.h:587
String readCreatedAt(unsigned long channelNumber, const char *readAPIKey)
Read the created-at timestamp associated with the latest update to a private ThingSpeak channel...
Definition: ThingSpeak.h:1479
int setStatus(String status)
Set the status of a multi-field update. To record a status message on a write, call setStatus() then ...
Definition: ThingSpeak.h:752
bool begin(Client &client, const char *customHostName, unsigned int port)
Initializes the ThingSpeak library and network settings using a custom installation of ThingSpeak...
Definition: ThingSpeak.h:138
int getLastReadStatus()
Get the status of the previous read.
Definition: ThingSpeak.h:1635
int writeField(unsigned long channelNumber, unsigned int field, int value, const char *writeAPIKey)
Write an integer value to a single field in a ThingSpeak channel.
Definition: ThingSpeak.h:230
Enables an Arduino, ESP8266 or other compatible hardware to write or read data to or from ThingSpeak...
Definition: ThingSpeak.h:108
long readLongField(unsigned long channelNumber, unsigned int field, const char *readAPIKey)
Read the latest long from a private ThingSpeak channel.
Definition: ThingSpeak.h:1353
int writeField(unsigned long channelNumber, unsigned int field, String value, const char *writeAPIKey)
Write a String to a single field in a ThingSpeak channel.
Definition: ThingSpeak.h:339
int setStatus(const char *status)
Set the status of a multi-field update. To record a status message on a write, call setStatus() then ...
Definition: ThingSpeak.h:715
int setField(unsigned int field, const char *value)
Set the value of a single field that will be part of a multi-field update. To write multiple fields a...
Definition: ThingSpeak.h:505
String readRaw(unsigned long channelNumber, String URLSuffix)
Read a raw response from a public ThingSpeak channel.
Definition: ThingSpeak.h:1523
long readLongField(unsigned long channelNumber, unsigned int field)
Read the latest long from a public ThingSpeak channel.
Definition: ThingSpeak.h:1374
int writeField(unsigned long channelNumber, unsigned int field, float value, const char *writeAPIKey)
Write a floating point value to a single field in a ThingSpeak channel.
Definition: ThingSpeak.h:277
int setCreatedAt(const char *createdAt)
Set the created-at date of a multi-field update. To record created-at of a write, call setField() for...
Definition: ThingSpeak.h:951
int readIntField(unsigned long channelNumber, unsigned int field, const char *readAPIKey)
Read the latest int from a private ThingSpeak channel.
Definition: ThingSpeak.h:1396
int setField(unsigned int field, String value)
Set the value of a single field that will be part of a multi-field update. To write multiple fields a...
Definition: ThingSpeak.h:541
int setCreatedAt(String createdAt)
Set the created-at date of a multi-field update. To record created-at of a write, call setField() for...
Definition: ThingSpeak.h:988
int setLongitude(float longitude)
Set the longitude of a multi-field update. To record latitude, longitude and elevation of a write...
Definition: ThingSpeak.h:630
float readFloatField(unsigned long channelNumber, unsigned int field, const char *readAPIKey)
Read the latest float from a private ThingSpeak channel.
Definition: ThingSpeak.h:1311
int setTwitterTweet(String twitter, String tweet)
Set the Twitter account and message to use for an update to be tweeted. To send a message to twitter ...
Definition: ThingSpeak.h:906
String readStatus(unsigned long channelNumber, const char *readAPIKey)
Read the latest status from a private ThingSpeak channel.
Definition: ThingSpeak.h:1436
bool begin(Client &client)
Initializes the ThingSpeak library and network settings using the ThingSpeak.com service.
Definition: ThingSpeak.h:202
float readFloatField(unsigned long channelNumber, unsigned int field)
Read the latest float from a public ThingSpeak channel.
Definition: ThingSpeak.h:1332
int writeField(unsigned long channelNumber, unsigned int field, const char *value, const char *writeAPIKey)
Write a string to a single field in a ThingSpeak channel.
Definition: ThingSpeak.h:310
int readIntField(unsigned long channelNumber, unsigned int field)
Read the latest int from a public ThingSpeak channel.
Definition: ThingSpeak.h:1417
int setField(unsigned int field, float value)
Set the value of a single field that will be part of a multi-field update. To write multiple fields a...
Definition: ThingSpeak.h:465
String readRaw(unsigned long channelNumber, String URLSuffix, const char *readAPIKey)
Read a raw response from a private ThingSpeak channel.
Definition: ThingSpeak.h:1544
String readStatus(unsigned long channelNumber)
Read the latest status from a public ThingSpeak channel.
Definition: ThingSpeak.h:1460
int setElevation(float elevation)
Set the elevation of a multi-field update. To record latitude, longitude and elevation of a write...
Definition: ThingSpeak.h:673
int writeField(unsigned long channelNumber, unsigned int field, long value, const char *writeAPIKey)
Write a long value to a single field in a ThingSpeak channel.
Definition: ThingSpeak.h:253