ThingSpeak Communication Library Enables an Arduino, ESP8266, or Particle to write or read data to or from ThingSpeak™ |

- Main Page
- Data Structures

- Data Structures
- Data Fields

Public Member Functions
ThingSpeakClass Class Reference

Enables an Arduino, ESP8266, Particle or other compatible hardware to write or read data to or from ThingSpeak, an open data platform for the Internet of Things with MATLAB analytics and visualization. More...

## Public Member Functions
bool | begin (Client &client, const char *customHostName, unsigned int port)
| Initializes the ThingSpeak library and network settings using a custom installation of ThingSpeak. More...
bool | begin (Client &client, IPAddress customIP, unsigned int port)
| Initializes the ThingSpeak library and network settings using a custom installation of ThingSpeak. More...
bool | begin (Client &client)
| Initializes the ThingSpeak library and network settings using the ThingSpeak.com service. More...
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. More...
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. More...
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. More...
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. More...
int | writeField (unsigned long channelNumber, unsigned int field, String value, const char *writeAPIKey)
| Write a String to a single field in a ThingSpeak channel. More...
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 at once, call setField() for each of the fields you want to write, and then call writeFields() More...
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 at once, call setField() for each of the fields you want to write, and then call writeFields() More...
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 at once, call setField() for each of the fields you want to write, and then call writeFields() More...
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 at once, call setField() for each of the fields you want to write, and then call writeFields() More...
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 at once, call setField() for each of the fields you want to write, and then call writeFields() More...
int | setLatitude (float latitude)
| Set the latitude of a multi-field update. To record latitude, longitude and elevation of a write, call setField() for each of the fields you want to write, setLatitude() / setLongitude() / setElevation(), and then call writeFields() More...
int | setLongitude (float longitude)
| Set the longitude of a multi-field update. To record latitude, longitude and elevation of a write, call setField() for each of the fields you want to write, setLatitude() / setLongitude() / setElevation(), and then call writeFields() More...
int | setElevation (float elevation)
| Set the elevation of a multi-field update. To record latitude, longitude and elevation of a write, call setField() for each of the fields you want to write, setLatitude() / setLongitude() / setElevation(), and then call writeFields() More...
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() More...
int | writeRaw (unsigned long channelNumber, const char *postMessage, const char *writeAPIKey)
| Write a raw POST to a ThingSpeak channel. More...
int | writeRaw (unsigned long channelNumber, String postMessage, const char *writeAPIKey)
| Write a raw POST to a ThingSpeak channel. More...
String | readStringField (unsigned long channelNumber, unsigned int field, const char *readAPIKey)
| Read the latest string from a private ThingSpeak channel. More...
String | readStringField (unsigned long channelNumber, unsigned int field)
| Read the latest string from a public ThingSpeak channel. More...
float | readFloatField (unsigned long channelNumber, unsigned int field, const char *readAPIKey)
| Read the latest float from a private ThingSpeak channel. More...
float | readFloatField (unsigned long channelNumber, unsigned int field)
| Read the latest float from a public ThingSpeak channel. More...
long | readLongField (unsigned long channelNumber, unsigned int field, const char *readAPIKey)
| Read the latest long from a private ThingSpeak channel. More...
long | readLongField (unsigned long channelNumber, unsigned int field)
| Read the latest long from a public ThingSpeak channel. More...
int | readIntField (unsigned long channelNumber, unsigned int field, const char *readAPIKey)
| Read the latest int from a private ThingSpeak channel. More...
int | readIntField (unsigned long channelNumber, unsigned int field)
| Read the latest int from a public ThingSpeak channel. More...
String | readRaw (unsigned long channelNumber, String URLSuffix)
| Read a raw response from a public ThingSpeak channel. More...
String | readRaw (unsigned long channelNumber, String URLSuffix, const char *readAPIKey)
| Read a raw response from a private ThingSpeak channel. More...
int | getLastReadStatus ()
| Get the status of the previous read. More...

