### Read from ThingSpeak Channels with ESP8266 Source: https://github.com/mathworks/thingspeak-arduino/blob/master/README.md This example demonstrates reading data from both a public weather station channel and a private counter channel. It includes error checking for read operations and handles WiFi connectivity. Ensure 'secrets.h' contains your network credentials and channel IDs. ```cpp #include #include "secrets.h" #include "ThingSpeak.h" char ssid[] = SECRET_SSID; char pass[] = SECRET_PASS; int keyIndex = 0; WiFiClient client; unsigned long weatherStationChannelNumber = SECRET_CH_ID_WEATHER_STATION; unsigned int temperatureFieldNumber = 4; unsigned long counterChannelNumber = SECRET_CH_ID_COUNTER; const char * myCounterReadAPIKey = SECRET_READ_APIKEY_COUNTER; unsigned int counterFieldNumber = 1; void setup() { Serial.begin(115200); while (!Serial) { ; } WiFi.mode(WIFI_STA); ThingSpeak.begin(client); } void loop() { int statusCode = 0; if(WiFi.status() != WL_CONNECTED){ Serial.print("Attempting to connect to SSID: "); Serial.println(SECRET_SSID); while(WiFi.status() != WL_CONNECTED){ WiFi.begin(ssid, pass); Serial.print("."); delay(5000); } Serial.println("\nConnected"); } float temperatureInF = ThingSpeak.readFloatField(weatherStationChannelNumber, temperatureFieldNumber); statusCode = ThingSpeak.getLastReadStatus(); if(statusCode == 200){ Serial.println("Temperature at MathWorks HQ: " + String(temperatureInF) + " deg F"); } else{ Serial.println("Problem reading channel. HTTP error code " + String(statusCode)); } delay(15000); long count = ThingSpeak.readLongField(counterChannelNumber, counterFieldNumber, myCounterReadAPIKey); statusCode = ThingSpeak.getLastReadStatus(); if(statusCode == 200){ Serial.println("Counter: " + String(count)); } else{ Serial.println("Problem reading channel. HTTP error code " + String(statusCode)); } delay(15000); } ``` -------------------------------- ### Get Field Value as String Source: https://github.com/mathworks/thingspeak-arduino/blob/master/README.md Fetches the stored value from a field as a String. Must be invoked after readMultipleFields(). Not available on Arduino Uno due to memory constraints. ```Arduino String getFieldAsString (field) ``` -------------------------------- ### Get Field Value as Float Source: https://github.com/mathworks/thingspeak-arduino/blob/master/README.md Fetches the stored value from a field as a Float. Must be invoked after readMultipleFields(). Not available on Arduino Uno due to memory constraints. ```Arduino float getFieldAsFloat (field) ``` -------------------------------- ### Get Last Read Status Source: https://github.com/mathworks/thingspeak-arduino/blob/master/README.md Retrieves the status code of the most recent read operation. Use this to diagnose issues with data retrieval. ```arduino int getLastReadStatus () ``` -------------------------------- ### Get Field Value as Int Source: https://github.com/mathworks/thingspeak-arduino/blob/master/README.md Fetches a stored value from a specific field as an Int data type. This function should be invoked after a successful call to readMultipleFields(). Not available on Arduino Uno due to memory constraints. ```arduino int getFieldAsInt (field) ``` -------------------------------- ### Get Field Value as Long Source: https://github.com/mathworks/thingspeak-arduino/blob/master/README.md Fetches a stored value from a specific field as a Long data type. This function should be invoked after a successful call to readMultipleFields(). Not available on Arduino Uno due to memory constraints. ```arduino long getFieldAsLong (field) ``` -------------------------------- ### begin Source: https://github.com/mathworks/thingspeak-arduino/blob/master/README.md Initializes the ThingSpeak library and network settings. It can be used for both secure and normal connections to ThingSpeak.com. ```APIDOC ## begin ### Description Initializes the ThingSpeak library and network settings, whether performing a secure connection or a normal connection to ThingSpeak. ### Method Signature ``` bool begin (client) ``` ### Parameters #### Path Parameters - **client** (Client &) - Required - TCPClient created earlier in the sketch ### Returns Always returns true. This does not validate the information passed in, or generate any calls to ThingSpeak. ``` -------------------------------- ### Initialize ThingSpeak Library Source: https://github.com/mathworks/thingspeak-arduino/blob/master/README.md Initializes the ThingSpeak library and network settings. Use this function at the beginning of your sketch. For secure connections, ensure TS_ENABLE_SSL is defined before including the library and pass an SSL-capable client. ```cpp bool begin (client) // defaults to ThingSpeak.com ``` -------------------------------- ### Read Created-At Timestamp (with API Key) Source: https://github.com/mathworks/thingspeak-arduino/blob/master/README.md Reads the created-at timestamp for the latest update to a channel. Include the readAPIKey to access private channels. ```Arduino String readCreatedAt (channelNumber, readAPIKey) ``` -------------------------------- ### Enable SSL for Secure Connection Source: https://github.com/mathworks/thingspeak-arduino/blob/master/README.md Enables SSL for a secure HTTPS connection to ThingSpeak. This macro must be defined before including the ThingSpeak library header. ```c++ #define TS_ENABLE_SSL ``` -------------------------------- ### Read Created-At Timestamp (without API Key) Source: https://github.com/mathworks/thingspeak-arduino/blob/master/README.md Reads the created-at timestamp for the latest update to a channel. This version is for public channels. ```Arduino String readCreatedAt (channelNumber) ``` -------------------------------- ### Read Multiple Fields (with API Key) Source: https://github.com/mathworks/thingspeak-arduino/blob/master/README.md Reads all the latest fields, status, location, and created-at timestamp for a channel. Include the readAPIKey to access private channels. Not available on Arduino Uno due to memory constraints. ```Arduino int readMultipleFields (channelNumber, readAPIKey) ``` -------------------------------- ### Secure Connection (HTTPS) Source: https://github.com/mathworks/thingspeak-arduino/blob/master/README.md Information on establishing a secure HTTPS connection to the ThingSpeak API, ensuring data confidentiality and authenticity. ```APIDOC ## Secure Connection ### Description Securely connect to the ThingSpeak API using HTTPS to ensure data confidentiality and authenticity. This is recommended for all interactions with the ThingSpeak service. ### HTTPS HTTPS provides both confidentiality (through SSL Encryption) and authenticity (verifying the server's identity). ### User Sketch Requirements To enable a secure connection, define the `TS_ENABLE_SSL` macro before including the `thingspeak.h` header. If this macro is not defined, the connection will default to insecure HTTP. #### Connection Scenarios based on `TS_ENABLE_SSL` and Client Capabilities: * **Case 1: `TS_ENABLE_SSL` defined + Client capable of SSL** = Secure HTTPS Connection. * **Case 2: `TS_ENABLE_SSL` defined + Client not capable of SSL** = Default HTTP connection with a warning message. * **Case 3: `TS_ENABLE_SSL` undefined + Client capable of SSL** = Error connecting to ThingSpeak (status code returned). * **Case 4: `TS_ENABLE_SSL` undefined + Client not capable of SSL** = HTTP connection. #### Confidentiality + Authenticity Authenticity is achieved through methods like Root Certificate Check or Certificate Fingerprint Check, which vary by client library. These checks should be performed before invoking the `begin()` function. Users are responsible for maintaining updated certificates due to their expiration dates. Refer to examples like `ReadMultipleFieldsSecure` for specific implementations on ESP8266 (Fingerprint Check) and ESP32 (Root Certificate Check). ``` -------------------------------- ### writeRaw Source: https://github.com/mathworks/thingspeak-arduino/blob/master/README.md Writes a raw POST message to a ThingSpeak channel using the provided channel number and write API key. ```APIDOC ## writeRaw ### Description Write a raw POST to a ThingSpeak channel. ### Method Signature ``` int writeRaw (channelNumber, postMessage, writeAPIKey) ``` ### Parameters #### Path Parameters - **channelNumber** (unsigned long) - Required - Channel number - **postMessage** (const char *, String) - Required - Raw URL to write to ThingSpeak. Refer to the [documentation](https://www.mathworks.com/help/thingspeak/channels-and-charts-api.html) - **writeAPIKey** (const char *) - Required - 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 Return Codes below for other possible return values. ``` -------------------------------- ### Read Raw Channel Response (with API Key) Source: https://github.com/mathworks/thingspeak-arduino/blob/master/README.md Reads a raw HTTP response from a channel. Include the readAPIKey to access private channels. ```Arduino String readRaw (channelNumber, URLSuffix, readAPIKey) ``` -------------------------------- ### Return Codes Source: https://github.com/mathworks/thingspeak-arduino/blob/master/README.md Provides a mapping of integer return codes to their corresponding meanings for read and write operations. ```APIDOC ## Return Codes ### Description This section details the possible integer return codes and their meanings for various operations within the ThingSpeak Arduino library. | Value | Meaning | |---|---| | 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) | | 0 | Other error | ``` -------------------------------- ### Read Multiple Fields (without API Key) Source: https://github.com/mathworks/thingspeak-arduino/blob/master/README.md Reads all the latest fields, status, location, and created-at timestamp for a channel. This version is for public channels. Not available on Arduino Uno due to memory constraints. ```Arduino int readMultipleFields (channelNumber) ``` -------------------------------- ### Write Multiple Fields to ThingSpeak Channel Source: https://github.com/mathworks/thingspeak-arduino/blob/master/README.md Writes multiple fields to a ThingSpeak channel after setting individual fields using a separate method (e.g., setField()). Requires channel number and write API key. Special characters are automatically encoded. ```cpp int writeFields (channelNumber, writeAPIKey) ``` -------------------------------- ### writeFields Source: https://github.com/mathworks/thingspeak-arduino/blob/master/README.md Writes multiple fields to a ThingSpeak channel. Fields to be written must be set using setField() prior to calling this method. ```APIDOC ## writeFields ### Description Write a multi-field update. Call setField() for each of the fields you want to write first. ### Method Signature ``` int writeFields (channelNumber, writeAPIKey) ``` ### Parameters #### Path Parameters - **channelNumber** (unsigned long) - Required - Channel number - **writeAPIKey** (const char *) - Required - 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 Return Codes below for other possible return values. ### Remarks Special characters will be automatically encoded by this method. See the note regarding special characters below. ``` -------------------------------- ### Write Raw POST Message to ThingSpeak Channel Source: https://github.com/mathworks/thingspeak-arduino/blob/master/README.md Sends a raw POST request to a ThingSpeak channel. This method is useful for advanced interactions or custom data formats. Requires channel number, the raw POST message (URL format), and the write API key. ```cpp int writeRaw (channelNumber, postMessage, writeAPIKey) ``` -------------------------------- ### Set created-at timestamp for an update Source: https://github.com/mathworks/thingspeak-arduino/blob/master/README.md Use `setCreatedAt` to specify a custom timestamp for a channel update. The timestamp must be in ISO 8601 format. UTC is assumed if no timezone offset is provided. ```c++ int setCreatedAt (createdAt) ``` -------------------------------- ### readCreatedAt Source: https://github.com/mathworks/thingspeak-arduino/blob/master/README.md Reads the created-at timestamp for the latest update to a channel. This function can be used for both public and private channels by providing the appropriate read API key. ```APIDOC ## readCreatedAt() ### Description Reads the created-at timestamp associated with the latest update to a channel. Include the readAPIKey to read a private channel. ### Method Signature `String readCreatedAt (channelNumber, readAPIKey)` `String readCreatedAt (channelNumber)` ### Parameters #### Path Parameters - **channelNumber** (unsigned long) - Description: Channel number - **readAPIKey** (const char *) - Description: Read API key associated with the channel. If you share code with others, do not share this key ### Returns Returns the created-at timestamp as a String. ``` -------------------------------- ### Read Raw Channel Response (without API Key) Source: https://github.com/mathworks/thingspeak-arduino/blob/master/README.md Reads a raw HTTP response from a channel. This version is for public channels. ```Arduino String readRaw (channelNumber, URLSuffix) ``` -------------------------------- ### Set latitude for a measurement Source: https://github.com/mathworks/thingspeak-arduino/blob/master/README.md Use `setLatitude` to record the latitude of a measurement in degrees. Positive values indicate North, and negative values indicate South. ```c++ int setLatitude (latitude) ``` -------------------------------- ### Set elevation for a measurement Source: https://github.com/mathworks/thingspeak-arduino/blob/master/README.md Use `setElevation` to specify the elevation of a measurement in meters above sea level. ```c++ int setElevation (elevation) ``` -------------------------------- ### setCreatedAt Source: https://github.com/mathworks/thingspeak-arduino/blob/master/README.md Sets the created-at timestamp for a multi-field update. The timestamp must be in ISO 8601 format. Timezones can be specified using an hour offset; otherwise, UTC is assumed. ```APIDOC ## setCreatedAt ### Description Set the created-at date of a multi-field update. The timestamp string must be in the ISO 8601 format. Example "2017-01-12 13:22:54" ### Method Signature ```c int setCreatedAt (createdAt) ``` ### Parameters #### Request Body * **createdAt** (String) - Required - Desired timestamp to be included with the channel update as a String. * **createdAt** (const char *) - Required - Desired timestamp to be included with the channel update as a character array (zero terminated). ### Returns HTTP status code of 200 if successful. See Return Codes below for other possible return values. ### Remarks Timezones can be set using the timezone hour offset parameter. For example, a timestamp for Eastern Standard Time is: "2017-01-12 13:22:54-05". If no timezone hour offset parameter is used, UTC time is assumed. ``` -------------------------------- ### setElevation Source: https://github.com/mathworks/thingspeak-arduino/blob/master/README.md Sets the elevation for a multi-field update. Elevation is measured in meters above sea level. ```APIDOC ## setElevation ### Description Set the elevation of a multi-field update. ### Method Signature ```c int setElevation (elevation) ``` ### Parameters #### Request Body * **elevation** (float) - Required - Elevation of the measurement (meters above sea level). ### Returns HTTP status code of 200 if successful. See Return Codes below for other possible return values. ``` -------------------------------- ### Read Status from ThingSpeak Channel Source: https://github.com/mathworks/thingspeak-arduino/blob/master/README.md Reads the latest status from a ThingSpeak channel as a String. Include the readAPIKey for private channels. ```c++ String readStatus (channelNumber, readAPIKey) ``` ```c++ String readStatus (channelNumber) ``` -------------------------------- ### readStatus Source: https://github.com/mathworks/thingspeak-arduino/blob/master/README.md Reads the latest status from a ThingSpeak channel. An optional read API key can be provided to access private channels. ```APIDOC ## readStatus ### Description Read the latest status from a channel. Include the readAPIKey to read a private channel. ### Method Signature ``` String readStatus (channelNumber, readAPIKey) ``` ``` String readStatus (channelNumber) ``` ### Parameters #### Path Parameters - **channelNumber** (unsigned long) - Channel number - **readAPIKey** (const char *) - Read API key associated with the channel. If you share code with others, do not share this key ### Returns Returns the status field as a String. ``` -------------------------------- ### Set status message for an update Source: https://github.com/mathworks/thingspeak-arduino/blob/master/README.md Use `setStatus` to include a status message with a channel update. The status is limited to 255 bytes and can be a String or character array. ```c++ int setStatus (status) ``` -------------------------------- ### readMultipleFields Source: https://github.com/mathworks/thingspeak-arduino/blob/master/README.md Reads all the latest fields, status, location, and created-at timestamp for a channel and stores them locally. This function can be used for private channels with a read API key. ```APIDOC ## readMultipleFields() ### Description Read all the latest fields, status, location, and created-at timestamp; and store these values locally. Use `getField` functions mentioned below to fetch the stored values. Include the readAPIKey to read a private channel. ### Method Signature `int readMultipleFields (channelNumber, readAPIKey)` `int readMultipleFields (channelNumber)` ### Parameters #### Path Parameters - **channelNumber** (unsigned long) - Description: Channel number - **readAPIKey** (const char *) - Description: Read 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 Return Codes below for other possible return values. ### Remarks This feature not available in Arduino Uno due to memory constraints. ``` -------------------------------- ### writeField Source: https://github.com/mathworks/thingspeak-arduino/blob/master/README.md Writes a value to a single field within a specified ThingSpeak channel using the provided write API key. ```APIDOC ## writeField ### Description Write a value to a single field in a ThingSpeak channel. ### Method Signature ``` int writeField(channelNumber, field, value, writeAPIKey) ``` ### Parameters #### Path Parameters - **channelNumber** (unsigned long) - Required - Channel number - **field** (unsigned int) - Required - Field number (1-8) within the channel to write to. - **value** (int, long, float, String, const char *) - Required - The value to write. Accepted types include integer, long, float, String, or character array. ThingSpeak limits String and character array fields to 255 bytes. - **writeAPIKey** (const char *) - Required - 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 Return Codes below for other possible return values. ### Remarks Special characters will be automatically encoded by this method. See the note regarding special characters below. ``` -------------------------------- ### Write to ThingSpeak Field with ESP8266 Source: https://github.com/mathworks/thingspeak-arduino/blob/master/README.md Use this snippet to write an incrementing number to a specific field in your ThingSpeak channel. Ensure you have included the necessary ThingSpeak and WiFi libraries and defined your network credentials and channel information in 'secrets.h'. ```cpp #include #include "secrets.h" #include "ThingSpeak.h" char ssid[] = SECRET_SSID; char pass[] = SECRET_PASS; int keyIndex = 0; WiFiClient client; unsigned long myChannelNumber = SECRET_CH_ID; const char * myWriteAPIKey = SECRET_WRITE_APIKEY; int number = 0; void setup() { Serial.begin(115200); while (!Serial) { ; } WiFi.mode(WIFI_STA); ThingSpeak.begin(client); } void loop() { if(WiFi.status() != WL_CONNECTED){ Serial.print("Attempting to connect to SSID: "); Serial.println(SECRET_SSID); while(WiFi.status() != WL_CONNECTED){ WiFi.begin(ssid, pass); Serial.print("."); delay(5000); } Serial.println("\nConnected."); } int x = ThingSpeak.writeField(myChannelNumber, 1, number, myWriteAPIKey); if(x == 200){ Serial.println("Channel update successful."); } else{ Serial.println("Problem updating channel. HTTP error code " + String(x)); } number++; if(number > 99){ number = 0; } delay(20000); } ``` -------------------------------- ### setStatus Source: https://github.com/mathworks/thingspeak-arduino/blob/master/README.md Sets the status message for a multi-field update. The status string is limited to 255 bytes. ```APIDOC ## setStatus ### Description Set the status of a multi-field update. Use status to provide additional details when writing a channel update. ### Method Signature ```c int setStatus (status) ``` ### Parameters #### Request Body * **status** (const char *) - Required - String to write (UTF8). ThingSpeak limits this to 255 bytes. * **status** (String) - Required - const character array (zero terminated). ThingSpeak limits this to 255 bytes. ### Returns HTTP status code of 200 if successful. See Return Codes below for other possible return values. ``` -------------------------------- ### setField Source: https://github.com/mathworks/thingspeak-arduino/blob/master/README.md Sets the value of a specific field within a channel for a multi-field update. Supports integer, long, float, and string values. Note that ThingSpeak limits string fields to 255 bytes. ```APIDOC ## setField ### Description Set the value of a single field that will be part of a multi-field update. ### Method Signature ```c int setField (field, value) ``` ### Parameters #### Path Parameters * **field** (unsigned int) - Required - Field number (1-8) within the channel to set. #### Request Body * **value** (int) - Required - Integer value (from -32,768 to 32,767) to write. * **value** (long) - Required - Long value (from -2,147,483,648 to 2,147,483,647) to write. * **value** (float) - Required - Floating point value (from -999999000000 to 999999000000) to write. * **value** (String) - Required - String to write (UTF8 string). ThingSpeak limits this field to 255 bytes. * **value** (const char *) - Required - Character array (zero terminated) to write (UTF8). ThingSpeak limits this field to 255 bytes. ### Returns HTTP status code of 200 if successful. See Return Codes below for other possible return values. ``` -------------------------------- ### readRaw Source: https://github.com/mathworks/thingspeak-arduino/blob/master/README.md Reads a raw HTTP response from a specified URL suffix for a given channel. This function is useful for fetching data in its raw format and can access private channels with a read API key. ```APIDOC ## readRaw() ### Description Read a raw response from a channel. Include the readAPIKey to read a private channel. ### Method Signature `String readRaw (channelNumber, URLSuffix, readAPIKey)` `String readRaw (channelNumber, URLSuffix)` ### Parameters #### Path Parameters - **channelNumber** (unsigned long) - Description: Channel number - **URLSuffix** (String) - Description: Raw URL to write to ThingSpeak as a String. See the documentation at https://thingspeak.com/docs/channels#get_feed - **readAPIKey** (const char *) - Description: Read API key associated with the channel. If you share code with others, do not share this key. ### Returns Returns the raw response from a HTTP request as a String. ``` -------------------------------- ### Write Single Field to ThingSpeak Channel Source: https://github.com/mathworks/thingspeak-arduino/blob/master/README.md Writes an integer, long, float, string, or character array value to a specific field in a ThingSpeak channel. Special characters are automatically encoded. Requires channel number, field number, value, and write API key. ```cpp int writeField(channelNumber, field, value, writeAPIKey) ``` -------------------------------- ### getFieldAsString Source: https://github.com/mathworks/thingspeak-arduino/blob/master/README.md Fetches a stored field value as a String after `readMultipleFields` has been invoked. This function retrieves data from a specific field within the channel. ```APIDOC ## getFieldAsString() ### Description Fetch the stored value from a field as String. Invoke this after invoking `readMultipleFields`. ### Method Signature `String getFieldAsString (field)` ### Parameters #### Path Parameters - **field** (unsigned int) - Description: Field number (1-8) within the channel to read from. ### Returns Value read (UTF8 string), empty string if there is an error, or old value read (UTF8 string) if invoked before readMultipleFields(). Use getLastReadStatus() to get more specific information. ### Remarks This feature not available in Arduino Uno due to memory constraints. ``` -------------------------------- ### getFieldAsInt Source: https://github.com/mathworks/thingspeak-arduino/blob/master/README.md Fetches the stored value from a specified field as an Integer data type. This method should be invoked after a successful call to readMultipleFields(). ```APIDOC ## getFieldAsInt ### Description Fetch the stored value from a field as Int. Invoke this after invoking `readMultipleFields`. ### Signature ```int getFieldAsInt (field)``` ### Parameters #### Path Parameters - **field** (unsigned int) - Required - Field number (1-8) within the channel to read from. ### Returns Value read as Int. Returns 0 if the field contains text or if an error occurred. If invoked before `readMultipleFields()`, it returns the previously read value. Use `getLastReadStatus()` for more specific error information. ### Remarks This feature is not available in Arduino Uno due to memory constraints. ``` -------------------------------- ### Read String Field from ThingSpeak Channel Source: https://github.com/mathworks/thingspeak-arduino/blob/master/README.md Reads the latest string value from a specified field in a ThingSpeak channel. Include the readAPIKey for private channels. ```c++ String readStringField (channelNumber, field, readAPIKey) ``` ```c++ String readStringField (channelNumber, field) ``` -------------------------------- ### getLastReadStatus Source: https://github.com/mathworks/thingspeak-arduino/blob/master/README.md Retrieves the status code of the most recent read operation. ```APIDOC ## getLastReadStatus ### Description Get the status of the previous read. ### Signature ```int getLastReadStatus () ``` ### Returns An integer representing the status of the previous read operation. Refer to the 'Return Codes' section for a detailed explanation of possible values. ``` -------------------------------- ### readIntField Source: https://github.com/mathworks/thingspeak-arduino/blob/master/README.md Reads the latest integer value from a specified field in a ThingSpeak channel. An optional read API key can be provided to access private channels. ```APIDOC ## readIntField ### Description Read the latest int from a channel. Include the readAPIKey to read a private channel. ### Method Signature ``` int readIntField (channelNumber, field, readAPIKey) ``` ``` int readIntField (channelNumber, field) ``` ### Parameters #### Path Parameters - **channelNumber** (unsigned long) - Channel number - **field** (unsigned int) - Field number (1-8) within the channel to read from. - **readAPIKey** (const char *) - 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. If the value returned is out of range for an int, the result is undefined. ``` -------------------------------- ### getFieldAsFloat Source: https://github.com/mathworks/thingspeak-arduino/blob/master/README.md Fetches a stored field value as a Float after `readMultipleFields` has been invoked. This function retrieves numerical data from a specific field. ```APIDOC ## getFieldAsFloat() ### Description Fetch the stored value from a field as Float. Invoke this after invoking `readMultipleFields`. ### Method Signature `float getFieldAsFloat (field)` ### Parameters #### Path Parameters - **field** (unsigned int) - Description: Field number (1-8) within the channel to read from. ### Returns Value read, 0 if the field is text or there is an error, or old value read if invoked before readMultipleFields(). Use getLastReadStatus() to get more specific information. Note that NAN, INFINITY, and -INFINITY are valid results. ### Remarks This feature not available in Arduino Uno due to memory constraints. ``` -------------------------------- ### setLatitude Source: https://github.com/mathworks/thingspeak-arduino/blob/master/README.md Sets the latitude for a multi-field update. Latitude is measured in degrees, with negative values indicating degrees South. ```APIDOC ## setLatitude ### Description Set the latitude of a multi-field update. ### Method Signature ```c int setLatitude (latitude) ``` ### Parameters #### Request Body * **latitude** (float) - Required - Latitude of the measurement (degrees N, use negative values for degrees S). ### Returns HTTP status code of 200 if successful. See Return Codes below for other possible return values. ``` -------------------------------- ### Read Integer Field from ThingSpeak Channel Source: https://github.com/mathworks/thingspeak-arduino/blob/master/README.md Reads the latest integer value from a specified field in a ThingSpeak channel. Include the readAPIKey for private channels. Returns 0 if the field is text or an error occurs. ```c++ int readIntField (channelNumber, field, readAPIKey) ``` ```c++ int readIntField (channelNumber, field) ``` -------------------------------- ### readFloatField Source: https://github.com/mathworks/thingspeak-arduino/blob/master/README.md Reads the latest float value from a specified field in a ThingSpeak channel. An optional read API key can be provided to access private channels. ```APIDOC ## readFloatField ### Description Read the latest float from a channel. Include the readAPIKey to read a private channel. ### Method Signature ``` float readFloatField (channelNumber, field, readAPIKey) ``` ``` float readFloatField (channelNumber, field) ``` ### Parameters #### Path Parameters - **channelNumber** (unsigned long) - Channel number - **field** (unsigned int) - Field number (1-8) within the channel to read from. - **readAPIKey** (const char *) - 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. ``` -------------------------------- ### Read Float Field from ThingSpeak Channel Source: https://github.com/mathworks/thingspeak-arduino/blob/master/README.md Reads the latest float value from a specified field in a ThingSpeak channel. Include the readAPIKey for private channels. Returns 0 if the field is text or an error occurs. ```c++ float readFloatField (channelNumber, field, readAPIKey) ``` ```c++ float readFloatField (channelNumber, field) ``` -------------------------------- ### Set longitude for a measurement Source: https://github.com/mathworks/thingspeak-arduino/blob/master/README.md Use `setLongitude` to record the longitude of a measurement in degrees. Positive values indicate East, and negative values indicate West. ```c++ int setLongitude (longitude) ``` -------------------------------- ### Set a single field value Source: https://github.com/mathworks/thingspeak-arduino/blob/master/README.md Use `setField` to specify the value for a particular field in a multi-field update. Supports integer, long, float, string, and character array types. ```c++ int setField (field, value) ``` -------------------------------- ### readStringField Source: https://github.com/mathworks/thingspeak-arduino/blob/master/README.md Reads the latest string value from a specified field in a ThingSpeak channel. An optional read API key can be provided to access private channels. ```APIDOC ## readStringField ### Description Read the latest string from a channel. Include the readAPIKey to read a private channel. ### Method Signature ``` String readStringField (channelNumber, field, readAPIKey) ``` ``` String readStringField (channelNumber, field) ``` ### Parameters #### Path Parameters - **channelNumber** (unsigned long) - Channel number - **field** (unsigned int) - Field number (1-8) within the channel to read from. - **readAPIKey** (const char *) - 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. ``` -------------------------------- ### setLongitude Source: https://github.com/mathworks/thingspeak-arduino/blob/master/README.md Sets the longitude for a multi-field update. Longitude is measured in degrees, with negative values indicating degrees West. ```APIDOC ## setLongitude ### Description Set the longitude of a multi-field update. ### Method Signature ```c int setLongitude (longitude) ``` ### Parameters #### Request Body * **longitude** (float) - Required - Longitude of the measurement (degrees E, use negative values for degrees W). ### Returns HTTP status code of 200 if successful. See Return Codes below for other possible return values. ``` -------------------------------- ### Read Long Field from ThingSpeak Channel Source: https://github.com/mathworks/thingspeak-arduino/blob/master/README.md Reads the latest long integer value from a specified field in a ThingSpeak channel. Include the readAPIKey for private channels. Returns 0 if the field is text or an error occurs. ```c++ long readLongField (channelNumber, field, readAPIKey) ``` ```c++ long readLongField (channelNumber, field) ``` -------------------------------- ### readLongField Source: https://github.com/mathworks/thingspeak-arduino/blob/master/README.md Reads the latest long integer value from a specified field in a ThingSpeak channel. An optional read API key can be provided to access private channels. ```APIDOC ## readLongField ### Description Read the latest long from a channel. Include the readAPIKey to read a private channel. ### Method Signature ``` long readLongField (channelNumber, field, readAPIKey) ``` ``` long readLongField (channelNumber, field) ``` ### Parameters #### Path Parameters - **channelNumber** (unsigned long) - Channel number - **field** (unsigned int) - Field number (1-8) within the channel to read from. - **readAPIKey** (const char *) - 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. ``` -------------------------------- ### getFieldAsLong Source: https://github.com/mathworks/thingspeak-arduino/blob/master/README.md Fetches the stored value from a specified field as a Long data type. This method should be invoked after a successful call to readMultipleFields(). ```APIDOC ## getFieldAsLong ### Description Fetch the stored value from a field as Long. Invoke this after invoking `readMultipleFields`. ### Signature ```long getFieldAsLong (field)``` ### Parameters #### Path Parameters - **field** (unsigned int) - Required - Field number (1-8) within the channel to read from. ### Returns Value read as Long. Returns 0 if the field contains text or if an error occurred. If invoked before `readMultipleFields()`, it returns the previously read value. Use `getLastReadStatus()` for more specific error information. ### Remarks This feature is not available in Arduino Uno due to memory constraints. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.