58 #if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM) || defined(ARDUINO_ARCH_ESP32) 62 #error Only Arduino MKR1000, Yun, Uno/Mega/Due with either WiFi101 or Ethernet shield. ESP8266 and ESP32 are also supported. 66 #define THINGSPEAK_URL "api.thingspeak.com" 67 #define THINGSPEAK_IPADDRESS IPAddress(184,106,153,149) 68 #define THINGSPEAK_PORT_NUMBER 80 70 #ifdef ARDUINO_ARCH_AVR 71 #ifdef ARDUINO_AVR_YUN 72 #define TS_USER_AGENT "tslib-arduino/1.3 (arduino yun)" 74 #define TS_USER_AGENT "tslib-arduino/1.3 (arduino uno or mega)" 76 #elif defined(ARDUINO_ARCH_ESP8266) 77 #define TS_USER_AGENT "tslib-arduino/1.3 (ESP8266)" 78 #elif defined(ARDUINO_SAMD_MKR1000) 79 #define TS_USER_AGENT "tslib-arduino/1.3 (arduino mkr1000)" 80 #elif defined(ARDUINO_SAM_DUE) 81 #define TS_USER_AGENT "tslib-arduino/1.3 (arduino due)" 82 #elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM) 83 #define TS_USER_AGENT "tslib-arduino/1.3 (arduino unknown sam or samd)" 84 #elif defined(ARDUINO_ARCH_ESP32) 85 #define TS_USER_AGENT "tslib-arduino/1.3 (ESP32)" 87 #error "Platform not supported" 90 #define FIELDNUM_MIN 1 91 #define FIELDNUM_MAX 8 92 #define FIELDLENGTH_MAX 255 // Max length for a field in ThingSpeak is 255 bytes (UTF-8) 94 #define TIMEOUT_MS_SERVERRESPONSE 5000 // Wait up to five seconds for server to respond 96 #define OK_SUCCESS 200 // OK / Success 97 #define ERR_BADAPIKEY 400 // Incorrect API key (or invalid ThingSpeak server address) 98 #define ERR_BADURL 404 // Incorrect API key (or invalid ThingSpeak server address) 99 #define ERR_OUT_OF_RANGE -101 // Value is out of range or string is too long (> 255 bytes) 100 #define ERR_INVALID_FIELD_NUM -201 // Invalid field number specified 101 #define ERR_SETFIELD_NOT_CALLED -210 // setField() was not called before writeFields() 102 #define ERR_CONNECT_FAILED -301 // Failed to connect to ThingSpeak 103 #define ERR_UNEXPECTED_FAIL -302 // Unexpected failure during write to ThingSpeak 104 #define ERR_BAD_RESPONSE -303 // Unable to parse response 105 #define ERR_TIMEOUT -304 // Timeout waiting for server to respond 106 #define ERR_NOT_INSERTED -401 // Point was not inserted (most probable cause is the rate limit of once every 15 seconds) 117 this->lastReadStatus = OK_SUCCESS;
141 bool begin(Client & client,
const char * customHostName,
unsigned int port)
143 #ifdef PRINT_DEBUG_MESSAGES 144 Serial.print(
"ts::tsBegin (client: Client URL: "); Serial.print(customHostName); Serial.println(
")");
146 this->setClient(&client);
147 this->setServer(customHostName, port);
149 this->lastReadStatus = OK_SUCCESS;
174 bool begin(Client & client, IPAddress customIP,
unsigned int port)
176 #ifdef PRINT_DEBUG_MESSAGES 177 Serial.print(
"ts::tsBegin (client: Client IP: "); Serial.print(customIP); Serial.println(
")");
179 this->setClient(&client);
180 this->setServer(customIP, port);
182 this->lastReadStatus = OK_SUCCESS;
207 #ifdef PRINT_DEBUG_MESSAGES 208 Serial.print(
"ts::tsBegin");
210 this->setClient(&client);
213 this->lastReadStatus = OK_SUCCESS;
233 int writeField(
unsigned long channelNumber,
unsigned int field,
int value,
const char * writeAPIKey)
235 char valueString[10];
236 itoa(value, valueString, 10);
237 return writeField(channelNumber, field, valueString, writeAPIKey);
256 int writeField(
unsigned long channelNumber,
unsigned int field,
long value,
const char * writeAPIKey)
258 char valueString[15];
259 ltoa(value, valueString, 10);
260 return writeField(channelNumber, field, valueString, writeAPIKey);
280 int writeField(
unsigned long channelNumber,
unsigned int field,
float value,
const char * writeAPIKey)
282 #ifdef PRINT_DEBUG_MESSAGES 283 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(
")");
285 char valueString[20];
286 int status = convertFloatToChar(value, valueString);
287 if(status != OK_SUCCESS)
return status;
289 return writeField(channelNumber, field, valueString, writeAPIKey);
313 int writeField(
unsigned long channelNumber,
unsigned int field,
const char * value,
const char * writeAPIKey)
315 return writeField(channelNumber, field, String(value), writeAPIKey);
342 int writeField(
unsigned long channelNumber,
unsigned int field, String value,
const char * writeAPIKey)
345 if(field < FIELDNUM_MIN || field > FIELDNUM_MAX)
return ERR_INVALID_FIELD_NUM;
347 if(value.length() > FIELDLENGTH_MAX)
return ERR_OUT_OF_RANGE;
349 #ifdef PRINT_DEBUG_MESSAGES 350 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(
"\")");
352 String postMessage = String(
"field") + String(field) +
"=" + value;
353 return writeRaw(channelNumber, postMessage, writeAPIKey);
391 char valueString[10];
392 itoa(value, valueString, 10);
394 return setField(field, valueString);
431 char valueString[15];
432 ltoa(value, valueString, 10);
433 return setField(field, valueString);
470 char valueString[20];
471 int status = convertFloatToChar(value, valueString);
472 if(status != OK_SUCCESS)
return status;
474 return setField(field, valueString);
508 int setField(
unsigned int field,
const char * value)
510 return setField(field, String(value));
546 #ifdef PRINT_DEBUG_MESSAGES 547 Serial.print(
"ts::setField (field: "); Serial.print(field); Serial.print(
" value: \""); Serial.print(value); Serial.println(
"\")");
549 if(field < FIELDNUM_MIN || field > FIELDNUM_MAX)
return ERR_INVALID_FIELD_NUM;
551 if(value.length() > FIELDLENGTH_MAX)
return ERR_OUT_OF_RANGE;
552 this->nextWriteField[field - 1] = value;
592 #ifdef PRINT_DEBUG_MESSAGES 593 Serial.print(
"ts::setLatitude(latitude: "); Serial.print(latitude,3); Serial.println(
"\")");
595 this->nextWriteLatitude = latitude;
635 #ifdef PRINT_DEBUG_MESSAGES 636 Serial.print(
"ts::setLongitude(longitude: "); Serial.print(longitude,3); Serial.println(
"\")");
638 this->nextWriteLongitude = longitude;
678 #ifdef PRINT_DEBUG_MESSAGES 679 Serial.print(
"ts::setElevation(elevation: "); Serial.print(elevation,3); Serial.println(
"\")");
681 this->nextWriteElevation = elevation;
757 #ifdef PRINT_DEBUG_MESSAGES 758 Serial.print(
"ts::setStatus(status: "); Serial.print(status); Serial.println(
"\")");
761 if(status.length() > FIELDLENGTH_MAX)
return ERR_OUT_OF_RANGE;
762 this->nextWriteStatus = status;
910 #ifdef PRINT_DEBUG_MESSAGES 911 Serial.print(
"ts::setTwitterTweet(twitter: "); Serial.print(twitter); Serial.print(
", tweet: "); Serial.print(tweet); Serial.println(
"\")");
914 if((twitter.length() > FIELDLENGTH_MAX) || (tweet.length() > FIELDLENGTH_MAX))
return ERR_OUT_OF_RANGE;
916 this->nextWriteTwitter = twitter;
917 this->nextWriteTweet = tweet;
993 #ifdef PRINT_DEBUG_MESSAGES 994 Serial.print(
"ts::setCreatedAt(createdAt: "); Serial.print(createdAt); Serial.println(
"\")");
1000 if(createdAt.length() > FIELDLENGTH_MAX)
return ERR_OUT_OF_RANGE;
1001 this->nextWriteCreatedAt = createdAt;
1041 int writeFields(
unsigned long channelNumber,
const char * writeAPIKey)
1043 String postMessage = String(
"");
1044 bool fFirstItem =
true;
1045 for(
size_t iField = 0; iField < 8; iField++)
1047 if(this->nextWriteField[iField].length() > 0)
1051 postMessage = postMessage + String(
"&");
1053 postMessage = postMessage + String(
"field") + String(iField + 1) + String(
"=") + this->nextWriteField[iField];
1055 this->nextWriteField[iField] =
"";
1059 if(!isnan(nextWriteLatitude))
1063 postMessage = postMessage + String(
"&");
1065 postMessage = postMessage + String(
"lat=") + String(this->nextWriteLatitude);
1067 this->nextWriteLatitude = NAN;
1070 if(!isnan(this->nextWriteLongitude))
1074 postMessage = postMessage + String(
"&");
1076 postMessage = postMessage + String(
"long=") + String(this->nextWriteLongitude);
1078 this->nextWriteLongitude = NAN;
1082 if(!isnan(this->nextWriteElevation))
1086 postMessage = postMessage + String(
"&");
1088 postMessage = postMessage + String(
"elevation=") + String(this->nextWriteElevation);
1090 this->nextWriteElevation = NAN;
1093 if(this->nextWriteStatus.length() > 0)
1097 postMessage = postMessage + String(
"&");
1099 postMessage = postMessage + String(
"status=") + String(this->nextWriteStatus);
1101 this->nextWriteStatus =
"";
1104 if(this->nextWriteTwitter.length() > 0)
1108 postMessage = postMessage + String(
"&");
1110 postMessage = postMessage + String(
"twitter=") + String(this->nextWriteTwitter);
1112 this->nextWriteTwitter =
"";
1115 if(this->nextWriteTweet.length() > 0)
1119 postMessage = postMessage + String(
"&");
1121 postMessage = postMessage + String(
"tweet=") + String(this->nextWriteTweet);
1123 this->nextWriteTweet =
"";
1126 if(this->nextWriteCreatedAt.length() > 0)
1130 postMessage = postMessage + String(
"&");
1132 postMessage = postMessage + String(
"created_at=") + String(this->nextWriteCreatedAt);
1134 this->nextWriteCreatedAt =
"";
1141 return ERR_SETFIELD_NOT_CALLED;
1144 return writeRaw(channelNumber, postMessage, writeAPIKey);
1168 int writeRaw(
unsigned long channelNumber,
const char * postMessage,
const char * writeAPIKey)
1170 return writeRaw(channelNumber, String(postMessage), writeAPIKey);
1189 int writeRaw(
unsigned long channelNumber, String postMessage,
const char * writeAPIKey)
1191 #ifdef PRINT_DEBUG_MESSAGES 1192 Serial.print(
"ts::writeRaw (channelNumber: "); Serial.print(channelNumber); Serial.print(
" writeAPIKey: "); Serial.print(writeAPIKey); Serial.print(
" postMessage: \""); Serial.print(postMessage); Serial.println(
"\")");
1195 if(!connectThingSpeak())
1198 return ERR_CONNECT_FAILED;
1201 postMessage = postMessage + String(
"&headers=false");
1203 #ifdef PRINT_DEBUG_MESSAGES 1204 Serial.print(
" POST \"");Serial.print(postMessage);Serial.println(
"\"");
1207 postMessage = postMessage + String(
"\n");
1210 if(!this->client->print(
"POST /update HTTP/1.1\r\n"))
return abortWriteRaw();
1211 if(!writeHTTPHeader(writeAPIKey))
return abortWriteRaw();
1212 if(!this->client->print(
"Content-Type: application/x-www-form-urlencoded\r\n"))
return abortWriteRaw();
1213 if(!this->client->print(
"Content-Length: "))
return abortWriteRaw();
1214 if(!this->client->print(postMessage.length()))
return abortWriteRaw();
1215 if(!this->client->print(
"\r\n\r\n"))
return abortWriteRaw();
1216 if(!this->client->print(postMessage))
return abortWriteRaw();
1218 String entryIDText = String();
1219 int status = getHTTPResponse(entryIDText);
1220 if(status != OK_SUCCESS)
1225 long entryID = entryIDText.toInt();
1227 #ifdef PRINT_DEBUG_MESSAGES 1228 Serial.print(
" Entry ID \"");Serial.print(entryIDText);Serial.print(
"\" (");Serial.print(entryID);Serial.println(
")");
1233 #ifdef PRINT_DEBUG_MESSAGES 1234 Serial.println(
"disconnected.");
1239 status = ERR_NOT_INSERTED;
1259 String
readStringField(
unsigned long channelNumber,
unsigned int field,
const char * readAPIKey)
1261 if(field < FIELDNUM_MIN || field > FIELDNUM_MAX)
1263 this->lastReadStatus = ERR_INVALID_FIELD_NUM;
1266 #ifdef PRINT_DEBUG_MESSAGES 1267 Serial.print(
"ts::readStringField(channelNumber: "); Serial.print(channelNumber);
1268 if(NULL != readAPIKey)
1270 Serial.print(
" readAPIKey: "); Serial.print(readAPIKey);
1272 Serial.print(
" field: "); Serial.print(field); Serial.println(
")");
1274 return readRaw(channelNumber, String(String(
"/fields/") + String(field) + String(
"/last")), readAPIKey);
1314 float readFloatField(
unsigned long channelNumber,
unsigned int field,
const char * readAPIKey)
1316 return convertStringToFloat(
readStringField(channelNumber, field, readAPIKey));
1356 long readLongField(
unsigned long channelNumber,
unsigned int field,
const char * readAPIKey)
1399 int readIntField(
unsigned long channelNumber,
unsigned int field,
const char * readAPIKey)
1439 String
readStatus(
unsigned long channelNumber,
const char * readAPIKey)
1441 String content =
readRaw(channelNumber,
"/feeds/last.txt?status=true", readAPIKey);
1447 return getJSONValueByKey(content,
"status");
1484 String content =
readRaw(channelNumber,
"/feeds/last.txt", readAPIKey);
1490 return getJSONValueByKey(content,
"created_at");
1526 String
readRaw(
unsigned long channelNumber, String URLSuffix)
1528 return readRaw(channelNumber, URLSuffix, NULL);
1547 String
readRaw(
unsigned long channelNumber, String URLSuffix,
const char * readAPIKey)
1549 #ifdef PRINT_DEBUG_MESSAGES 1550 Serial.print(
"ts::readRaw (channelNumber: "); Serial.print(channelNumber);
1551 if(NULL != readAPIKey)
1553 Serial.print(
" readAPIKey: "); Serial.print(readAPIKey);
1555 Serial.print(
" URLSuffix: \""); Serial.print(URLSuffix); Serial.println(
"\")");
1558 if(!connectThingSpeak())
1560 this->lastReadStatus = ERR_CONNECT_FAILED;
1564 String URL = String(
"/channels/") + String(channelNumber) + URLSuffix;
1566 #ifdef PRINT_DEBUG_MESSAGES 1567 Serial.print(
" GET \"");Serial.print(URL);Serial.println(
"\"");
1571 if(!this->client->print(
"GET "))
return abortReadRaw();
1572 if(!this->client->print(URL))
return abortReadRaw();
1573 if(!this->client->print(
" HTTP/1.1\r\n"))
return abortReadRaw();
1574 if(!writeHTTPHeader(readAPIKey))
return abortReadRaw();
1575 if(!this->client->print(
"\r\n"))
return abortReadRaw();
1577 String content = String();
1578 int status = getHTTPResponse(content);
1580 this->lastReadStatus = status;
1583 #ifdef PRINT_DEBUG_MESSAGES 1584 if(status == OK_SUCCESS)
1586 Serial.print(
"Read: \""); Serial.print(content); Serial.println(
"\"");
1591 #ifdef PRINT_DEBUG_MESSAGES 1592 Serial.println(
"disconnected.");
1595 if(status != OK_SUCCESS)
1602 return String(
"") + content;
1640 return this->lastReadStatus;
1644 String getJSONValueByKey(String textToSearch, String key)
1646 if(textToSearch.length() == 0){
1650 String searchPhrase = String(
"\"") + key + String(
"\":\"");
1652 int fromPosition = textToSearch.indexOf(searchPhrase,0);
1654 if(fromPosition == -1){
1659 fromPosition = fromPosition + searchPhrase.length();
1661 int toPosition = textToSearch.indexOf(
"\"", fromPosition);
1664 if(toPosition == -1){
1669 textToSearch.remove(toPosition);
1671 return textToSearch.substring(fromPosition);
1676 this->client->stop();
1677 return ERR_UNEXPECTED_FAIL;
1680 String abortReadRaw()
1682 this->client->stop();
1683 #ifdef PRINT_DEBUG_MESSAGES 1684 Serial.println(
"ReadRaw abort - disconnected.");
1686 this->lastReadStatus = ERR_UNEXPECTED_FAIL;
1690 void setServer(
const char * customHostName,
unsigned int port)
1692 #ifdef PRINT_DEBUG_MESSAGES 1693 Serial.print(
"ts::setServer (URL: \""); Serial.print(customHostName); Serial.println(
"\")");
1695 this->customIP = INADDR_NONE;
1696 this->customHostName = customHostName;
1700 void setServer(IPAddress customIP,
unsigned int port)
1702 #ifdef PRINT_DEBUG_MESSAGES 1703 Serial.print(
"ts::setServer (IP: \""); Serial.print(customIP); Serial.println(
"\")");
1705 this->customIP = customIP;
1706 this->customHostName = NULL;
1712 #ifdef PRINT_DEBUG_MESSAGES 1713 Serial.print(
"ts::setServer (default)");
1715 this->customIP = INADDR_NONE;
1716 this->customHostName = NULL;
1717 this->port = THINGSPEAK_PORT_NUMBER;
1720 void setClient(Client * client) {this->client = client;};
1722 Client * client = NULL;
1723 const char * customHostName = NULL;
1724 IPAddress customIP = INADDR_NONE;
1725 unsigned int port = THINGSPEAK_PORT_NUMBER;
1726 String nextWriteField[8];
1727 float nextWriteLatitude;
1728 float nextWriteLongitude;
1729 float nextWriteElevation;
1731 String nextWriteStatus;
1732 String nextWriteTwitter;
1733 String nextWriteTweet;
1734 String nextWriteCreatedAt;
1736 bool connectThingSpeak()
1738 bool connectSuccess =
false;
1739 if(this->customIP == INADDR_NONE && NULL == this->customHostName)
1741 #ifdef PRINT_DEBUG_MESSAGES 1742 Serial.print(
" Connect to default ThingSpeak URL...");
1744 connectSuccess = client->connect(THINGSPEAK_URL,THINGSPEAK_PORT_NUMBER);
1747 #ifdef PRINT_DEBUG_MESSAGES 1748 Serial.print(
"Failed. Try default IP...");
1750 connectSuccess = client->connect(THINGSPEAK_IPADDRESS,THINGSPEAK_PORT_NUMBER);
1755 if(!(this->customIP == INADDR_NONE))
1758 #ifdef PRINT_DEBUG_MESSAGES 1759 Serial.print(
" Connect to ");Serial.print(this->customIP);Serial.print(
"...");
1761 connectSuccess = client->connect(this->customIP,this->port);
1763 if(NULL != this->customHostName)
1766 #ifdef PRINT_DEBUG_MESSAGES 1767 Serial.print(
" Connect to ");Serial.print(this->customHostName);Serial.print(
" ...");
1769 connectSuccess = client->connect(customHostName,this->port);
1773 #ifdef PRINT_DEBUG_MESSAGES 1776 Serial.println(
"Success.");
1780 Serial.println(
"Failed.");
1783 return connectSuccess;
1786 bool writeHTTPHeader(
const char * APIKey)
1788 if(NULL != this->customHostName)
1790 if (!this->client->print(
"Host: "))
return false;
1791 if (!this->client->print(this->customHostName))
return false;
1792 if (!this->client->print(
"\r\n"))
return false;
1796 if (!this->client->print(
"Host: api.thingspeak.com\r\n"))
return false;
1798 if (!this->client->print(
"Connection: close\r\n"))
return false;
1799 if (!this->client->print(
"User-Agent: "))
return false;
1800 if (!this->client->print(TS_USER_AGENT))
return false;
1801 if (!this->client->print(
"\r\n"))
return false;
1804 if (!this->client->print(
"X-THINGSPEAKAPIKEY: "))
return false;
1805 if (!this->client->print(APIKey))
return false;
1806 if (!this->client->print(
"\r\n"))
return false;
1811 int getHTTPResponse(String & response)
1813 long startWaitForResponseAt = millis();
1814 while(client->available() == 0 && millis() - startWaitForResponseAt < TIMEOUT_MS_SERVERRESPONSE)
1818 if(client->available() == 0)
1823 if(!client->find(const_cast<char *>(
"HTTP/1.1")))
1826 Serial.println(
"ERROR: Didn't find HTTP/1.1");
1828 return ERR_BAD_RESPONSE;
1830 int status = client->parseInt();
1832 Serial.print(
"Got Status of ");Serial.println(status);
1834 if(status != OK_SUCCESS)
1839 if(!client->find(const_cast<char *>(
"\r\n")))
1842 Serial.println(
"ERROR: Didn't find end of status line");
1844 return ERR_BAD_RESPONSE;
1847 Serial.println(
"Found end of status line");
1850 if(!client->find(const_cast<char *>(
"\n\r\n")))
1853 Serial.println(
"ERROR: Didn't find end of header");
1855 return ERR_BAD_RESPONSE;
1858 Serial.println(
"Found end of header");
1861 String tempString = client->readString();
1862 response = tempString;
1864 Serial.print(
"Response: \"");Serial.print(response);Serial.println(
"\"");
1869 int convertFloatToChar(
float value,
char *valueString)
1872 if(0 == isinf(value) && (value > 999999000000 || value < -999999000000))
1875 return ERR_OUT_OF_RANGE;
1879 #if defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM) 1880 sprintf(valueString,
"%.5f", value);
1882 dtostrf(value,1,5, valueString);
1887 float convertStringToFloat(String value)
1890 float result = value.toFloat();
1892 if(1 == isinf(result) && *value.c_str() ==
'-')
1894 result = (float)-INFINITY;
1899 void resetWriteFields()
1901 for(
size_t iField = 0; iField < 8; iField++)
1903 this->nextWriteField[iField] =
"";
1905 this->nextWriteLatitude = NAN;
1906 this->nextWriteLongitude = NAN;
1907 this->nextWriteElevation = NAN;
1908 this->nextWriteStatus =
"";
1909 this->nextWriteTwitter =
"";
1910 this->nextWriteTweet =
"";
1911 this->nextWriteCreatedAt =
"";
1917 #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:1168
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:798
String readStringField(unsigned long channelNumber, unsigned int field, const char *readAPIKey)
Read the latest string from a private ThingSpeak channel.
Definition: ThingSpeak.h:1259
String readStringField(unsigned long channelNumber, unsigned int field)
Read the latest string from a public ThingSpeak channel.
Definition: ThingSpeak.h:1292
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:429
String readCreatedAt(unsigned long channelNumber)
Read the created-at timestamp associated with the latest update to a private ThingSpeak channel...
Definition: ThingSpeak.h:1506
int writeRaw(unsigned long channelNumber, String postMessage, const char *writeAPIKey)
Write a raw POST to a ThingSpeak channel.
Definition: ThingSpeak.h:1189
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:174
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:1041
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:388
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:872
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:835
int setLatitude(float latitude)
Set the latitude of a multi-field update. To record latitude, longitude and elevation of a write...
Definition: ThingSpeak.h:590
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:1482
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:755
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:141
int getLastReadStatus()
Get the status of the previous read.
Definition: ThingSpeak.h:1638
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:233
Enables an Arduino, ESP8266, ESP32 or other compatible hardware to write or read data to or from Thin...
Definition: ThingSpeak.h:111
long readLongField(unsigned long channelNumber, unsigned int field, const char *readAPIKey)
Read the latest long from a private ThingSpeak channel.
Definition: ThingSpeak.h:1356
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:342
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:718
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:508
String readRaw(unsigned long channelNumber, String URLSuffix)
Read a raw response from a public ThingSpeak channel.
Definition: ThingSpeak.h:1526
long readLongField(unsigned long channelNumber, unsigned int field)
Read the latest long from a public ThingSpeak channel.
Definition: ThingSpeak.h:1377
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:280
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:954
int readIntField(unsigned long channelNumber, unsigned int field, const char *readAPIKey)
Read the latest int from a private ThingSpeak channel.
Definition: ThingSpeak.h:1399
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:544
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:991
int setLongitude(float longitude)
Set the longitude of a multi-field update. To record latitude, longitude and elevation of a write...
Definition: ThingSpeak.h:633
float readFloatField(unsigned long channelNumber, unsigned int field, const char *readAPIKey)
Read the latest float from a private ThingSpeak channel.
Definition: ThingSpeak.h:1314
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:909
String readStatus(unsigned long channelNumber, const char *readAPIKey)
Read the latest status from a private ThingSpeak channel.
Definition: ThingSpeak.h:1439
bool begin(Client &client)
Initializes the ThingSpeak library and network settings using the ThingSpeak.com service.
Definition: ThingSpeak.h:205
float readFloatField(unsigned long channelNumber, unsigned int field)
Read the latest float from a public ThingSpeak channel.
Definition: ThingSpeak.h:1335
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:313
int readIntField(unsigned long channelNumber, unsigned int field)
Read the latest int from a public ThingSpeak channel.
Definition: ThingSpeak.h:1420
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:468
String readRaw(unsigned long channelNumber, String URLSuffix, const char *readAPIKey)
Read a raw response from a private ThingSpeak channel.
Definition: ThingSpeak.h:1547
String readStatus(unsigned long channelNumber)
Read the latest status from a public ThingSpeak channel.
Definition: ThingSpeak.h:1463
int setElevation(float elevation)
Set the elevation of a multi-field update. To record latitude, longitude and elevation of a write...
Definition: ThingSpeak.h:676
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:256