## Detailed Description

Enables an Arduino, ESP8266, Particle or other compatible hardware to write or read data to or from ThingSpeak, an open data platform for the Internet of Things with MATLAB analytics and visualization.

## Member Function Documentation

bool begin | ( | Client & | client,
|  | const char * | customHostName,
|  | unsigned int | port
| ) |  |

Initializes the ThingSpeak library and network settings using a custom installation of ThingSpeak.

Parameters

  client | EthernetClient, YunClient, TCPClient, or WiFiClient created earlier in the sketch
  customHostName | Host name of a custom install of ThingSpeak
  port | Port number to use with a custom install of ThingSpeak

Returns
  Always returns true This does not validate the information passed in, or generate any calls to ThingSpeak.
  #include <SPI.h>
  #include <Ethernet.h>
  byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
  EthernetClient client;
  #include "ThingSpeak.h"
  void setup() {
  Ethernet.begin(mac);
  ThingSpeak.begin(client,"api.thingspeak.com", 80);
  }

bool begin | ( | Client & | client,
|  | IPAddress | customIP,
|  | unsigned int | port
| ) |  |

Initializes the ThingSpeak library and network settings using a custom installation of ThingSpeak.

Parameters

  client | EthernetClient, YunClient, TCPClient, or WiFiClient created earlier in the sketch
  customIP | IP address of a custom install of ThingSpeak
  port | Port number to use with a custom install of ThingSpeak

Returns
  Always returns true This does not validate the information passed in, or generate any calls to ThingSpeak.
  #include <SPI.h>
  #include <Ethernet.h>
  byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
  EthernetClient client;
  #include "ThingSpeak.h"
  void setup() {
  Ethernet.begin(mac);
  ThingSpeak.begin(client,IPAddress(184,106,153,149), 80);
  }

bool begin | ( | Client & | client | ) |

Initializes the ThingSpeak library and network settings using the ThingSpeak.com service.

Parameters

  client | EthernetClient, YunClient, TCPClient, or WiFiClient created earlier in the sketch

Returns
  Always returns true This does not validate the information passed in, or generate any calls to ThingSpeak.
  #include <SPI.h>
  #include <Ethernet.h>
  byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
  EthernetClient client;
  #include "ThingSpeak.h"
  void setup() {
  Ethernet.begin(mac);
  ThingSpeak.begin(client);
  }

int getLastReadStatus | ( |  | ) |

Get the status of the previous read.

Returns
  Generally, these are HTTP status codes. Negative values indicate an error generated by the library. Possible response codes:
  - 200: OK / Success
  - 404: Incorrect API key (or invalid ThingSpeak server address)
  - -101: Value is out of range or string is too long (> 255 characters)
  - -201: Invalid field number specified
  - -210: setField() was not called before writeFields()
  - -301: Failed to connect to ThingSpeak
  - -302: Unexpected failure during write to ThingSpeak
  - -303: Unable to parse response
  - -304: Timeout waiting for server to respond
  - -401: Point was not inserted (most probable cause is the rate limit of once every 15 seconds)

Remarks
  The read functions will return zero or empty if there is an error. Use this function to retrieve the details.
  void loop() {
  String message = ThingSpeak.readStringField(myChannelNumber, 1);
  int resultCode = ThingSpeak.getLastReadStatus();
  if(resultCode == 200)
  {
  Serial.print("Latest message is: ");
  Serial.println(message);
  }
  else
  {
  Serial.print("Error reading message. Status was: ");
  Serial.println(resultCode);
  }
  delay(30000);
  }

float readFloatField | ( | unsigned long | channelNumber,
|  | unsigned int | field,
|  | const char * | readAPIKey
| ) |  |

Read the latest float from a private ThingSpeak channel.

Parameters

  channelNumber | Channel number
  field | Field number (1-8) within the channel to read from.
  readAPIKey | Read API key associated with the channel. If you share code with others, do not share this key

Returns
  Value read, or 0 if the field is text or there is an error. Use getLastReadStatus() to get more specific information. Note that NAN, INFINITY, and -INFINITY are valid results.
  void loop() {
  float voltage = ThingSpeak.readFloatField(myChannelNumber, 1, myReadAPIKey);
  Serial.print("Latest voltage is: ");
  Serial.print(voltage);
  Serial.println("V");
  delay(30000);
  }

float readFloatField | ( | unsigned long | channelNumber,
|  | unsigned int | field
| ) |  |

Read the latest float from a public ThingSpeak channel.

Parameters

  channelNumber | Channel number
  field | Field number (1-8) within the channel to read from.

Returns
  Value read, or 0 if the field is text or there is an error. Use getLastReadStatus() to get more specific information. Note that NAN, INFINITY, and -INFINITY are valid results.
  void loop() {
  float voltage = ThingSpeak.readFloatField(myChannelNumber, 1);
  Serial.print("Latest voltage is: ");
  Serial.print(voltage);
  Serial.println("V");
  delay(30000);
  }

int readIntField | ( | unsigned long | channelNumber,
|  | unsigned int | field,
|  | const char * | readAPIKey
| ) |  |

Read the latest int from a private ThingSpeak channel.

Parameters

  channelNumber | Channel number
  field | Field number (1-8) within the channel to read from.
  readAPIKey | Read API key associated with the channel. If you share code with others, do not share this key

Returns
  Value read, or 0 if the field is text or there is an error. Use getLastReadStatus() to get more specific information.

Remarks
  If the value returned is out of range for an int, the result is undefined.
  void loop() {
  int value = ThingSpeak.readIntField(myChannelNumber, 1, myReadAPIKey);
  Serial.print("Latest value is: ");
  Serial.print(value);
  delay(30000);
  }

int readIntField | ( | unsigned long | channelNumber,
|  | unsigned int | field
| ) |  |

Read the latest int from a public ThingSpeak channel.

Parameters

  channelNumber | Channel number
  field | Field number (1-8) within the channel to read from.

Returns
  Value read, or 0 if the field is text or there is an error. Use getLastReadStatus() to get more specific information.

Remarks
  If the value returned is out of range for an int, the result is undefined.
  void loop() {
  int value = ThingSpeak.readIntField(myChannelNumber, 1);
  Serial.print("Latest value is: ");
  Serial.print(value);
  delay(30000);
  }

long readLongField | ( | unsigned long | channelNumber,
|  | unsigned int | field,
|  | const char * | readAPIKey
| ) |  |

Read the latest long from a private ThingSpeak channel.

Parameters

  channelNumber | Channel number
  field | Field number (1-8) within the channel to read from.
  readAPIKey | Read API key associated with the channel. If you share code with others, do not share this key

Returns
  Value read, or 0 if the field is text or there is an error. Use getLastReadStatus() to get more specific information.
  void loop() {
  long value = ThingSpeak.readLongField(myChannelNumber, 1, myReadAPIKey);
  Serial.print("Latest value is: ");
  Serial.print(value);
  delay(30000);
  }

long readLongField | ( | unsigned long | channelNumber,
|  | unsigned int | field
| ) |  |

Read the latest long from a public ThingSpeak channel.

Parameters

  channelNumber | Channel number
  field | Field number (1-8) within the channel to read from.

Returns
  Value read, or 0 if the field is text or there is an error. Use getLastReadStatus() to get more specific information.
  void loop() {
  long value = ThingSpeak.readLongField(myChannelNumber, 1);
  Serial.print("Latest value is: ");
  Serial.print(value);
  delay(30000);
  }

String readRaw | ( | unsigned long | channelNumber,
|  | String | URLSuffix
| ) |  |

Read a raw response from a public ThingSpeak channel.

Parameters

  channelNumber | Channel number
  URLSuffix | Raw URL to write to ThingSpeak as a String. See the documentation at https://thingspeak.com/docs/channels#get_feed

Returns
  Response if successful, or empty string. Use getLastReadStatus() to get more specific information.

Remarks
  This is low level functionality that will not be required by most users.
  void loop() {
  String response = ThingSpeak.readRaw(myChannelNumber, String("feeds/days=1"));
  Serial.print("Response: ");
  Serial.print(response);
  delay(30000);
  }

String readRaw | ( | unsigned long | channelNumber,
|  | String | URLSuffix,
|  | const char * | readAPIKey
| ) |  |

Read a raw response from a private ThingSpeak channel.

Parameters

  channelNumber | Channel number
  URLSuffix | Raw URL to write to ThingSpeak as a String. See the documentation at https://thingspeak.com/docs/channels#get_feed
  readAPIKey | Read API key associated with the channel. If you share code with others, do not share this key

Returns
  Response if successful, or empty string. Use getLastReadStatus() to get more specific information.

Remarks
  This is low level functionality that will not be required by most users.
  void loop() {
  String response = ThingSpeak.readRaw(myChannelNumber, String("feeds/days=1"), myReadAPIKey);
  Serial.print("Response: ");
  Serial.print(response);
  delay(30000);
  }

String readStringField | ( | unsigned long | channelNumber,
|  | unsigned int | field,
|  | const char * | readAPIKey
| ) |  |

Read the latest string from a private ThingSpeak channel.

Parameters

  channelNumber | Channel number
  field | Field number (1-8) within the channel to read from.
  readAPIKey | Read API key associated with the channel. If you share code with others, do not share this key

Returns
  Value read (UTF8 string), or empty string if there is an error. Use getLastReadStatus() to get more specific information.
  void loop() {
  String message = ThingSpeak.readStringField(myChannelNumber, 1, myReadAPIKey);
  Serial.print("Latest message is: ");
  Serial.println(message);
  delay(30000);
  }

String readStringField | ( | unsigned long | channelNumber,
|  | unsigned int | field
| ) |  |

Read the latest string from a public ThingSpeak channel.

Parameters

  channelNumber | Channel number
  field | Field number (1-8) within the channel to read from.

Returns
  Value read (UTF8), or empty string if there is an error. Use getLastReadStatus() to get more specific information.
  void loop() {
  String message = ThingSpeak.readStringField(myChannelNumber, 1);
  Serial.print("Latest message is: ");
  Serial.println(message);
  delay(30000);
  }

int setElevation | ( | float | elevation | ) |

Set the elevation of a multi-field update. To record latitude, longitude and elevation of a write, call setField() for each of the fields you want to write, setLatitude() / setLongitude() / setElevation(), and then call writeFields()

Parameters

  elevation | Elevation of the measurement (meters above sea level)

Returns
  HTTP status code of 200 if successful. See getLastReadStatus() for other possible return values.

See also
  setField(), setLatitude(), setLongitude(), writeFields()
  void loop() {
  int sensor1Value = analogRead(A0);
  float sensor2Voltage = analogRead(A1) * (5.0 / 1023.0);
  String sensor3Meaning;
  int sensor3Value = analogRead(A2);
  if (sensor3Value < 400) {
  sensor3Meaning = String("Too Cold!");
  } else if (sensor3Value > 600) {
  sensor3Meaning = String("Too Hot!");
  } else {
  sensor3Meaning = String("Just Right");
  }
  long timeRead = millis();
  ThingSpeak.setField(1, sensor1Value);
  ThingSpeak.setField(2, sensor2Voltage);
  ThingSpeak.setField(3, sensor3Meaning);
  ThingSpeak.setField(4, timeRead);
  setLatitude(42.2833);
  setLongitude(-71.3500);
  setElevation(100);
  ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
  delay(20000);
  }

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 at once, call setField() for each of the fields you want to write, and then call writeFields()

Parameters

  field | Field number (1-8) within the channel to set
  value | Integer value (from -32,768 to 32,767) to set.

Returns
  HTTP status code of 200 if successful. See getLastReadStatus() for other possible return values.

See also
  setLatitude(), setLongitude(), setElevation(), writeFields()
  void loop() {
  int sensor1Value = analogRead(A0);
  float sensor2Voltage = analogRead(A1) * (5.0 / 1023.0);
  String sensor3Meaning;
  int sensor3Value = analogRead(A2);
  if (sensor3Value < 400) {
  sensor3Meaning = String("Too Cold!");
  } else if (sensor3Value > 600) {
  sensor3Meaning = String("Too Hot!");
  } else {
  sensor3Meaning = String("Just Right");
  }
  long timeRead = millis();
  ThingSpeak.setField(1, sensor1Value);
  ThingSpeak.setField(2, sensor2Voltage);
  ThingSpeak.setField(3, sensor3Meaning);
  ThingSpeak.setField(4, timeRead);
  ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
  delay(20000);
  }

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 at once, call setField() for each of the fields you want to write, and then call writeFields()

Parameters

  field | Field number (1-8) within the channel to set
  value | Long value (from -2,147,483,648 to 2,147,483,647) to write.

Returns
  HTTP status code of 200 if successful. See getLastReadStatus() for other possible return values.

See also
  setLatitude(), setLongitude(), setElevation(), writeFields()
  void loop() {
  int sensor1Value = analogRead(A0);
  float sensor2Voltage = analogRead(A1) * (5.0 / 1023.0);
  String sensor3Meaning;
  int sensor3Value = analogRead(A2);
  if (sensor3Value < 400) {
  sensor3Meaning = String("Too Cold!");
  } else if (sensor3Value > 600) {
  sensor3Meaning = String("Too Hot!");
  } else {
  sensor3Meaning = String("Just Right");
  }
  long timeRead = millis();
  ThingSpeak.setField(1, sensor1Value);
  ThingSpeak.setField(2, sensor2Voltage);
  ThingSpeak.setField(3, sensor3Meaning);
  ThingSpeak.setField(4, timeRead);
  ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
  delay(20000);
  }

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 at once, call setField() for each of the fields you want to write, and then call writeFields()

Parameters

  field | Field number (1-8) within the channel to set
  value | Floating point value (from -999999000000 to 999999000000) to write. If you need more accuracy, or a wider range, you should format the number yourself (using `dtostrf`) and setField() using the resulting string.

Returns
  HTTP status code of 200 if successful. See getLastReadStatus() for other possible return values.

See also
  setLatitude(), setLongitude(), setElevation(), writeFields()
  void loop() {
  int sensor1Value = analogRead(A0);
  float sensor2Voltage = analogRead(A1) * (5.0 / 1023.0);
  String sensor3Meaning;
  int sensor3Value = analogRead(A2);
  if (sensor3Value < 400) {
  sensor3Meaning = String("Too Cold!");
  } else if (sensor3Value > 600) {
  sensor3Meaning = String("Too Hot!");
  } else {
  sensor3Meaning = String("Just Right");
  }
  long timeRead = millis();
  ThingSpeak.setField(1, sensor1Value);
  ThingSpeak.setField(2, sensor2Voltage);
  ThingSpeak.setField(3, sensor3Meaning);
  ThingSpeak.setField(4, timeRead);
  ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
  delay(20000);
  }

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 at once, call setField() for each of the fields you want to write, and then call writeFields()

Parameters

  field | Field number (1-8) within the channel to set
  value | String to write (UTF8). ThingSpeak limits this to 255 bytes.

Returns
  HTTP status code of 200 if successful. See getLastReadStatus() for other possible return values.

See also
  setLatitude(), setLongitude(), setElevation(), writeFields()
  void loop() {
  int sensor1Value = analogRead(A0);
  float sensor2Voltage = analogRead(A1) * (5.0 / 1023.0);
  String sensor3Meaning;
  int sensor3Value = analogRead(A2);
  if (sensor3Value < 400) {
  sensor3Meaning = String("Too Cold!");
  } else if (sensor3Value > 600) {
  sensor3Meaning = String("Too Hot!");
  } else {
  sensor3Meaning = String("Just Right");
  }
  long timeRead = millis();
  ThingSpeak.setField(1, sensor1Value);
  ThingSpeak.setField(2, sensor2Voltage);
  ThingSpeak.setField(3, sensor3Meaning);
  ThingSpeak.setField(4, timeRead);
  ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
  delay(20000);
  }

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 at once, call setField() for each of the fields you want to write, and then call writeFields()

Parameters

  field | Field number (1-8) within the channel to set
  value | String to write (UTF8). ThingSpeak limits this to 255 bytes.

Returns
  HTTP status code of 200 if successful. See getLastReadStatus() for other possible return values.

See also
  setLatitude(), setLongitude(), setElevation(), writeFields()
  void loop() {
  int sensor1Value = analogRead(A0);
  float sensor2Voltage = analogRead(A1) * (5.0 / 1023.0);
  String sensor3Meaning;
  int sensor3Value = analogRead(A2);
  if (sensor3Value < 400) {
  sensor3Meaning = String("Too Cold!");
  } else if (sensor3Value > 600) {
  sensor3Meaning = String("Too Hot!");
  } else {
  sensor3Meaning = String("Just Right");
  }
  long timeRead = millis();
  ThingSpeak.setField(1, sensor1Value);
  ThingSpeak.setField(2, sensor2Voltage);
  ThingSpeak.setField(3, sensor3Meaning);
  ThingSpeak.setField(4, timeRead);
  ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
  delay(20000);
  }

int setLatitude | ( | float | latitude | ) |

Set the latitude of a multi-field update. To record latitude, longitude and elevation of a write, call setField() for each of the fields you want to write, setLatitude() / setLongitude() / setElevation(), and then call writeFields()

Parameters

  latitude | Latitude of the measurement (degrees N, use negative values for degrees S)

Returns
  HTTP status code of 200 if successful. See getLastReadStatus() for other possible return values.

See also
  setField(), setLongitude(), setElevation(), writeFields()
  void loop() {
  int sensor1Value = analogRead(A0);
  float sensor2Voltage = analogRead(A1) * (5.0 / 1023.0);
  String sensor3Meaning;
  int sensor3Value = analogRead(A2);
  if (sensor3Value < 400) {
  sensor3Meaning = String("Too Cold!");
  } else if (sensor3Value > 600) {
  sensor3Meaning = String("Too Hot!");
  } else {
  sensor3Meaning = String("Just Right");
  }
  long timeRead = millis();
  ThingSpeak.setField(1, sensor1Value);
  ThingSpeak.setField(2, sensor2Voltage);
  ThingSpeak.setField(3, sensor3Meaning);
  ThingSpeak.setField(4, timeRead);
  ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
  setLatitude(42.2833);
  setLongitude(-71.3500);
  setElevation(100);
  delay(20000);
  }

int setLongitude | ( | float | longitude | ) |

Set the longitude of a multi-field update. To record latitude, longitude and elevation of a write, call setField() for each of the fields you want to write, setLatitude() / setLongitude() / setElevation(), and then call writeFields()

Parameters

  longitude | Longitude of the measurement (degrees E, use negative values for degrees W)

Returns
  HTTP status code of 200 if successful. See getLastReadStatus() for other possible return values.

See also
  setField(), setLatitude(), setElevation(), writeFields()
  void loop() {
  int sensor1Value = analogRead(A0);
  float sensor2Voltage = analogRead(A1) * (5.0 / 1023.0);
  String sensor3Meaning;
  int sensor3Value = analogRead(A2);
  if (sensor3Value < 400) {
  sensor3Meaning = String("Too Cold!");
  } else if (sensor3Value > 600) {
  sensor3Meaning = String("Too Hot!");
  } else {
  sensor3Meaning = String("Just Right");
  }
  long timeRead = millis();
  ThingSpeak.setField(1, sensor1Value);
  ThingSpeak.setField(2, sensor2Voltage);
  ThingSpeak.setField(3, sensor3Meaning);
  ThingSpeak.setField(4, timeRead);
  setLatitude(42.2833);
  setLongitude(-71.3500);
  setElevation(100);
  ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
  delay(20000);
  }

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.

Parameters

  channelNumber | Channel number
  field | Field number (1-8) within the channel to write to.
  value | Integer value (from -32,768 to 32,767) to write.
  writeAPIKey | Write API key associated with the channel. If you share code with others, do not share this key

Returns
  HTTP status code of 200 if successful. See getLastReadStatus() for other possible return values.

Remarks
  Visit https://thingspeak.com/docs/channels for more information about channels, API keys, and fields. ThingSpeak limits the number of writes to a channel to once every 15 seconds.
  void loop() {
  int sensorValue = analogRead(A0);
  ThingSpeak.writeField(myChannelNumber, 1, sensorValue, myWriteAPIKey);
  delay(20000);
  }

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.

Parameters

  channelNumber | Channel number
  field | Field number (1-8) within the channel to write to.
  value | Long value (from -2,147,483,648 to 2,147,483,647) to write.
  writeAPIKey | Write API key associated with the channel. If you share code with others, do not share this key

Returns
  HTTP status code of 200 if successful. See getLastReadStatus() for other possible return values.

Remarks
  Visit https://thingspeak.com/docs/channels for more information about channels, API keys, and fields. ThingSpeak limits the number of writes to a channel to once every 15 seconds.
  void loop() {
  int sensorValue = analogRead(A0);
  ThingSpeak.writeField(myChannelNumber, 1, sensorValue, myWriteAPIKey);
  delay(20000);
  }

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.

Parameters

  channelNumber | Channel number
  field | Field number (1-8) within the channel to write to.
  value | Floating point value (from -999999000000 to 999999000000) to write. If you need more accuracy, or a wider range, you should format the number using `dtostrf` and writeField().
  writeAPIKey | Write API key associated with the channel. If you share code with others, do not share this key

Returns
  HTTP status code of 200 if successful. See getLastReadStatus() for other possible return values.

Remarks
  Visit https://thingspeak.com/docs/channels for more information about channels, API keys, and fields. ThingSpeak limits the number of writes to a channel to once every 15 seconds.
  void loop() {
  int sensorValue = analogRead(A0);
  float voltage = sensorValue * (5.0 / 1023.0);
  ThingSpeak.writeField(myChannelNumber, 1, voltage, myWriteAPIKey);
  delay(20000);
  }

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.

Parameters

  channelNumber | Channel number
  field | Field number (1-8) within the channel to write to.
  value | String to write (UTF8 string). ThingSpeak limits this field to 255 bytes.
  writeAPIKey | Write API key associated with the channel. If you share code with others, do not share this key

Returns
  HTTP status code of 200 if successful. See getLastReadStatus() for other possible return values.

Remarks
  Visit https://thingspeak.com/docs/channels for more information about channels, API keys, and fields. ThingSpeak limits the number of writes to a channel to once every 15 seconds.
  void loop() {
  int sensorValue = analogRead(A0);
  if (sensorValue > 512) {
  ThingSpeak.writeField(myChannelNumber, 1, "High", myWriteAPIKey);
  }
  else {
  ThingSpeak.writeField(myChannelNumber, 1, "Low", myWriteAPIKey);
  }
  delay(20000);
  }

int writeField | ( | unsigned long | channelNumber,
|  | unsigned int | field,
|  | String | value,
|  | const char * | writeAPIKey
| ) |  |

Write a String to a single field in a ThingSpeak channel.

Parameters

  channelNumber | Channel number
  field | Field number (1-8) within the channel to write to.
  value | Character array (zero terminated) to write (UTF8). ThingSpeak limits this field to 255 bytes.
  writeAPIKey | Write API key associated with the channel. If you share code with others, do not share this key

Returns
  HTTP status code of 200 if successful. See getLastReadStatus() for other possible return values.

Remarks
  Visit https://thingspeak.com/docs/channels for more information about channels, API keys, and fields. ThingSpeak limits the number of writes to a channel to once every 15 seconds.
  void loop() {
  int sensorValue = analogRead(A0);
  String meaning;
  if (sensorValue < 400) {
  meaning = String("Too Cold!");
  } else if (sensorValue > 600) {
  meaning = String("Too Hot!");
  } else {
  meaning = String("Just Right");
  }
  ThingSpeak.writeField(myChannelNumber, 1, meaning, myWriteAPIKey);
  delay(20000);
  }

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()

Parameters

  channelNumber | Channel number
  writeAPIKey | Write API key associated with the channel. If you share code with others, do not share this key

Returns
  HTTP status code of 200 if successful. See getLastReadStatus() for other possible return values.

See also
  setField(), setLatitude(), setLongitude(), setElevation()
  void loop() {
  int sensor1Value = analogRead(A0);
  float sensor2Voltage = analogRead(A1) * (5.0 / 1023.0);
  String sensor3Meaning;
  int sensor3Value = analogRead(A2);
  if (sensor3Value < 400) {
  sensor3Meaning = String("Too Cold!");
  } else if (sensor3Value > 600) {
  sensor3Meaning = String("Too Hot!");
  } else {
  sensor3Meaning = String("Just Right");
  }
  long timeRead = millis();
  ThingSpeak.setField(1, sensor1Value);
  ThingSpeak.setField(2, sensor2Voltage);
  ThingSpeak.setField(3, sensor3Meaning);
  ThingSpeak.setField(4, timeRead);
  setLatitude(42.2833);
  setLongitude(-71.3500);
  setElevation(100);
  ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
  delay(20000);
  }

int writeRaw | ( | unsigned long | channelNumber,
|  | const char * | postMessage,
|  | const char * | writeAPIKey
| ) |  |

Write a raw POST to a ThingSpeak channel.

Parameters

  channelNumber | Channel number
  postMessage | Raw URL to write to ThingSpeak as a string. See the documentation at https://thingspeak.com/docs/channels#update_feed.
  writeAPIKey | Write API key associated with the channel. If you share code with others, do not share this key

Returns
  HTTP status code of 200 if successful. See getLastReadStatus() for other possible return values.

Remarks
  This is low level functionality that will not be required by most users.
  void loop() {
  const char postMessage[] = "field1=23&created_at=2014-12-31%2023:59:59";
  ThingSpeak.setField(1, sensor1Value);
  ThingSpeak.setField(2, sensor2Voltage);
  ThingSpeak.setField(3, sensor3Meaning);
  ThingSpeak.setField(4, timeRead);
  ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
  delay(20000);
  }

int writeRaw | ( | unsigned long | channelNumber,
|  | String | postMessage,
|  | const char * | writeAPIKey
| ) |  |

Write a raw POST to a ThingSpeak channel.

Parameters

  channelNumber | Channel number
  postMessage | Raw URL to write to ThingSpeak as a String. See the documentation at https://thingspeak.com/docs/channels#update_feed.
  writeAPIKey | Write API key associated with the channel. If you share code with others, do not share this key

Returns
  HTTP status code of 200 if successful. See getLastReadStatus() for other possible return values.

Remarks
  This is low level functionality that will not be required by most users.
  void loop() {
  String postMessage = String("field1=23&created_at=2014-12-31%2023:59:59");
  ThingSpeak.writeRaw(myChannelNumber, postMessage, myWriteAPIKey);
  delay(20000);
  }