diff --git a/examples/CheerLights/CheerLights.ino b/examples/CheerLights/CheerLights.ino index 7bd3cd9..e4772fe 100644 --- a/examples/CheerLights/CheerLights.ino +++ b/examples/CheerLights/CheerLights.ino @@ -5,72 +5,64 @@ On Spark core, the built in RGB LED is used Visit http://www.cheerlights.com for more info. - ThingSpeak ( https://www.thingspeak.com ) is a free IoT service for prototyping - systems that collect, analyze, and react to their environments. + ThingSpeak ( https://www.thingspeak.com ) is an analytic IoT platform service that allows you to aggregate, visualize and + analyze live data streams in the cloud. - Copyright 2015, The MathWorks, Inc. + Copyright 2016, The MathWorks, Inc. Documentation for the ThingSpeak Communication Library for Arduino is in the extras/documentation folder where the library was installed. See the accompaning licence file for licensing information. */ -#ifdef SPARK - #include "ThingSpeak/ThingSpeak.h" -#else - #include "ThingSpeak.h" -#endif +#include "ThingSpeak.h" + // *********************************************************************************************************** // This example selects the correct library to use based on the board selected under the Tools menu in the IDE. -// Yun, Wired Ethernet shield, wi-fi shield, esp8266, and Spark are all supported. -// With Uno and Mega, the default is that you're using a wired ethernet shield (http://www.arduino.cc/en/Main/ArduinoEthernetShield) -// If you're using a wi-fi shield (http://www.arduino.cc/en/Main/ArduinoWiFiShield), uncomment the line below +// Yun, Ethernet shield, WiFi101 shield, esp8266, and MXR1000 are all supported. +// With Yun, the default is that you're using the Ethernet connection. +// If you're using a wi-fi 101 or ethernet shield (http://www.arduino.cc/en/Main/ArduinoWiFiShield), uncomment the corresponding line below // *********************************************************************************************************** -//#define USE_WIFI_SHIELD + +//#define USE_WIFI101_SHIELD +//#define USE_ETHERNET_SHIELD + +#if !defined(USE_WIFI101_SHIELD) && !defined(USE_ETHERNET_SHIELD) && !defined(ARDUINO_SAMD_MKR1000) && !defined(ARDUINO_AVR_YUN) && !defined(ARDUINO_ARCH_ESP8266) + #error "Uncomment the #define for either USE_WIFI101_SHIELD or USE_ETHERNET_SHIELD" +#endif + // Make sure that you put a 330 ohm resistor between the arduino // pins and each of the color pins on the LED. int pinRed = 9; int pinGreen = 6; -int pinBlue = 5; +int pinBlue = 3; -#ifdef ARDUINO_ARCH_AVR - #ifdef ARDUINO_AVR_YUN +#if defined(ARDUINO_AVR_YUN) #include "YunClient.h" YunClient client; - #else - - #ifdef USE_WIFI_SHIELD - #include - // ESP8266 USERS -- YOU MUST COMMENT OUT THE LINE BELOW. There's a bug in the Arduino IDE that causes it to not respect #ifdef when it comes to #includes - // If you get "multiple definition of `WiFi'" -- comment out the line below. - #include - char ssid[] = ""; // your network SSID (name) - char pass[] = ""; // your network password - int status = WL_IDLE_STATUS; - WiFiClient client; +#else + #if defined(USE_WIFI101_SHIELD) || defined(ARDUINO_SAMD_MKR1000) || defined(ARDUINO_ARCH_ESP8266) + // Use WiFi + #ifdef ARDUINO_ARCH_ESP8266 + #include #else - // Use wired ethernet shield #include - #include - byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; - EthernetClient client; + #include #endif + char ssid[] = ""; // your network SSID (name) + char pass[] = ""; // your network password + int status = WL_IDLE_STATUS; + WiFiClient client; + #elif defined(USE_ETHERNET_SHIELD) + // Use wired ethernet shield + #include + #include + byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; + EthernetClient client; #endif #endif -#ifdef ARDUINO_ARCH_ESP8266 - #include - char ssid[] = ""; // your network SSID (name) - char pass[] = ""; // your network password - int status = WL_IDLE_STATUS; - WiFiClient client; -#endif - -#ifdef SPARK - TCPClient client; -#endif - /* This is the ThingSpeak channel number for CheerLights @@ -80,32 +72,29 @@ int pinBlue = 5; unsigned long cheerLightsChannelNumber = 1417; void setup() { - #if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_ESP8266) - #ifdef ARDUINO_AVR_YUN - Bridge.begin(); + + #ifdef ARDUINO_AVR_YUN + Bridge.begin(); + #else + #if defined(ARDUINO_ARCH_ESP8266) || defined(USE_WIFI101_SHIELD) || defined(ARDUINO_SAMD_MKR1000) + WiFi.begin(ssid, pass); #else - #if defined(USE_WIFI_SHIELD) || defined(ARDUINO_ARCH_ESP8266) - WiFi.begin(ssid, pass); - #else - Ethernet.begin(mac); - #endif + Ethernet.begin(mac); #endif #endif ThingSpeak.begin(client); - #if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_ESP8266) - pinMode(pinRed,OUTPUT); - pinMode(pinGreen,OUTPUT); - pinMode(pinBlue,OUTPUT); - #endif + pinMode(pinRed,OUTPUT); + pinMode(pinGreen,OUTPUT); + pinMode(pinBlue,OUTPUT); } void loop() { // Read the latest value from field 1 of channel 1417 String color = ThingSpeak.readStringField(cheerLightsChannelNumber, 1); setColor(color); - + // Check again in 5 seconds delay(5000); } @@ -137,16 +126,12 @@ void setColor(String color) { // When it matches, look up the RGB values for that color in the table, // and write the red, green, and blue values. - #if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_ESP8266) - analogWrite(pinRed,colorRGB[iColor][0]); - analogWrite(pinGreen,colorRGB[iColor][1]); - analogWrite(pinBlue,colorRGB[iColor][2]); - #endif - #ifdef SPARK - RGB.control(true); - RGB.color(colorRGB[iColor][0], colorRGB[iColor][1], colorRGB[iColor][2]); - #endif + + analogWrite(pinRed,colorRGB[iColor][0]); + analogWrite(pinGreen,colorRGB[iColor][1]); + analogWrite(pinBlue,colorRGB[iColor][2]); + return; } } -} +} diff --git a/examples/ReadLastTemperature/ReadLastTemperature.ino b/examples/ReadLastTemperature/ReadLastTemperature.ino index 8cbbe2e..d7825f1 100644 --- a/examples/ReadLastTemperature/ReadLastTemperature.ino +++ b/examples/ReadLastTemperature/ReadLastTemperature.ino @@ -5,8 +5,8 @@ https://thingspeak.com/channels/12397 on ThingSpeak, and prints to the serial port debug window every 30 seconds. - ThingSpeak ( https://www.thingspeak.com ) is a free IoT service for building - systems that collect, analyze, and react to their environments. + ThingSpeak ( https://www.thingspeak.com ) is an analytic IoT platform service that allows you to aggregate, visualize and + analyze live data streams in the cloud. Copyright 2016, The MathWorks, Inc. @@ -14,58 +14,50 @@ See the accompaning licence file for licensing information. */ -#ifdef SPARK - #include "ThingSpeak/ThingSpeak.h" -#else - #include "ThingSpeak.h" -#endif +#include "ThingSpeak.h" + // *********************************************************************************************************** // This example selects the correct library to use based on the board selected under the Tools menu in the IDE. -// Yun, Wired Ethernet shield, wi-fi shield, esp8266, and Spark are all supported. -// With Uno and Mega, the default is that you're using a wired ethernet shield (http://www.arduino.cc/en/Main/ArduinoEthernetShield) -// If you're using a wi-fi shield (http://www.arduino.cc/en/Main/ArduinoWiFiShield), uncomment the line below +// Yun, Ethernet shield, WiFi101 shield, esp8266, and MXR1000 are all supported. +// With Yun, the default is that you're using the Ethernet connection. +// If you're using a wi-fi 101 or ethernet shield (http://www.arduino.cc/en/Main/ArduinoWiFiShield), uncomment the corresponding line below // *********************************************************************************************************** -//#define USE_WIFI_SHIELD -#ifdef ARDUINO_ARCH_AVR - #ifdef ARDUINO_AVR_YUN +//#define USE_WIFI101_SHIELD +//#define USE_ETHERNET_SHIELD + + +#if !defined(USE_WIFI101_SHIELD) && !defined(USE_ETHERNET_SHIELD) && !defined(ARDUINO_SAMD_MKR1000) && !defined(ARDUINO_AVR_YUN) && !defined(ARDUINO_ARCH_ESP8266) + #error "Uncomment the #define for either USE_WIFI101_SHIELD or USE_ETHERNET_SHIELD" +#endif + + +#if defined(ARDUINO_AVR_YUN) #include "YunClient.h" YunClient client; - #else - - #ifdef USE_WIFI_SHIELD - #include - // ESP8266 USERS -- YOU MUST COMMENT OUT THE LINE BELOW. There's a bug in the Arduino IDE that causes it to not respect #ifdef when it comes to #includes - // If you get "multiple definition of `WiFi'" -- comment out the line below. - #include - char ssid[] = ""; // your network SSID (name) - char pass[] = ""; // your network password - int status = WL_IDLE_STATUS; - WiFiClient client; +#else + #if defined(USE_WIFI101_SHIELD) || defined(ARDUINO_SAMD_MKR1000) || defined(ARDUINO_ARCH_ESP8266) + // Use WiFi + #ifdef ARDUINO_ARCH_ESP8266 + #include #else - // Use wired ethernet shield #include - #include - byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; - EthernetClient client; + #include #endif + char ssid[] = ""; // your network SSID (name) + char pass[] = ""; // your network password + int status = WL_IDLE_STATUS; + WiFiClient client; + #elif defined(USE_ETHERNET_SHIELD) + // Use wired ethernet shield + #include + #include + byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; + EthernetClient client; #endif #endif -#ifdef ARDUINO_ARCH_ESP8266 - #include - char ssid[] = ""; // your network SSID (name) - char pass[] = ""; // your network password - int status = WL_IDLE_STATUS; - WiFiClient client; -#endif - -// On Particle Core, Photon, and Electron the results are published to the Particle dashboard using events. -// Go to http://dashboard.particle.io, click on the logs tab, and you'll see the events coming in. -#ifdef SPARK - TCPClient client; -#endif /* This is the ThingSpeak channel number for the MathwWorks weather station @@ -79,33 +71,34 @@ unsigned long weatherStationChannelNumber = 12397; unsigned int temperatureFieldNumber = 4; void setup() { - #if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_ESP8266) - Serial.begin(9600); - #ifdef ARDUINO_AVR_YUN - Bridge.begin(); + + Serial.begin(9600); + #ifdef ARDUINO_AVR_YUN + Bridge.begin(); + #else + #if defined(ARDUINO_ARCH_ESP8266) || defined(USE_WIFI101_SHIELD) || defined(ARDUINO_SAMD_MKR1000) + WiFi.begin(ssid, pass); #else - #if defined(USE_WIFI_SHIELD) || defined(ARDUINO_ARCH_ESP8266) - WiFi.begin(ssid, pass); - #else - Ethernet.begin(mac); - #endif - #endif + Ethernet.begin(mac); + #endif #endif - + ThingSpeak.begin(client); - + } void loop() { // Read the latest value from field 4 of channel 12397 float temperatureInF = ThingSpeak.readFloatField(weatherStationChannelNumber, temperatureFieldNumber); - #if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_ESP8266) - Serial.print("Current temp is: "); - Serial.print(temperatureInF); - Serial.println(" degrees F"); - #endif - #ifdef SPARK - Particle.publish("thingspeak-lasttemp", String::format("Current temp %.1f degrees F",temperatureInF),60,PRIVATE); - #endif + + Serial.print("Current temp is: "); + Serial.print(temperatureInF); + Serial.println(" degrees F"); + delay(30000); // Note that the weather station only updates once a minute } + + + + + diff --git a/examples/ReadPrivateChannel/ReadPrivateChannel.ino b/examples/ReadPrivateChannel/ReadPrivateChannel.ino index 5c266a7..f1c9c17 100644 --- a/examples/ReadPrivateChannel/ReadPrivateChannel.ino +++ b/examples/ReadPrivateChannel/ReadPrivateChannel.ino @@ -6,8 +6,8 @@ For an example of how to read from a public channel, see ReadChannel example - ThingSpeak ( https://www.thingspeak.com ) is a free IoT service for prototyping - systems that collect, analyze, and react to their environments. + ThingSpeak ( https://www.thingspeak.com ) is an analytic IoT platform service that allows you to aggregate, visualize and + analyze live data streams in the cloud. Copyright 2016, The MathWorks, Inc. @@ -15,58 +15,47 @@ See the accompaning licence file for licensing information. */ -#ifdef SPARK - #include "ThingSpeak/ThingSpeak.h" -#else - #include "ThingSpeak.h" -#endif +#include "ThingSpeak.h" + // *********************************************************************************************************** // This example selects the correct library to use based on the board selected under the Tools menu in the IDE. -// Yun, Wired Ethernet shield, wi-fi shield, esp8266, and Spark are all supported. -// With Uno and Mega, the default is that you're using a wired ethernet shield (http://www.arduino.cc/en/Main/ArduinoEthernetShield) -// If you're using a wi-fi shield (http://www.arduino.cc/en/Main/ArduinoWiFiShield), uncomment the line below +// Yun, Ethernet shield, WiFi101 shield, esp8266, and MXR1000 are all supported. +// With Yun, the default is that you're using the Ethernet connection. +// If you're using a wi-fi 101 or ethernet shield (http://www.arduino.cc/en/Main/ArduinoWiFiShield), uncomment the corresponding line below // *********************************************************************************************************** -//#define USE_WIFI_SHIELD -#ifdef ARDUINO_ARCH_AVR +//#define USE_WIFI101_SHIELD +//#define USE_ETHERNET_SHIELD - #ifdef ARDUINO_AVR_YUN +#if !defined(USE_WIFI101_SHIELD) && !defined(USE_ETHERNET_SHIELD) && !defined(ARDUINO_SAMD_MKR1000) && !defined(ARDUINO_AVR_YUN) && !defined(ARDUINO_ARCH_ESP8266) + #error "Uncomment the #define for either USE_WIFI101_SHIELD or USE_ETHERNET_SHIELD" +#endif + +#if defined(ARDUINO_AVR_YUN) #include "YunClient.h" YunClient client; - #else - - #ifdef USE_WIFI_SHIELD - #include - // ESP8266 USERS -- YOU MUST COMMENT OUT THE LINE BELOW. There's a bug in the Arduino IDE that causes it to not respect #ifdef when it comes to #includes - // If you get "multiple definition of `WiFi'" -- comment out the line below. - #include - char ssid[] = ""; // your network SSID (name) - char pass[] = ""; // your network password - int status = WL_IDLE_STATUS; - WiFiClient client; +#else + #if defined(USE_WIFI101_SHIELD) || defined(ARDUINO_SAMD_MKR1000) || defined(ARDUINO_ARCH_ESP8266) + // Use WiFi + #ifdef ARDUINO_ARCH_ESP8266 + #include #else - // Use wired ethernet shield #include - #include - byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; - EthernetClient client; + #include #endif + char ssid[] = ""; // your network SSID (name) + char pass[] = ""; // your network password + int status = WL_IDLE_STATUS; + WiFiClient client; + #elif defined(USE_ETHERNET_SHIELD) + // Use wired ethernet shield + #include + #include + byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; + EthernetClient client; #endif #endif -#ifdef ARDUINO_ARCH_ESP8266 - #include - char ssid[] = ""; // your network SSID (name) - char pass[] = ""; // your network password - int status = WL_IDLE_STATUS; - WiFiClient client; -#endif - -// Particle Core, Photon, and Electron the results are published to the Particle dashboard using events. -// Go to http://dashboard.particle.io, click on the logs tab, and you'll see the events coming in. -#ifdef SPARK - TCPClient client; -#endif /* ***************************************************************************************** @@ -83,16 +72,15 @@ unsigned long myChannelNumber = 31461; const char * myReadAPIKey = "NKX4Z5JGO4M5I18A"; void setup() { - #if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_ESP8266) - Serial.begin(9600); - #ifdef ARDUINO_AVR_YUN - Bridge.begin(); + + Serial.begin(9600); + #ifdef ARDUINO_AVR_YUN + Bridge.begin(); + #else + #if defined(ARDUINO_ARCH_ESP8266) || defined(USE_WIFI101_SHIELD) || defined(ARDUINO_SAMD_MKR1000) + WiFi.begin(ssid, pass); #else - #if defined(USE_WIFI_SHIELD) || defined(ARDUINO_ARCH_ESP8266) - WiFi.begin(ssid, pass); - #else - Ethernet.begin(mac); - #endif + Ethernet.begin(mac); #endif #endif @@ -102,13 +90,10 @@ void setup() { void loop() { // Read the latest value from field 1 of channel 31461 float voltage = ThingSpeak.readFloatField(myChannelNumber, 1, myReadAPIKey); - #if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_ESP8266) - Serial.print("Latest voltage is: "); - Serial.print(voltage); - Serial.println("V"); - #endif - #ifdef SPARK - Particle.publish("thingspeak-readvoltage", "Latest voltage is: " + String(voltage) + "V",60,PRIVATE); - #endif + + Serial.print("Latest voltage is: "); + Serial.print(voltage); + Serial.println("V"); + delay(30000); -} +} diff --git a/examples/ReadWeatherStation/ReadWeatherStation.ino b/examples/ReadWeatherStation/ReadWeatherStation.ino index db6b9cd..0175af6 100644 --- a/examples/ReadWeatherStation/ReadWeatherStation.ino +++ b/examples/ReadWeatherStation/ReadWeatherStation.ino @@ -4,8 +4,8 @@ Reads the latest weather data every 60 seconds from the public MathWorks weather station in Natick, MA https://thingspeak.com/channels/12397 on ThingSpeak. - ThingSpeak ( https://www.thingspeak.com ) is a free IoT service for prototyping - systems that collect, analyze, and react to their environments. + ThingSpeak ( https://www.thingspeak.com ) is an analytic IoT platform service that allows you to aggregate, visualize and + analyze live data streams in the cloud. Copyright 2016, The MathWorks, Inc. @@ -13,58 +13,49 @@ See the accompaning licence file for licensing information. */ -#ifdef SPARK - #include "ThingSpeak/ThingSpeak.h" -#else - #include "ThingSpeak.h" -#endif +#include "ThingSpeak.h" -/// *********************************************************************************************************** +// *********************************************************************************************************** // This example selects the correct library to use based on the board selected under the Tools menu in the IDE. -// Yun, Wired Ethernet shield, wi-fi shield, esp8266, and Spark are all supported. -// With Uno and Mega, the default is that you're using a wired ethernet shield (http://www.arduino.cc/en/Main/ArduinoEthernetShield) -// If you're using a wi-fi shield (http://www.arduino.cc/en/Main/ArduinoWiFiShield), uncomment the line below +// Yun, Ethernet shield, WiFi101 shield, esp8266, and MXR1000 are all supported. +// With Yun, the default is that you're using the Ethernet connection. +// If you're using a wi-fi 101 or ethernet shield (http://www.arduino.cc/en/Main/ArduinoWiFiShield), uncomment the corresponding line below // *********************************************************************************************************** -//#define USE_WIFI_SHIELD -#ifdef ARDUINO_ARCH_AVR - #ifdef ARDUINO_AVR_YUN +//#define USE_WIFI101_SHIELD +//#define USE_ETHERNET_SHIELD + + +#if !defined(USE_WIFI101_SHIELD) && !defined(USE_ETHERNET_SHIELD) && !defined(ARDUINO_SAMD_MKR1000) && !defined(ARDUINO_AVR_YUN) && !defined(ARDUINO_ARCH_ESP8266) + #error "Uncomment the #define for either USE_WIFI101_SHIELD or USE_ETHERNET_SHIELD" +#endif + + +#if defined(ARDUINO_AVR_YUN) #include "YunClient.h" YunClient client; - #else - - #ifdef USE_WIFI_SHIELD - #include - // ESP8266 USERS -- YOU MUST COMMENT OUT THE LINE BELOW. There's a bug in the Arduino IDE that causes it to not respect #ifdef when it comes to #includes - // If you get "multiple definition of `WiFi'" -- comment out the line below. - #include - char ssid[] = ""; // your network SSID (name) - char pass[] = ""; // your network password - int status = WL_IDLE_STATUS; - WiFiClient client; +#else + #if defined(USE_WIFI101_SHIELD) || defined(ARDUINO_SAMD_MKR1000) || defined(ARDUINO_ARCH_ESP8266) + // Use WiFi + #ifdef ARDUINO_ARCH_ESP8266 + #include #else - // Use wired ethernet shield #include - #include - byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; - EthernetClient client; + #include #endif + char ssid[] = ""; // your network SSID (name) + char pass[] = ""; // your network password + int status = WL_IDLE_STATUS; + WiFiClient client; + #elif defined(USE_ETHERNET_SHIELD) + // Use wired ethernet shield + #include + #include + byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; + EthernetClient client; #endif #endif -#ifdef ARDUINO_ARCH_ESP8266 - #include - char ssid[] = ""; // your network SSID (name) - char pass[] = ""; // your network password - int status = WL_IDLE_STATUS; - WiFiClient client; -#endif - -// On Particle Core, Photon, and Electron the results are published to the Particle dashboard using events. -// Go to http://dashboard.particle.io, click on the logs tab, and you'll see the events coming in. -#ifdef SPARK - TCPClient client; -#endif /* This is the ThingSpeak channel number for the MathwWorks weather station @@ -80,16 +71,15 @@ unsigned long weatherStationChannelNumber = 12397; void setup() { - #if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_ESP8266) - Serial.begin(9600); - #ifdef ARDUINO_AVR_YUN - Bridge.begin(); + + Serial.begin(9600); + #ifdef ARDUINO_AVR_YUN + Bridge.begin(); + #else + #if defined(ARDUINO_ARCH_ESP8266) || defined(USE_WIFI101_SHIELD) || defined(ARDUINO_SAMD_MKR1000) + WiFi.begin(ssid, pass); #else - #if defined(USE_WIFI_SHIELD) || defined(ARDUINO_ARCH_ESP8266) - WiFi.begin(ssid, pass); - #else - Ethernet.begin(mac); - #endif + Ethernet.begin(mac); #endif #endif @@ -104,41 +94,26 @@ void loop() { float rainfall = ThingSpeak.readFloatField(weatherStationChannelNumber,5); float pressure = ThingSpeak.readFloatField(weatherStationChannelNumber,6); - #if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_ESP8266) - Serial.println("======================================"); - Serial.println("Current weather conditions in Natick: "); - Serial.print(temperature); - Serial.print(" degrees F, "); - Serial.print(humidity); - Serial.println("% humidity"); - Serial.print("Wind at "); - Serial.print(windSpeed); - Serial.print(" MPH at "); - Serial.print(windDirection); - Serial.println(" degrees"); - Serial.print("Pressure is "); - Serial.print(pressure); - Serial.print(" inHg"); - if(rainfall > 0) - { - Serial.print(", and it's raining"); - } - Serial.println(); - #endif - #ifdef SPARK - Particle.publish("thingspeak-weather", "Current weather conditions in Natick: ",60,PRIVATE); - Particle.publish("thingspeak-weather", String(temperature) + " degrees F, " + String(humidity) + "% humidity",60,PRIVATE); - Particle.publish("thingspeak-weather", "Wind at " + String(windSpeed) + " MPH at " + String (windDirection) + " degrees",60,PRIVATE); - if(rainfall > 0) - { - Particle.publish("thingspeak-weather", "Pressure is " + String(pressure) + " inHg, and it's raining",60,PRIVATE); - } - else - { - Particle.publish("thingspeak-weather", "Pressure is " + String(pressure) + " inHg",60,PRIVATE); - } - #endif + Serial.println("======================================"); + Serial.println("Current weather conditions in Natick: "); + Serial.print(temperature); + Serial.print(" degrees F, "); + Serial.print(humidity); + Serial.println("% humidity"); + Serial.print("Wind at "); + Serial.print(windSpeed); + Serial.print(" MPH at "); + Serial.print(windDirection); + Serial.println(" degrees"); + Serial.print("Pressure is "); + Serial.print(pressure); + Serial.print(" inHg"); + if(rainfall > 0) + { + Serial.print(", and it's raining"); + } + Serial.println(); delay(60000); // Note that the weather station only updates once a minute -} +} diff --git a/examples/WriteMultipleVoltages/WriteMultipleVoltages.ino b/examples/WriteMultipleVoltages/WriteMultipleVoltages.ino index 8da695c..376f02a 100644 --- a/examples/WriteMultipleVoltages/WriteMultipleVoltages.ino +++ b/examples/WriteMultipleVoltages/WriteMultipleVoltages.ino @@ -3,73 +3,75 @@ Reads analog voltages from pins 0-7 and writes them to the 8 fields of a channel on ThingSpeak every 20 seconds. - ThingSpeak ( https://www.thingspeak.com ) is a free IoT service for prototyping - systems that collect, analyze, and react to their environments. + ThingSpeak ( https://www.thingspeak.com ) is an analytic IoT platform service that allows you to aggregate, visualize and + analyze live data streams in the cloud. - Copyright 2015, The MathWorks, Inc. + Copyright 2016, The MathWorks, Inc. Documentation for the ThingSpeak Communication Library for Arduino is in the extras/documentation folder where the library was installed. See the accompaning licence file for licensing information. */ -#ifdef SPARK - #include "ThingSpeak/ThingSpeak.h" -#else - #include "ThingSpeak.h" -#endif +#include "ThingSpeak.h" -/// *********************************************************************************************************** +// *********************************************************************************************************** // This example selects the correct library to use based on the board selected under the Tools menu in the IDE. -// Yun, Wired Ethernet shield, wi-fi shield, esp8266, and Spark are all supported. -// With Uno and Mega, the default is that you're using a wired ethernet shield (http://www.arduino.cc/en/Main/ArduinoEthernetShield) -// If you're using a wi-fi shield (http://www.arduino.cc/en/Main/ArduinoWiFiShield), uncomment the line below +// Yun, Ethernet shield, WiFi101 shield, esp8266, and MXR1000 are all supported. +// With Yun, the default is that you're using the Ethernet connection. +// If you're using a wi-fi 101 or ethernet shield (http://www.arduino.cc/en/Main/ArduinoWiFiShield), uncomment the corresponding line below // *********************************************************************************************************** -//#define USE_WIFI_SHIELD -#ifdef ARDUINO_ARCH_AVR - #ifdef ARDUINO_AVR_YUN +//#define USE_WIFI101_SHIELD +//#define USE_ETHERNET_SHIELD + + +#if !defined(USE_WIFI101_SHIELD) && !defined(USE_ETHERNET_SHIELD) && !defined(ARDUINO_SAMD_MKR1000) && !defined(ARDUINO_AVR_YUN) && !defined(ARDUINO_ARCH_ESP8266) + #error "Uncomment the #define for either USE_WIFI101_SHIELD or USE_ETHERNET_SHIELD" +#endif + +#if defined(ARDUINO_AVR_YUN) #include "YunClient.h" YunClient client; - #else - - #ifdef USE_WIFI_SHIELD - #include - // ESP8266 USERS -- YOU MUST COMMENT OUT THE LINE BELOW. There's a bug in the Arduino IDE that causes it to not respect #ifdef when it comes to #includes - // If you get "multiple definition of `WiFi'" -- comment out the line below. - #include - char ssid[] = ""; // your network SSID (name) - char pass[] = ""; // your network password - int status = WL_IDLE_STATUS; - WiFiClient client; +#else + #if defined(USE_WIFI101_SHIELD) || defined(ARDUINO_SAMD_MKR1000) || defined(ARDUINO_ARCH_ESP8266) + // Use WiFi + #ifdef ARDUINO_ARCH_ESP8266 + #include #else - // Use wired ethernet shield #include - #include - byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; - EthernetClient client; + #include #endif + char ssid[] = ""; // your network SSID (name) + char pass[] = ""; // your network password + int status = WL_IDLE_STATUS; + WiFiClient client; + #elif defined(USE_ETHERNET_SHIELD) + // Use wired ethernet shield + #include + #include + byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; + EthernetClient client; #endif +#endif + +#ifdef ARDUINO_ARCH_AVR // On Arduino: 0 - 1023 maps to 0 - 5 volts #define VOLTAGE_MAX 5.0 #define VOLTAGE_MAXCOUNTS 1023.0 -#endif - -#ifdef ARDUINO_ARCH_ESP8266 - #include - char ssid[] = ""; // your network SSID (name) - char pass[] = ""; // your network password - int status = WL_IDLE_STATUS; - WiFiClient client; +#elif ARDUINO_SAMD_MKR1000 + // On MKR1000: 0 - 1023 maps to 0 - 3.3 volts + #define VOLTAGE_MAX 3.3 + #define VOLTAGE_MAXCOUNTS 1023.0 +#elif ARDUINO_SAM_DUE + // On Due: 0 - 1023 maps to 0 - 3.3 volts + #define VOLTAGE_MAX 3.3 + #define VOLTAGE_MAXCOUNTS 1023.0 +#elif ARDUINO_ARCH_ESP8266 // On ESP8266: 0 - 1023 maps to 0 - 1 volts #define VOLTAGE_MAX 1.0 #define VOLTAGE_MAXCOUNTS 1023.0 #endif -#ifdef SPARK - TCPClient client; - #define VOLTAGE_MAX 3.3 - #define VOLTAGE_MAXCOUNTS 4095.0 -#endif /* ***************************************************************************************** @@ -82,26 +84,26 @@ unsigned long myChannelNumber = 31461; const char * myWriteAPIKey = "LD79EOAAWRVYF04Y"; void setup() { - #if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_ESP8266) - #ifdef ARDUINO_AVR_YUN - Bridge.begin(); + + #ifdef ARDUINO_AVR_YUN + Bridge.begin(); + #else + #if defined(ARDUINO_ARCH_ESP8266) || defined(USE_WIFI101_SHIELD) || defined(ARDUINO_SAMD_MKR1000) + WiFi.begin(ssid, pass); #else - #if defined(USE_WIFI_SHIELD) || defined(ARDUINO_ARCH_ESP8266) - WiFi.begin(ssid, pass); - #else - Ethernet.begin(mac); - #endif + Ethernet.begin(mac); #endif #endif - + ThingSpeak.begin(client); + } void loop() { // Read the input on each pin, convert the reading, and set each field to be sent to ThingSpeak. - // On Arduino: 0 - 1023 maps to 0 - 5 volts + // On Uno,Mega,Yun: 0 - 1023 maps to 0 - 5 volts // On ESP8266: 0 - 1023 maps to 0 - 1 volts - // On Particle: 0 - 4095 maps to 0 - 3.3 volts + // On MKR1000,Due: 0 - 4095 maps to 0 - 3.3 volts float pinVoltage = analogRead(A0) * (VOLTAGE_MAX / VOLTAGE_MAXCOUNTS); ThingSpeak.setField(1,pinVoltage); #ifndef ARDUINO_ARCH_ESP8266 @@ -126,4 +128,4 @@ void loop() { ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey); delay(20000); // ThingSpeak will only accept updates every 15 seconds. -} +} diff --git a/examples/WriteVoltage/WriteVoltage.ino b/examples/WriteVoltage/WriteVoltage.ino index 9ec5df4..04a3cef 100644 --- a/examples/WriteVoltage/WriteVoltage.ino +++ b/examples/WriteVoltage/WriteVoltage.ino @@ -3,75 +3,70 @@ Reads an analog voltage from pin 0, and writes it to a channel on ThingSpeak every 20 seconds. - ThingSpeak ( https://www.thingspeak.com ) is a free IoT service for prototyping - systems that collect, analyze, and react to their environments. + ThingSpeak ( https://www.thingspeak.com ) is an analytic IoT platform service that allows you to aggregate, visualize and + analyze live data streams in the cloud. - Copyright 2015, The MathWorks, Inc. + Copyright 2016, The MathWorks, Inc. Documentation for the ThingSpeak Communication Library for Arduino is in the extras/documentation folder where the library was installed. See the accompaning licence file for licensing information. */ -#ifdef SPARK - #include "ThingSpeak/ThingSpeak.h" -#else - #include "ThingSpeak.h" -#endif +#include "ThingSpeak.h" -/// *********************************************************************************************************** +// *********************************************************************************************************** // This example selects the correct library to use based on the board selected under the Tools menu in the IDE. -// Yun, Wired Ethernet shield, wi-fi shield, esp8266, and Spark are all supported. -// With Uno and Mega, the default is that you're using a wired ethernet shield (http://www.arduino.cc/en/Main/ArduinoEthernetShield) -// If you're using a wi-fi shield (http://www.arduino.cc/en/Main/ArduinoWiFiShield), uncomment the line below +// Yun, Ethernet shield, WiFi101 shield, esp8266, and MXR1000 are all supported. +// With Yun, the default is that you're using the Ethernet connection. +// If you're using a wi-fi 101 or ethernet shield (http://www.arduino.cc/en/Main/ArduinoWiFiShield), uncomment the corresponding line below // *********************************************************************************************************** -//#define USE_WIFI_SHIELD -#ifdef ARDUINO_ARCH_AVR - #ifdef ARDUINO_AVR_YUN +//#define USE_WIFI101_SHIELD +//#define USE_ETHERNET_SHIELD + +#if defined(ARDUINO_AVR_YUN) #include "YunClient.h" YunClient client; - #else - - #ifdef USE_WIFI_SHIELD - #include - // ESP8266 USERS -- YOU MUST COMMENT OUT THE LINE BELOW. There's a bug in the Arduino IDE that causes it to not respect #ifdef when it comes to #includes - // If you get "multiple definition of `WiFi'" -- comment out the line below. - #include - char ssid[] = ""; // your network SSID (name) - char pass[] = ""; // your network password - int status = WL_IDLE_STATUS; - WiFiClient client; +#else + #if defined(USE_WIFI101_SHIELD) || defined(ARDUINO_SAMD_MKR1000) || defined(ARDUINO_ARCH_ESP8266) + // Use WiFi + #ifdef ARDUINO_ARCH_ESP8266 + #include #else - // Use wired ethernet shield #include - #include - byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; - EthernetClient client; + #include #endif + char ssid[] = ""; // your network SSID (name) + char pass[] = ""; // your network password + int status = WL_IDLE_STATUS; + WiFiClient client; + #elif defined(USE_ETHERNET_SHIELD) + // Use wired ethernet shield + #include + #include + byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; + EthernetClient client; #endif +#endif + +#ifdef ARDUINO_ARCH_AVR // On Arduino: 0 - 1023 maps to 0 - 5 volts #define VOLTAGE_MAX 5.0 #define VOLTAGE_MAXCOUNTS 1023.0 -#endif - -#ifdef ARDUINO_ARCH_ESP8266 - #include - char ssid[] = ""; // your network SSID (name) - char pass[] = ""; // your network password - int status = WL_IDLE_STATUS; - WiFiClient client; +#elif ARDUINO_SAMD_MKR1000 + // On MKR1000: 0 - 1023 maps to 0 - 3.3 volts + #define VOLTAGE_MAX 3.3 + #define VOLTAGE_MAXCOUNTS 1023.0 +#elif ARDUINO_SAM_DUE + // On Due: 0 - 1023 maps to 0 - 3.3 volts + #define VOLTAGE_MAX 3.3 + #define VOLTAGE_MAXCOUNTS 1023.0 +#elif ARDUINO_ARCH_ESP8266 // On ESP8266: 0 - 1023 maps to 0 - 1 volts #define VOLTAGE_MAX 1.0 #define VOLTAGE_MAXCOUNTS 1023.0 #endif -#ifdef SPARK - TCPClient client; - // On Particle: 0 - 4095 maps to 0 - 3.3 volts - #define VOLTAGE_MAX 3.3 - #define VOLTAGE_MAXCOUNTS 4095.0 -#endif - /* ***************************************************************************************** **** Visit https://www.thingspeak.com to sign up for a free account and create @@ -83,18 +78,17 @@ unsigned long myChannelNumber = 31461; const char * myWriteAPIKey = "LD79EOAAWRVYF04Y"; void setup() { - #if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_ESP8266) - #ifdef ARDUINO_AVR_YUN - Bridge.begin(); + + #ifdef ARDUINO_AVR_YUN + Bridge.begin(); + #else + #if defined(ARDUINO_ARCH_ESP8266) || defined(USE_WIFI101_SHIELD) || defined(ARDUINO_SAMD_MKR1000) + WiFi.begin(ssid, pass); #else - #if defined(USE_WIFI_SHIELD) || defined(ARDUINO_ARCH_ESP8266) - WiFi.begin(ssid, pass); - #else - Ethernet.begin(mac); - #endif + Ethernet.begin(mac); #endif #endif - + ThingSpeak.begin(client); } @@ -102,13 +96,13 @@ void loop() { // read the input on analog pin 0: int sensorValue = analogRead(A0); // Convert the analog reading - // On Arduino: 0 - 1023 maps to 0 - 5 volts + // On Uno,Mega,YunArduino: 0 - 1023 maps to 0 - 5 volts // On ESP8266: 0 - 1023 maps to 0 - 1 volts - // On Particle: 0 - 4095 maps to 0 - 3.3 volts + // On MKR1000,Due: 0 - 4095 maps to 0 - 3.3 volts float voltage = sensorValue * (VOLTAGE_MAX / VOLTAGE_MAXCOUNTS); // Write to ThingSpeak. There are up to 8 fields in a channel, allowing you to store up to 8 different // pieces of information in a channel. Here, we write to field 1. ThingSpeak.writeField(myChannelNumber, 1, voltage, myWriteAPIKey); delay(20000); // ThingSpeak will only accept updates every 15 seconds. -} +} diff --git a/extras/documentation/_thing_speak_8h_source.html b/extras/documentation/_thing_speak_8h_source.html index f1660e1..7a61c21 100644 --- a/extras/documentation/_thing_speak_8h_source.html +++ b/extras/documentation/_thing_speak_8h_source.html @@ -8,7 +8,7 @@ - + ThingSpeak Communication Library For Arduino, ESP8266, and Particle @@ -31,7 +31,7 @@ - +
-
1 /*
-
2  ThingSpeak(TM) Communication Library For Arduino, ESP8266, and Particle
-
3 
-
4  Enables an Arduino or other compatible hardware to write or read data to or from ThingSpeak,
-
5  an open data platform for the Internet of Things with MATLAB analytics and visualization.
-
6 
-
7  ThingSpeak ( https://www.thingspeak.com ) is a free IoT service for building
-
8  systems that collect, analyze, and react to their environments.
-
9 
-
10  Copyright 2016, The MathWorks, Inc.
-
11 
-
12  See the accompaning licence file for licensing information.
-
13 */
-
14 
-
50 #ifndef ThingSpeak_h
-
51 #define ThingSpeak_h
-
52 
-
53 //#define PRINT_DEBUG_MESSAGES
-
54 //#define PRINT_HTTP
-
55 
-
56 #ifdef SPARK
-
57  // Create platform defines for Particle devices
-
58  #if PLATFORM_ID == 6
-
59  #define PARTICLE_PHOTON
-
60  #define PARTICLE_PHOTONELECTRON
-
61  #elif PLATFORM_ID == 10
-
62  #define PARTICLE_ELECTRON
-
63  #define PARTICLE_PHOTONELECTRON
-
64  #elif PLATFORM_ID == 0
-
65  #define PARTICLE_CORE
-
66  #endif
-
67 
-
68  #include "math.h"
-
69  #include "application.h"
-
70  #ifdef PARTICLE_PHOTONELECTRON
-
71  extern char* dtoa(double val, unsigned char prec, char *sout);
-
72  // On spark photon, There is no itoa, so map to ltoa.
-
73  #include "string_convert.h"
-
74  #define itoa ltoa
-
75  #else
-
76  // On spark core, a long and an int are equivalent, and so there's no "ltoa" function defined. Map it to itoa.
-
77  extern char * itoa(int a, char* buffer, unsigned char radix);
-
78  #define ltoa itoa
-
79  extern char *dtostrf (double val, signed char width, unsigned char prec, char *sout);
-
80  #endif
-
81 #else
-
82  #if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_ESP8266)
-
83  #include "Arduino.h"
-
84  #include <Client.h>
-
85  #else
-
86  #error Only Arduino Yun, Uno/Mega/Due with either Wired or wi-fi Ethernet shield, ESP8266, and Spark Core/Photon/Electron are supported.
-
87  #endif
-
88 #endif
-
89 
-
90 #define THINGSPEAK_URL "api.thingspeak.com"
-
91 #define THINGSPEAK_IPADDRESS IPAddress(184,106,153,149)
-
92 #define THINGSPEAK_PORT_NUMBER 80
-
93 
-
94 #ifdef ARDUINO_ARCH_AVR
-
95  #ifdef ARDUINO_AVR_YUN
-
96  #define TS_USER_AGENT "tslib-arduino/1.0 (arduino yun)"
-
97  #else
-
98  #define TS_USER_AGENT "tslib-arduino/1.0 (arduino uno or mega)"
-
99  #endif
-
100 #elif defined(ARDUINO_ARCH_ESP8266)
-
101  #define TS_USER_AGENT "tslib-arduino/1.0 (ESP8266)"
-
102 #elif defined(SPARK)
-
103  #ifdef PARTICLE_CORE
-
104  #define TS_USER_AGENT "tslib-arduino/1.0 (particle core)"
-
105  #elif defined(PARTICLE_PHOTON)
-
106  #define TS_USER_AGENT "tslib-arduino/1.0 (particle photon)"
-
107  #elif defined(PARTICLE_ELECTRON)
-
108  #define TS_USER_AGENT "tslib-arduino/1.0 (particle electron)"
-
109  #endif
-
110  #define SPARK_PUBLISH_TTL 60 // Spark "time to live" for published messages
-
111  #define SPARK_PUBLISH_TOPIC "thingspeak-debug"
-
112 #endif
-
113 
-
114 #define FIELDNUM_MIN 1
-
115 #define FIELDNUM_MAX 8
-
116 #define FIELDLENGTH_MAX 255 // Max length for a field in ThingSpeak is 255 bytes (UTF-8)
-
117 
-
118 #define TIMEOUT_MS_SERVERRESPONSE 5000 // Wait up to five seconds for server to respond
-
119 
-
120 #define OK_SUCCESS 200 // OK / Success
-
121 #define ERR_BADAPIKEY 400 // Incorrect API key (or invalid ThingSpeak server address)
-
122 #define ERR_BADURL 404 // Incorrect API key (or invalid ThingSpeak server address)
-
123 #define ERR_OUT_OF_RANGE -101 // Value is out of range or string is too long (> 255 bytes)
-
124 #define ERR_INVALID_FIELD_NUM -201 // Invalid field number specified
-
125 #define ERR_SETFIELD_NOT_CALLED -210 // setField() was not called before writeFields()
-
126 #define ERR_CONNECT_FAILED -301 // Failed to connect to ThingSpeak
-
127 #define ERR_UNEXPECTED_FAIL -302 // Unexpected failure during write to ThingSpeak
-
128 #define ERR_BAD_RESPONSE -303 // Unable to parse response
-
129 #define ERR_TIMEOUT -304 // Timeout waiting for server to respond
-
130 #define ERR_NOT_INSERTED -401 // Point was not inserted (most probable cause is the rate limit of once every 15 seconds)
-
131 
- -
136 {
-
137  public:
- -
139  {
-
140  resetWriteFields();
-
141  this->lastReadStatus = OK_SUCCESS;
-
142  };
-
143 
-
165  bool begin(Client & client, const char * customHostName, unsigned int port)
-
166  {
-
167 #ifdef PRINT_DEBUG_MESSAGES
-
168  Serial.print("ts::tsBegin (client: Client URL: "); Serial.print(customHostName); Serial.println(")");
-
169 #endif
-
170  this->setClient(&client);
-
171  this->setServer(customHostName, port);
-
172  resetWriteFields();
-
173  this->lastReadStatus = OK_SUCCESS;
-
174  return true;
-
175  };
-
176 
-
198  bool begin(Client & client, IPAddress customIP, unsigned int port)
-
199  {
-
200 #ifdef PRINT_DEBUG_MESSAGES
-
201  Serial.print("ts::tsBegin (client: Client IP: "); Serial.print(customIP); Serial.println(")");
-
202 #endif
-
203  this->setClient(&client);
-
204  this->setServer(customIP, port);
-
205  resetWriteFields();
-
206  this->lastReadStatus = OK_SUCCESS;
-
207  return true;
-
208  };
-
209 
-
229  bool begin(Client & client)
-
230  {
-
231 #ifdef PRINT_DEBUG_MESSAGES
-
232  Serial.print("ts::tsBegin");
-
233 #endif
-
234  this->setClient(&client);
-
235  this->setServer();
-
236  resetWriteFields();
-
237  this->lastReadStatus = OK_SUCCESS;
-
238  return true;
-
239  };
-
240 
-
257  int writeField(unsigned long channelNumber, unsigned int field, int value, const char * writeAPIKey)
-
258  {
-
259 #ifdef SPARK
-
260  // On Spark, int and long are the same, so map to the long version
-
261  return writeField(channelNumber, field, (long)value, writeAPIKey);
-
262 #else
-
263  char valueString[10]; // int range is -32768 to 32768, so 7 bytes including terminator, plus a little extra
-
264  itoa(value, valueString, 10);
-
265  return writeField(channelNumber, field, valueString, writeAPIKey);
-
266 #endif
-
267  };
-
268 
-
285  int writeField(unsigned long channelNumber, unsigned int field, long value, const char * writeAPIKey)
-
286  {
-
287  char valueString[15]; // long range is -2147483648 to 2147483647, so 12 bytes including terminator
-
288  ltoa(value, valueString, 10);
-
289  return writeField(channelNumber, field, valueString, writeAPIKey);
-
290  };
-
291 
-
309  int writeField(unsigned long channelNumber, unsigned int field, float value, const char * writeAPIKey)
-
310  {
-
311  #ifdef PRINT_DEBUG_MESSAGES
-
312  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(")");
-
313  #endif
-
314  char valueString[20]; // range is -999999000000.00000 to 999999000000.00000, so 19 + 1 for the terminator
-
315  int status = convertFloatToChar(value, valueString);
-
316  if(status != OK_SUCCESS) return status;
-
317 
-
318  return writeField(channelNumber, field, valueString, writeAPIKey);
-
319  };
-
320 
-
342  int writeField(unsigned long channelNumber, unsigned int field, const char * value, const char * writeAPIKey)
-
343  {
-
344  return writeField(channelNumber, field, String(value), writeAPIKey);
-
345  };
-
346 
-
371  int writeField(unsigned long channelNumber, unsigned int field, String value, const char * writeAPIKey)
-
372  {
-
373  // Invalid field number specified
-
374  if(field < FIELDNUM_MIN || field > FIELDNUM_MAX) return ERR_INVALID_FIELD_NUM;
-
375  // Max # bytes for ThingSpeak field is 255
-
376  if(value.length() > FIELDLENGTH_MAX) return ERR_OUT_OF_RANGE;
-
377 
-
378  #ifdef PRINT_DEBUG_MESSAGES
-
379  #ifdef SPARK
-
380  Particle.publish(SPARK_PUBLISH_TOPIC, "writeField (" + String(channelNumber) + ", " + String(writeAPIKey) + ", " + String(field) + ", " + String(value) + ")", SPARK_PUBLISH_TTL, PRIVATE);
-
381  #else
-
382  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("\")");
-
383  #endif
-
384  #endif
-
385  String postMessage = String("field") + String(field) + "=" + value;
-
386  return writeRaw(channelNumber, postMessage, writeAPIKey);
-
387  };
-
388 
-
389 
-
421  int setField(unsigned int field, int value)
-
422  {
-
423 #ifdef SPARK
-
424  // On Spark, int and long are the same, so map to the long version
-
425  return setField(field, (long)value);
-
426 #else
-
427  char valueString[10]; // int range is -32768 to 32768, so 7 bytes including terminator
-
428  itoa(value, valueString, 10);
-
429 
-
430  return setField(field, valueString);
-
431 #endif
-
432  };
-
433 
-
465  int setField(unsigned int field, long value)
-
466  {
-
467  char valueString[15]; // long range is -2147483648 to 2147483647, so 12 bytes including terminator
-
468  ltoa(value, valueString, 10);
-
469  return setField(field, valueString);
-
470  };
-
471 
-
472 
-
504  int setField(unsigned int field, float value)
-
505  {
-
506  char valueString[20]; // range is -999999000000.00000 to 999999000000.00000, so 19 + 1 for the terminator
-
507  int status = convertFloatToChar(value, valueString);
-
508  if(status != OK_SUCCESS) return status;
-
509 
-
510  return setField(field, valueString);
-
511  };
-
512 
-
544  int setField(unsigned int field, const char * value)
-
545  {
-
546  return setField(field, String(value));
-
547  };
-
548 
-
580  int setField(unsigned int field, String value)
-
581  {
-
582  #ifdef PRINT_DEBUG_MESSAGES
-
583  #ifdef SPARK
-
584  Particle.publish(SPARK_PUBLISH_TOPIC, "setField " + String(field) + " to " + String(value), SPARK_PUBLISH_TTL, PRIVATE);
-
585  #else
-
586  Serial.print("ts::setField (field: "); Serial.print(field); Serial.print(" value: \""); Serial.print(value); Serial.println("\")");
-
587  #endif
-
588  #endif
-
589  if(field < FIELDNUM_MIN || field > FIELDNUM_MAX) return ERR_INVALID_FIELD_NUM;
-
590  // Max # bytes for ThingSpeak field is 255 (UTF-8)
-
591  if(value.length() > FIELDLENGTH_MAX) return ERR_OUT_OF_RANGE;
-
592  this->nextWriteField[field - 1] = value;
-
593  return OK_SUCCESS;
-
594  };
-
595 
-
596 
-
630  int setLatitude(float latitude)
-
631  {
-
632  #ifdef PRINT_DEBUG_MESSAGES
-
633  Serial.print("ts::setLatitude(latitude: "); Serial.print(latitude,3); Serial.println("\")");
-
634  #endif
-
635  this->nextWriteLatitude = latitude;
-
636  return OK_SUCCESS;
-
637  };
-
638 
-
639 
-
673  int setLongitude(float longitude)
-
674  {
-
675  #ifdef PRINT_DEBUG_MESSAGES
-
676  Serial.print("ts::setLongitude(longitude: "); Serial.print(longitude,3); Serial.println("\")");
-
677  #endif
-
678  this->nextWriteLongitude = longitude;
-
679  return OK_SUCCESS;
-
680  };
-
681 
-
682 
-
716  int setElevation(float elevation)
-
717  {
-
718  #ifdef PRINT_DEBUG_MESSAGES
-
719  Serial.print("ts::setElevation(elevation: "); Serial.print(elevation,3); Serial.println("\")");
-
720  #endif
-
721  this->nextWriteElevation = elevation;
-
722  return OK_SUCCESS;
-
723  };
-
724 
-
725 
-
760  int writeFields(unsigned long channelNumber, const char * writeAPIKey)
-
761  {
-
762  String postMessage = String("");
-
763  bool fFirstItem = true;
-
764  for(size_t iField = 0; iField < 8; iField++)
-
765  {
-
766  if(this->nextWriteField[iField].length() > 0)
-
767  {
-
768  if(!fFirstItem)
-
769  {
-
770  postMessage = postMessage + String("&");
-
771  }
-
772  postMessage = postMessage + String("field") + String(iField + 1) + String("=") + this->nextWriteField[iField];
-
773  fFirstItem = false;
-
774  this->nextWriteField[iField] = "";
-
775  }
-
776  }
-
777 
-
778  if(!isnan(nextWriteLatitude))
-
779  {
-
780  if(!fFirstItem)
-
781  {
-
782  postMessage = postMessage + String("&");
-
783  }
-
784  postMessage = postMessage + String("lat=") + String(this->nextWriteLatitude);
-
785  fFirstItem = false;
-
786  this->nextWriteLatitude = NAN;
-
787  }
-
788 
-
789  if(!isnan(this->nextWriteLongitude))
-
790  {
-
791  if(!fFirstItem)
-
792  {
-
793  postMessage = postMessage + String("&");
-
794  }
-
795  postMessage = postMessage + String("long=") + String(this->nextWriteLongitude);
-
796  fFirstItem = false;
-
797  this->nextWriteLongitude = NAN;
-
798  }
-
799 
-
800 
-
801  if(!isnan(this->nextWriteElevation))
-
802  {
-
803  if(!fFirstItem)
-
804  {
-
805  postMessage = postMessage + String("&");
-
806  }
-
807  postMessage = postMessage + String("elevation=") + String(this->nextWriteElevation);
-
808  fFirstItem = false;
-
809  this->nextWriteElevation = NAN;
-
810  }
-
811 
-
812  if(fFirstItem)
-
813  {
-
814  // setField was not called before writeFields
-
815  return ERR_SETFIELD_NOT_CALLED;
-
816  }
-
817 
-
818  return writeRaw(channelNumber, postMessage, writeAPIKey);
-
819  };
-
820 
-
821 
-
842  int writeRaw(unsigned long channelNumber, const char * postMessage, const char * writeAPIKey)
-
843  {
-
844  return writeRaw(channelNumber, String(postMessage), writeAPIKey);
-
845  };
-
846 
-
847 
-
863  int writeRaw(unsigned long channelNumber, String postMessage, const char * writeAPIKey)
-
864  {
-
865  #ifdef PRINT_DEBUG_MESSAGES
-
866  Serial.print("ts::writeRaw (channelNumber: "); Serial.print(channelNumber); Serial.print(" writeAPIKey: "); Serial.print(writeAPIKey); Serial.print(" postMessage: \""); Serial.print(postMessage); Serial.println("\")");
-
867  #endif
-
868 
-
869  if(!connectThingSpeak())
-
870  {
-
871  // Failed to connect to ThingSpeak
-
872  return ERR_CONNECT_FAILED;
-
873  }
-
874 
-
875  postMessage = postMessage + String("&headers=false");
-
876 
-
877  #ifdef PRINT_DEBUG_MESSAGES
-
878  #ifdef SPARK
-
879  Particle.publish(SPARK_PUBLISH_TOPIC, "Post " + postMessage, SPARK_PUBLISH_TTL, PRIVATE);
-
880  #else
-
881  Serial.print(" POST \"");Serial.print(postMessage);Serial.println("\"");
-
882  #endif
-
883  #endif
-
884 
-
885  postMessage = postMessage + String("\n");
-
886 
-
887  // Post data to thingspeak
-
888  if(!this->client->print("POST /update HTTP/1.1\n")) return abortWriteRaw();
-
889  if(!writeHTTPHeader(writeAPIKey)) return abortWriteRaw();
-
890  if(!this->client->print("Content-Type: application/x-www-form-urlencoded\n")) return abortWriteRaw();
-
891  if(!this->client->print("Content-Length: ")) return abortWriteRaw();
-
892  if(!this->client->print(postMessage.length())) return abortWriteRaw();
-
893  if(!this->client->print("\n\n")) return abortWriteRaw();
-
894  if(!this->client->print(postMessage)) return abortWriteRaw();
-
895 
-
896  String entryIDText = String();
-
897  int status = getHTTPResponse(entryIDText);
-
898  if(status != OK_SUCCESS)
-
899  {
-
900  client->stop();
-
901  return status;
-
902  }
-
903  long entryID = entryIDText.toInt();
-
904 
-
905  #ifdef PRINT_DEBUG_MESSAGES
-
906  Serial.print(" Entry ID \"");Serial.print(entryIDText);Serial.print("\" (");Serial.print(entryID);Serial.println(")");
-
907  #endif
-
908 
-
909  client->stop();
-
910 
-
911  #ifdef PRINT_DEBUG_MESSAGES
-
912  Serial.println("disconnected.");
-
913  #endif
-
914  if(entryID == 0)
-
915  {
-
916  // ThingSpeak did not accept the write
-
917  status = ERR_NOT_INSERTED;
-
918  }
-
919  return status;
-
920  };
-
921 
-
937  String readStringField(unsigned long channelNumber, unsigned int field, const char * readAPIKey)
-
938  {
-
939  if(field < FIELDNUM_MIN || field > FIELDNUM_MAX)
-
940  {
-
941  this->lastReadStatus = ERR_INVALID_FIELD_NUM;
-
942  return("");
-
943  }
-
944  #ifdef PRINT_DEBUG_MESSAGES
-
945  Serial.print("ts::readStringField(channelNumber: "); Serial.print(channelNumber);
-
946  if(NULL != readAPIKey)
-
947  {
-
948  Serial.print(" readAPIKey: "); Serial.print(readAPIKey);
-
949  }
-
950  Serial.print(" field: "); Serial.print(field); Serial.println(")");
-
951  #endif
-
952  return readRaw(channelNumber, String(String("/fields/") + String(field) + String("/last")), readAPIKey);
-
953  }
-
954 
-
955 
-
970  String readStringField(unsigned long channelNumber, unsigned int field)
-
971  {
-
972  return readStringField(channelNumber, field, NULL);
-
973  };
-
974 
-
975 
-
992  float readFloatField(unsigned long channelNumber, unsigned int field, const char * readAPIKey)
-
993  {
-
994  return convertStringToFloat(readStringField(channelNumber, field, readAPIKey));
-
995  };
-
996 
-
997 
-
1013  float readFloatField(unsigned long channelNumber, unsigned int field)
-
1014  {
-
1015  return readFloatField(channelNumber, field, NULL);
-
1016  };
-
1017 
-
1018 
-
1034  long readLongField(unsigned long channelNumber, unsigned int field, const char * readAPIKey)
-
1035  {
-
1036  // Note that although the function is called "toInt" it really returns a long.
-
1037  return readStringField(channelNumber, field, readAPIKey).toInt();
-
1038  }
-
1039 
-
1040 
-
1055  long readLongField(unsigned long channelNumber, unsigned int field)
-
1056  {
-
1057  return readLongField(channelNumber, field, NULL);
-
1058  };
-
1059 
-
1060 
-
1077  int readIntField(unsigned long channelNumber, unsigned int field, const char * readAPIKey)
-
1078  {
-
1079  return readLongField(channelNumber, field, readAPIKey);
-
1080  }
-
1081 
-
1082 
-
1098  int readIntField(unsigned long channelNumber, unsigned int field)
-
1099  {
-
1100  return readLongField(channelNumber, field, NULL);
-
1101  };
-
1102 
-
1118  String readRaw(unsigned long channelNumber, String URLSuffix)
-
1119  {
-
1120  return readRaw(channelNumber, URLSuffix, NULL);
-
1121  }
-
1122 
-
1139  String readRaw(unsigned long channelNumber, String URLSuffix, const char * readAPIKey)
-
1140  {
-
1141  #ifdef PRINT_DEBUG_MESSAGES
-
1142  Serial.print("ts::readRaw (channelNumber: "); Serial.print(channelNumber);
-
1143  if(NULL != readAPIKey)
-
1144  {
-
1145  Serial.print(" readAPIKey: "); Serial.print(readAPIKey);
-
1146  }
-
1147  Serial.print(" URLSuffix: \""); Serial.print(URLSuffix); Serial.println("\")");
-
1148  #endif
-
1149 
-
1150  if(!connectThingSpeak())
-
1151  {
-
1152  this->lastReadStatus = ERR_CONNECT_FAILED;
-
1153  return String("");
-
1154  }
-
1155 
-
1156  String URL = String("/channels/") + String(channelNumber) + URLSuffix;
-
1157 
-
1158  #ifdef PRINT_DEBUG_MESSAGES
-
1159  Serial.print(" GET \"");Serial.print(URL);Serial.println("\"");
-
1160  #endif
-
1161 
-
1162  // Post data to thingspeak
-
1163  if(!this->client->print("GET ")) return abortReadRaw();
-
1164  if(!this->client->print(URL)) return abortReadRaw();
-
1165  if(!this->client->print(" HTTP/1.1\n")) return abortReadRaw();
-
1166  if(!writeHTTPHeader(readAPIKey)) return abortReadRaw();
-
1167  if(!this->client->print("\n")) return abortReadRaw();
-
1168 
-
1169  String content = String();
-
1170  int status = getHTTPResponse(content);
-
1171  this->lastReadStatus = status;
-
1172 
-
1173 
-
1174  #ifdef PRINT_DEBUG_MESSAGES
-
1175  if(status == OK_SUCCESS)
-
1176  {
-
1177  Serial.print("Read: \""); Serial.print(content); Serial.println("\"");
-
1178  }
-
1179  #endif
-
1180 
-
1181  client->stop();
-
1182  #ifdef PRINT_DEBUG_MESSAGES
-
1183  Serial.println("disconnected.");
-
1184  #endif
-
1185 
-
1186  if(status != OK_SUCCESS)
-
1187  {
-
1188  // return status;
-
1189  return String("");
-
1190  }
-
1191 
-
1192  // This is a workaround to a bug in the Spark implementation of String
-
1193  return String("") + content;
-
1194  };
-
1195 
- -
1230  {
-
1231  return this->lastReadStatus;
-
1232  };
-
1233 private:
-
1234 
-
1235  int abortWriteRaw()
-
1236  {
-
1237  this->client->stop();
-
1238  return ERR_UNEXPECTED_FAIL;
-
1239  }
-
1240 
-
1241  String abortReadRaw()
-
1242  {
-
1243  this->client->stop();
-
1244  #ifdef PRINT_DEBUG_MESSAGES
-
1245  Serial.println("ReadRaw abort - disconnected.");
-
1246  #endif
-
1247  this->lastReadStatus = ERR_UNEXPECTED_FAIL;
-
1248  return String("");
-
1249  }
-
1250 
-
1251  void setServer(const char * customHostName, unsigned int port)
-
1252  {
-
1253  #ifdef PRINT_DEBUG_MESSAGES
-
1254  Serial.print("ts::setServer (URL: \""); Serial.print(customHostName); Serial.println("\")");
-
1255  #endif
-
1256  this->customIP = INADDR_NONE;
-
1257  this->customHostName = customHostName;
-
1258  this->port = port;
-
1259  };
-
1260 
-
1261  void setServer(IPAddress customIP, unsigned int port)
-
1262  {
-
1263  #ifdef PRINT_DEBUG_MESSAGES
-
1264  Serial.print("ts::setServer (IP: \""); Serial.print(customIP); Serial.println("\")");
-
1265  #endif
-
1266  this->customIP = customIP;
-
1267  this->customHostName = NULL;
-
1268  this->port = port;
-
1269  };
-
1270 
-
1271  void setServer()
-
1272  {
-
1273  #ifdef PRINT_DEBUG_MESSAGES
-
1274  Serial.print("ts::setServer (default)");
-
1275  #endif
-
1276  this->customIP = INADDR_NONE;
-
1277  this->customHostName = NULL;
-
1278  this->port = THINGSPEAK_PORT_NUMBER;
-
1279  };
-
1280 
-
1281  void setClient(Client * client) {this->client = client;};
-
1282 
-
1283  Client * client = NULL;
-
1284  const char * customHostName = NULL;
-
1285  IPAddress customIP = INADDR_NONE;
-
1286  unsigned int port = THINGSPEAK_PORT_NUMBER;
-
1287  String nextWriteField[8];
-
1288  float nextWriteLatitude;
-
1289  float nextWriteLongitude;
-
1290  float nextWriteElevation;
-
1291  int lastReadStatus;
-
1292 
-
1293  bool connectThingSpeak()
-
1294  {
-
1295  bool connectSuccess = false;
-
1296  if(this->customIP == INADDR_NONE && NULL == this->customHostName)
-
1297  {
-
1298  #ifdef PRINT_DEBUG_MESSAGES
-
1299  Serial.print(" Connect to default ThingSpeak URL...");
-
1300  #endif
-
1301  connectSuccess = client->connect(THINGSPEAK_URL,THINGSPEAK_PORT_NUMBER);
-
1302  if(!connectSuccess)
-
1303  {
-
1304  #ifdef PRINT_DEBUG_MESSAGES
-
1305  Serial.print("Failed. Try default IP...");
-
1306  #endif
-
1307  connectSuccess = client->connect(THINGSPEAK_IPADDRESS,THINGSPEAK_PORT_NUMBER);
-
1308  }
-
1309  }
-
1310  else
-
1311  {
-
1312  if(!(this->customIP == INADDR_NONE))
-
1313  {
-
1314  // Connect to the server on port 80 (HTTP) at the customIP address
-
1315  #ifdef PRINT_DEBUG_MESSAGES
-
1316  Serial.print(" Connect to ");Serial.print(this->customIP);Serial.print("...");
-
1317  #endif
-
1318  connectSuccess = client->connect(this->customIP,this->port);
-
1319  }
-
1320  if(NULL != this->customHostName)
-
1321  {
-
1322  // Connect to the server on port 80 (HTTP) at the URL address
-
1323  #ifdef PRINT_DEBUG_MESSAGES
-
1324  #ifdef SPARK
-
1325  Particle.publish(SPARK_PUBLISH_TOPIC, "Attempt Connect to URL " + String(this->customHostName), SPARK_PUBLISH_TTL, PRIVATE);
-
1326  #else
-
1327  Serial.print(" Connect to ");Serial.print(this->customHostName);Serial.print(" ...");
-
1328  #endif
-
1329  #endif
-
1330  connectSuccess = client->connect(customHostName,this->port);
-
1331  }
-
1332  }
-
1333 
-
1334  #ifdef PRINT_DEBUG_MESSAGES
-
1335  if (connectSuccess)
-
1336  {
-
1337  #ifdef SPARK
-
1338  Particle.publish(SPARK_PUBLISH_TOPIC, "Connection Success", SPARK_PUBLISH_TTL, PRIVATE);
-
1339  #else
-
1340  Serial.println("Success.");
-
1341  #endif
-
1342  }
-
1343  else
-
1344  {
-
1345  #ifdef SPARK
-
1346  Particle.publish(SPARK_PUBLISH_TOPIC, "Connection Failure", SPARK_PUBLISH_TTL, PRIVATE);
-
1347  #else
-
1348  Serial.println("Failed.");
-
1349  #endif
-
1350  }
-
1351  #endif
-
1352  return connectSuccess;
-
1353  };
-
1354 
-
1355  bool writeHTTPHeader(const char * APIKey)
-
1356  {
-
1357  if(NULL != this->customHostName)
-
1358  {
-
1359  if (!this->client->print("Host: ")) return false;
-
1360  if (!this->client->print(this->customHostName)) return false;
-
1361  if (!this->client->print("\n")) return false;
-
1362  }
-
1363  else
-
1364  {
-
1365  if (!this->client->print("Host: api.thingspeak.com\n")) return false;
-
1366  }
-
1367  if (!this->client->print("Connection: close\n")) return false;
-
1368  if (!this->client->print("User-Agent: ")) return false;
-
1369  if (!this->client->print(TS_USER_AGENT)) return false;
-
1370  if (!this->client->print("\n")) return false;
-
1371  if(NULL != APIKey)
-
1372  {
-
1373  if (!this->client->print("X-THINGSPEAKAPIKEY: ")) return false;
-
1374  if (!this->client->print(APIKey)) return false;
-
1375  if (!this->client->print("\n")) return false;
-
1376  }
-
1377  return true;
-
1378  };
-
1379 
-
1380  int getHTTPResponse(String & response)
-
1381  {
-
1382  long startWaitForResponseAt = millis();
-
1383  while(client->available() == 0 && millis() - startWaitForResponseAt < TIMEOUT_MS_SERVERRESPONSE)
-
1384  {
-
1385  delay(100);
-
1386  }
-
1387  if(client->available() == 0)
-
1388  {
-
1389  return ERR_TIMEOUT; // Didn't get server response in time
-
1390  }
-
1391 
-
1392  if(!client->find(const_cast<char *>("HTTP/1.1")))
-
1393  {
-
1394  #ifdef PRINT_HTTP
-
1395  #ifdef SPARK
-
1396  Particle.publish(SPARK_PUBLISH_TOPIC, "ERROR: Didn't find HTTP/1.1", SPARK_PUBLISH_TTL, PRIVATE);
-
1397  #else
-
1398  Serial.println("ERROR: Didn't find HTTP/1.1");
-
1399  #endif
-
1400  #endif
-
1401  return ERR_BAD_RESPONSE; // Couldn't parse response (didn't find HTTP/1.1)
-
1402  }
-
1403  int status = client->parseInt();
-
1404  #ifdef PRINT_HTTP
-
1405  #ifdef SPARK
-
1406  Particle.publish(SPARK_PUBLISH_TOPIC, "Got Status of " + String(status), SPARK_PUBLISH_TTL, PRIVATE);
-
1407  #else
-
1408  Serial.print("Got Status of ");Serial.println(status);
-
1409  #endif
-
1410  #endif
-
1411  if(status != OK_SUCCESS)
-
1412  {
-
1413  return status;
-
1414  }
-
1415 
-
1416  if(!client->find(const_cast<char *>("\r\n")))
-
1417  {
-
1418  #ifdef PRINT_HTTP
-
1419  #ifdef SPARK
-
1420  Particle.publish(SPARK_PUBLISH_TOPIC, "ERROR: Didn't find end of status line", SPARK_PUBLISH_TTL, PRIVATE);
-
1421  #else
-
1422  Serial.println("ERROR: Didn't find end of status line");
-
1423  #endif
-
1424  #endif
-
1425  return ERR_BAD_RESPONSE;
-
1426  }
-
1427  #ifdef PRINT_HTTP
-
1428  #ifdef SPARK
-
1429  Particle.publish(SPARK_PUBLISH_TOPIC, "Found end of status line", SPARK_PUBLISH_TTL, PRIVATE);
-
1430  #else
-
1431  Serial.println("Found end of status line");
-
1432  #endif
-
1433  #endif
-
1434 
-
1435  if(!client->find(const_cast<char *>("\n\r\n")))
-
1436  {
-
1437  #ifdef PRINT_HTTP
-
1438  #ifdef SPARK
-
1439  Particle.publish(SPARK_PUBLISH_TOPIC, "ERROR: Didn't find end of header", SPARK_PUBLISH_TTL, PRIVATE);
-
1440  #else
-
1441  Serial.println("ERROR: Didn't find end of header");
-
1442  #endif
-
1443  #endif
-
1444  return ERR_BAD_RESPONSE;
-
1445  }
-
1446  #ifdef PRINT_HTTP
-
1447  #ifdef SPARK
-
1448  Particle.publish(SPARK_PUBLISH_TOPIC, "Found end of header", SPARK_PUBLISH_TTL, PRIVATE);
-
1449  #else
-
1450  Serial.println("Found end of header");
-
1451  #endif
-
1452  #endif
-
1453  // This is a workaround to a bug in the Spark implementation of String
-
1454  String tempString = client->readStringUntil('\r');
-
1455  response = tempString;
-
1456  #ifdef PRINT_HTTP
-
1457  #ifdef SPARK
-
1458  Particle.publish(SPARK_PUBLISH_TOPIC, "Response: \"" + tempString + "\"", SPARK_PUBLISH_TTL, PRIVATE);
-
1459  #else
-
1460  Serial.print("Response: \"");Serial.print(response);Serial.println("\"");
-
1461  #endif
-
1462  #endif
-
1463  return status;
-
1464  };
-
1465 
-
1466  int convertFloatToChar(float value, char *valueString)
-
1467  {
-
1468  // Supported range is -999999000000 to 999999000000
-
1469  if(0 == isinf(value) && (value > 999999000000 || value < -999999000000))
-
1470  {
-
1471  // Out of range
-
1472  return ERR_OUT_OF_RANGE;
-
1473  }
-
1474  // Given that the resolution of Spark is 1 / 2^12, or ~0.00024 volts, assume that 5 places right of decimal should be sufficient for most applications
-
1475  #ifdef PARTICLE_PHOTONELECTRON
-
1476  //Photon doesn't have a dtostrf, but does have dtoa
-
1477  dtoa((double)value,5, valueString);
-
1478  #else
-
1479  dtostrf(value,1,5, valueString);
-
1480  #endif
-
1481  return OK_SUCCESS;
-
1482  };
-
1483 
-
1484  float convertStringToFloat(String value)
-
1485  {
-
1486  // There's a bug in the AVR function strtod that it doesn't decode -INF correctly (it maps it to INF)
-
1487  float result = value.toFloat();
-
1488  if(1 == isinf(result) && *value.c_str() == '-')
-
1489  {
-
1490  result = (float)-INFINITY;
-
1491  }
-
1492  return result;
-
1493  };
-
1494 
-
1495  void resetWriteFields()
-
1496  {
-
1497  for(size_t iField = 0; iField < 8; iField++)
-
1498  {
-
1499  this->nextWriteField[iField] = "";
-
1500  }
-
1501  this->nextWriteLatitude = NAN;
-
1502  this->nextWriteLongitude = NAN;
-
1503  this->nextWriteElevation = NAN;
-
1504  };
-
1505 };
-
1506 
-
1507 extern ThingSpeakClass ThingSpeak;
-
1508 
-
1509 #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:842
-
String readStringField(unsigned long channelNumber, unsigned int field, const char *readAPIKey)
Read the latest string from a private ThingSpeak channel.
Definition: ThingSpeak.h:937
-
String readStringField(unsigned long channelNumber, unsigned int field)
Read the latest string from a public ThingSpeak channel.
Definition: ThingSpeak.h:970
-
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:465
-
int writeRaw(unsigned long channelNumber, String postMessage, const char *writeAPIKey)
Write a raw POST to a ThingSpeak channel.
Definition: ThingSpeak.h:863
-
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:198
-
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:760
-
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:421
-
int setLatitude(float latitude)
Set the latitude of a multi-field update. To record latitude, longitude and elevation of a write...
Definition: ThingSpeak.h:630
-
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:165
-
int getLastReadStatus()
Get the status of the previous read.
Definition: ThingSpeak.h:1229
-
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:257
-
Enables an Arduino, ESP8266, Particle or other compatible hardware to write or read data to or from T...
Definition: ThingSpeak.h:135
-
long readLongField(unsigned long channelNumber, unsigned int field, const char *readAPIKey)
Read the latest long from a private ThingSpeak channel.
Definition: ThingSpeak.h:1034
-
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:371
-
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:544
-
String readRaw(unsigned long channelNumber, String URLSuffix)
Read a raw response from a public ThingSpeak channel.
Definition: ThingSpeak.h:1118
-
long readLongField(unsigned long channelNumber, unsigned int field)
Read the latest long from a public ThingSpeak channel.
Definition: ThingSpeak.h:1055
-
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:309
-
int readIntField(unsigned long channelNumber, unsigned int field, const char *readAPIKey)
Read the latest int from a private ThingSpeak channel.
Definition: ThingSpeak.h:1077
-
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:580
-
int setLongitude(float longitude)
Set the longitude of a multi-field update. To record latitude, longitude and elevation of a write...
Definition: ThingSpeak.h:673
-
float readFloatField(unsigned long channelNumber, unsigned int field, const char *readAPIKey)
Read the latest float from a private ThingSpeak channel.
Definition: ThingSpeak.h:992
-
bool begin(Client &client)
Initializes the ThingSpeak library and network settings using the ThingSpeak.com service.
Definition: ThingSpeak.h:229
-
float readFloatField(unsigned long channelNumber, unsigned int field)
Read the latest float from a public ThingSpeak channel.
Definition: ThingSpeak.h:1013
-
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:342
-
int readIntField(unsigned long channelNumber, unsigned int field)
Read the latest int from a public ThingSpeak channel.
Definition: ThingSpeak.h:1098
-
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:504
-
String readRaw(unsigned long channelNumber, String URLSuffix, const char *readAPIKey)
Read a raw response from a private ThingSpeak channel.
Definition: ThingSpeak.h:1139
-
int setElevation(float elevation)
Set the elevation of a multi-field update. To record latitude, longitude and elevation of a write...
Definition: ThingSpeak.h:716
-
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:285
+
1 /*
2  ThingSpeak(TM) Communication Library For Arduino, ESP8266, and Particle
3 
4  Enables an Arduino or other compatible hardware to write or read data to or from ThingSpeak,
5  an open data platform for the Internet of Things with MATLAB analytics and visualization.
6 
7  ThingSpeak ( https://www.thingspeak.com ) is an analytic IoT platform service that allows you to aggregate, visualize and
8  analyze live data streams in the cloud.
9 
10  Copyright 2016, The MathWorks, Inc.
11 
12  See the accompaning licence file for licensing information.
13 */
14 
50 #ifndef ThingSpeak_h
51 #define ThingSpeak_h
52 
53 //#define PRINT_DEBUG_MESSAGES
54 //#define PRINT_HTTP
55 
56 
57 #if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM)
58  #include "Arduino.h"
59  #include <Client.h>
60 #else
61  #error Only Arduino MKR1000, Yun, Uno/Mega/Due with either WiFi101 or Ethernet shield. ESP8266 also supported.
62 #endif
63 
64 
65 #define THINGSPEAK_URL "api.thingspeak.com"
66 #define THINGSPEAK_IPADDRESS IPAddress(184,106,153,149)
67 #define THINGSPEAK_PORT_NUMBER 80
68 
69 #ifdef ARDUINO_ARCH_AVR
70  #ifdef ARDUINO_AVR_YUN
71  #define TS_USER_AGENT "tslib-arduino/1.0 (arduino yun)"
72  #else
73  #define TS_USER_AGENT "tslib-arduino/1.0 (arduino uno or mega)"
74  #endif
75 #elif defined(ARDUINO_ARCH_ESP8266)
76  #define TS_USER_AGENT "tslib-arduino/1.0 (ESP8266)"
77 #elif defined(ARDUINO_SAMD_MKR1000)
78  #define TS_USER_AGENT "tslib-arduino/1.0 (arduino mkr1000)"
79 #elif defined(ARDUINO_SAM_DUE)
80  #define TS_USER_AGENT "tslib-arduino/1.0 (arduino due)"
81 #elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM)
82  #define TS_USER_AGENT "tslib-arduino/1.0 (arduino unknown sam or samd)"
83 #else
84  #error "Platform not supported"
85 #endif
86 
87 #define FIELDNUM_MIN 1
88 #define FIELDNUM_MAX 8
89 #define FIELDLENGTH_MAX 255 // Max length for a field in ThingSpeak is 255 bytes (UTF-8)
90 
91 #define TIMEOUT_MS_SERVERRESPONSE 5000 // Wait up to five seconds for server to respond
92 
93 #define OK_SUCCESS 200 // OK / Success
94 #define ERR_BADAPIKEY 400 // Incorrect API key (or invalid ThingSpeak server address)
95 #define ERR_BADURL 404 // Incorrect API key (or invalid ThingSpeak server address)
96 #define ERR_OUT_OF_RANGE -101 // Value is out of range or string is too long (> 255 bytes)
97 #define ERR_INVALID_FIELD_NUM -201 // Invalid field number specified
98 #define ERR_SETFIELD_NOT_CALLED -210 // setField() was not called before writeFields()
99 #define ERR_CONNECT_FAILED -301 // Failed to connect to ThingSpeak
100 #define ERR_UNEXPECTED_FAIL -302 // Unexpected failure during write to ThingSpeak
101 #define ERR_BAD_RESPONSE -303 // Unable to parse response
102 #define ERR_TIMEOUT -304 // Timeout waiting for server to respond
103 #define ERR_NOT_INSERTED -401 // Point was not inserted (most probable cause is the rate limit of once every 15 seconds)
104 
109 {
110  public:
112  {
113  resetWriteFields();
114  this->lastReadStatus = OK_SUCCESS;
115  };
116 
138  bool begin(Client & client, const char * customHostName, unsigned int port)
139  {
140 #ifdef PRINT_DEBUG_MESSAGES
141  Serial.print("ts::tsBegin (client: Client URL: "); Serial.print(customHostName); Serial.println(")");
142 #endif
143  this->setClient(&client);
144  this->setServer(customHostName, port);
145  resetWriteFields();
146  this->lastReadStatus = OK_SUCCESS;
147  return true;
148  };
149 
171  bool begin(Client & client, IPAddress customIP, unsigned int port)
172  {
173 #ifdef PRINT_DEBUG_MESSAGES
174  Serial.print("ts::tsBegin (client: Client IP: "); Serial.print(customIP); Serial.println(")");
175 #endif
176  this->setClient(&client);
177  this->setServer(customIP, port);
178  resetWriteFields();
179  this->lastReadStatus = OK_SUCCESS;
180  return true;
181  };
182 
202  bool begin(Client & client)
203  {
204 #ifdef PRINT_DEBUG_MESSAGES
205  Serial.print("ts::tsBegin");
206 #endif
207  this->setClient(&client);
208  this->setServer();
209  resetWriteFields();
210  this->lastReadStatus = OK_SUCCESS;
211  return true;
212  };
213 
230  int writeField(unsigned long channelNumber, unsigned int field, int value, const char * writeAPIKey)
231  {
232  char valueString[10]; // int range is -32768 to 32768, so 7 bytes including terminator, plus a little extra
233  itoa(value, valueString, 10);
234  return writeField(channelNumber, field, valueString, writeAPIKey);
235  };
236 
253  int writeField(unsigned long channelNumber, unsigned int field, long value, const char * writeAPIKey)
254  {
255  char valueString[15]; // long range is -2147483648 to 2147483647, so 12 bytes including terminator
256  ltoa(value, valueString, 10);
257  return writeField(channelNumber, field, valueString, writeAPIKey);
258  };
259 
277  int writeField(unsigned long channelNumber, unsigned int field, float value, const char * writeAPIKey)
278  {
279  #ifdef PRINT_DEBUG_MESSAGES
280  Serial.print("ts::writeField (channelNumber: "); Serial.print(channelNumber); Serial.print(" writeAPIKey: "); Serial.print(writeAPIKey); Serial.print(" field: "); Serial.print(field); Serial.print(" value: "); Serial.print(value,5); Serial.println(")");
281  #endif
282  char valueString[20]; // range is -999999000000.00000 to 999999000000.00000, so 19 + 1 for the terminator
283  int status = convertFloatToChar(value, valueString);
284  if(status != OK_SUCCESS) return status;
285 
286  return writeField(channelNumber, field, valueString, writeAPIKey);
287  };
288 
310  int writeField(unsigned long channelNumber, unsigned int field, const char * value, const char * writeAPIKey)
311  {
312  return writeField(channelNumber, field, String(value), writeAPIKey);
313  };
314 
339  int writeField(unsigned long channelNumber, unsigned int field, String value, const char * writeAPIKey)
340  {
341  // Invalid field number specified
342  if(field < FIELDNUM_MIN || field > FIELDNUM_MAX) return ERR_INVALID_FIELD_NUM;
343  // Max # bytes for ThingSpeak field is 255
344  if(value.length() > FIELDLENGTH_MAX) return ERR_OUT_OF_RANGE;
345 
346  #ifdef PRINT_DEBUG_MESSAGES
347  Serial.print("ts::writeField (channelNumber: "); Serial.print(channelNumber); Serial.print(" writeAPIKey: "); Serial.print(writeAPIKey); Serial.print(" field: "); Serial.print(field); Serial.print(" value: \""); Serial.print(value); Serial.println("\")");
348  #endif
349  String postMessage = String("field") + String(field) + "=" + value;
350  return writeRaw(channelNumber, postMessage, writeAPIKey);
351  };
352 
353 
385  int setField(unsigned int field, int value)
386  {
387 
388  char valueString[10]; // int range is -32768 to 32768, so 7 bytes including terminator
389  itoa(value, valueString, 10);
390 
391  return setField(field, valueString);
392 
393  };
394 
426  int setField(unsigned int field, long value)
427  {
428  char valueString[15]; // long range is -2147483648 to 2147483647, so 12 bytes including terminator
429  ltoa(value, valueString, 10);
430  return setField(field, valueString);
431  };
432 
433 
465  int setField(unsigned int field, float value)
466  {
467  char valueString[20]; // range is -999999000000.00000 to 999999000000.00000, so 19 + 1 for the terminator
468  int status = convertFloatToChar(value, valueString);
469  if(status != OK_SUCCESS) return status;
470 
471  return setField(field, valueString);
472  };
473 
505  int setField(unsigned int field, const char * value)
506  {
507  return setField(field, String(value));
508  };
509 
541  int setField(unsigned int field, String value)
542  {
543  #ifdef PRINT_DEBUG_MESSAGES
544  Serial.print("ts::setField (field: "); Serial.print(field); Serial.print(" value: \""); Serial.print(value); Serial.println("\")");
545  #endif
546  if(field < FIELDNUM_MIN || field > FIELDNUM_MAX) return ERR_INVALID_FIELD_NUM;
547  // Max # bytes for ThingSpeak field is 255 (UTF-8)
548  if(value.length() > FIELDLENGTH_MAX) return ERR_OUT_OF_RANGE;
549  this->nextWriteField[field - 1] = value;
550  return OK_SUCCESS;
551  };
552 
553 
587  int setLatitude(float latitude)
588  {
589  #ifdef PRINT_DEBUG_MESSAGES
590  Serial.print("ts::setLatitude(latitude: "); Serial.print(latitude,3); Serial.println("\")");
591  #endif
592  this->nextWriteLatitude = latitude;
593  return OK_SUCCESS;
594  };
595 
596 
630  int setLongitude(float longitude)
631  {
632  #ifdef PRINT_DEBUG_MESSAGES
633  Serial.print("ts::setLongitude(longitude: "); Serial.print(longitude,3); Serial.println("\")");
634  #endif
635  this->nextWriteLongitude = longitude;
636  return OK_SUCCESS;
637  };
638 
639 
673  int setElevation(float elevation)
674  {
675  #ifdef PRINT_DEBUG_MESSAGES
676  Serial.print("ts::setElevation(elevation: "); Serial.print(elevation,3); Serial.println("\")");
677  #endif
678  this->nextWriteElevation = elevation;
679  return OK_SUCCESS;
680  };
681 
682 
717  int writeFields(unsigned long channelNumber, const char * writeAPIKey)
718  {
719  String postMessage = String("");
720  bool fFirstItem = true;
721  for(size_t iField = 0; iField < 8; iField++)
722  {
723  if(this->nextWriteField[iField].length() > 0)
724  {
725  if(!fFirstItem)
726  {
727  postMessage = postMessage + String("&");
728  }
729  postMessage = postMessage + String("field") + String(iField + 1) + String("=") + this->nextWriteField[iField];
730  fFirstItem = false;
731  this->nextWriteField[iField] = "";
732  }
733  }
734 
735  if(!isnan(nextWriteLatitude))
736  {
737  if(!fFirstItem)
738  {
739  postMessage = postMessage + String("&");
740  }
741  postMessage = postMessage + String("lat=") + String(this->nextWriteLatitude);
742  fFirstItem = false;
743  this->nextWriteLatitude = NAN;
744  }
745 
746  if(!isnan(this->nextWriteLongitude))
747  {
748  if(!fFirstItem)
749  {
750  postMessage = postMessage + String("&");
751  }
752  postMessage = postMessage + String("long=") + String(this->nextWriteLongitude);
753  fFirstItem = false;
754  this->nextWriteLongitude = NAN;
755  }
756 
757 
758  if(!isnan(this->nextWriteElevation))
759  {
760  if(!fFirstItem)
761  {
762  postMessage = postMessage + String("&");
763  }
764  postMessage = postMessage + String("elevation=") + String(this->nextWriteElevation);
765  fFirstItem = false;
766  this->nextWriteElevation = NAN;
767  }
768 
769  if(fFirstItem)
770  {
771  // setField was not called before writeFields
772  return ERR_SETFIELD_NOT_CALLED;
773  }
774 
775  return writeRaw(channelNumber, postMessage, writeAPIKey);
776  };
777 
778 
799  int writeRaw(unsigned long channelNumber, const char * postMessage, const char * writeAPIKey)
800  {
801  return writeRaw(channelNumber, String(postMessage), writeAPIKey);
802  };
803 
804 
820  int writeRaw(unsigned long channelNumber, String postMessage, const char * writeAPIKey)
821  {
822  #ifdef PRINT_DEBUG_MESSAGES
823  Serial.print("ts::writeRaw (channelNumber: "); Serial.print(channelNumber); Serial.print(" writeAPIKey: "); Serial.print(writeAPIKey); Serial.print(" postMessage: \""); Serial.print(postMessage); Serial.println("\")");
824  #endif
825 
826  if(!connectThingSpeak())
827  {
828  // Failed to connect to ThingSpeak
829  return ERR_CONNECT_FAILED;
830  }
831 
832  postMessage = postMessage + String("&headers=false");
833 
834  #ifdef PRINT_DEBUG_MESSAGES
835  Serial.print(" POST \"");Serial.print(postMessage);Serial.println("\"");
836  #endif
837 
838  postMessage = postMessage + String("\n");
839 
840  // Post data to thingspeak
841  if(!this->client->print("POST /update HTTP/1.1\n")) return abortWriteRaw();
842  if(!writeHTTPHeader(writeAPIKey)) return abortWriteRaw();
843  if(!this->client->print("Content-Type: application/x-www-form-urlencoded\n")) return abortWriteRaw();
844  if(!this->client->print("Content-Length: ")) return abortWriteRaw();
845  if(!this->client->print(postMessage.length())) return abortWriteRaw();
846  if(!this->client->print("\n\n")) return abortWriteRaw();
847  if(!this->client->print(postMessage)) return abortWriteRaw();
848 
849  String entryIDText = String();
850  int status = getHTTPResponse(entryIDText);
851  if(status != OK_SUCCESS)
852  {
853  client->stop();
854  return status;
855  }
856  long entryID = entryIDText.toInt();
857 
858  #ifdef PRINT_DEBUG_MESSAGES
859  Serial.print(" Entry ID \"");Serial.print(entryIDText);Serial.print("\" (");Serial.print(entryID);Serial.println(")");
860  #endif
861 
862  client->stop();
863 
864  #ifdef PRINT_DEBUG_MESSAGES
865  Serial.println("disconnected.");
866  #endif
867  if(entryID == 0)
868  {
869  // ThingSpeak did not accept the write
870  status = ERR_NOT_INSERTED;
871  }
872  return status;
873  };
874 
890  String readStringField(unsigned long channelNumber, unsigned int field, const char * readAPIKey)
891  {
892  if(field < FIELDNUM_MIN || field > FIELDNUM_MAX)
893  {
894  this->lastReadStatus = ERR_INVALID_FIELD_NUM;
895  return("");
896  }
897  #ifdef PRINT_DEBUG_MESSAGES
898  Serial.print("ts::readStringField(channelNumber: "); Serial.print(channelNumber);
899  if(NULL != readAPIKey)
900  {
901  Serial.print(" readAPIKey: "); Serial.print(readAPIKey);
902  }
903  Serial.print(" field: "); Serial.print(field); Serial.println(")");
904  #endif
905  return readRaw(channelNumber, String(String("/fields/") + String(field) + String("/last")), readAPIKey);
906  }
907 
908 
923  String readStringField(unsigned long channelNumber, unsigned int field)
924  {
925  return readStringField(channelNumber, field, NULL);
926  };
927 
928 
945  float readFloatField(unsigned long channelNumber, unsigned int field, const char * readAPIKey)
946  {
947  return convertStringToFloat(readStringField(channelNumber, field, readAPIKey));
948  };
949 
950 
966  float readFloatField(unsigned long channelNumber, unsigned int field)
967  {
968  return readFloatField(channelNumber, field, NULL);
969  };
970 
971 
987  long readLongField(unsigned long channelNumber, unsigned int field, const char * readAPIKey)
988  {
989  // Note that although the function is called "toInt" it really returns a long.
990  return readStringField(channelNumber, field, readAPIKey).toInt();
991  }
992 
993 
1008  long readLongField(unsigned long channelNumber, unsigned int field)
1009  {
1010  return readLongField(channelNumber, field, NULL);
1011  };
1012 
1013 
1030  int readIntField(unsigned long channelNumber, unsigned int field, const char * readAPIKey)
1031  {
1032  return readLongField(channelNumber, field, readAPIKey);
1033  }
1034 
1035 
1051  int readIntField(unsigned long channelNumber, unsigned int field)
1052  {
1053  return readLongField(channelNumber, field, NULL);
1054  };
1055 
1071  String readRaw(unsigned long channelNumber, String URLSuffix)
1072  {
1073  return readRaw(channelNumber, URLSuffix, NULL);
1074  }
1075 
1092  String readRaw(unsigned long channelNumber, String URLSuffix, const char * readAPIKey)
1093  {
1094  #ifdef PRINT_DEBUG_MESSAGES
1095  Serial.print("ts::readRaw (channelNumber: "); Serial.print(channelNumber);
1096  if(NULL != readAPIKey)
1097  {
1098  Serial.print(" readAPIKey: "); Serial.print(readAPIKey);
1099  }
1100  Serial.print(" URLSuffix: \""); Serial.print(URLSuffix); Serial.println("\")");
1101  #endif
1102 
1103  if(!connectThingSpeak())
1104  {
1105  this->lastReadStatus = ERR_CONNECT_FAILED;
1106  return String("");
1107  }
1108 
1109  String URL = String("/channels/") + String(channelNumber) + URLSuffix;
1110 
1111  #ifdef PRINT_DEBUG_MESSAGES
1112  Serial.print(" GET \"");Serial.print(URL);Serial.println("\"");
1113  #endif
1114 
1115  // Post data to thingspeak
1116  if(!this->client->print("GET ")) return abortReadRaw();
1117  if(!this->client->print(URL)) return abortReadRaw();
1118  if(!this->client->print(" HTTP/1.1\n")) return abortReadRaw();
1119  if(!writeHTTPHeader(readAPIKey)) return abortReadRaw();
1120  if(!this->client->print("\n")) return abortReadRaw();
1121 
1122  String content = String();
1123  int status = getHTTPResponse(content);
1124 
1125  this->lastReadStatus = status;
1126 
1127 
1128  #ifdef PRINT_DEBUG_MESSAGES
1129  if(status == OK_SUCCESS)
1130  {
1131  Serial.print("Read: \""); Serial.print(content); Serial.println("\"");
1132  }
1133  #endif
1134 
1135  client->stop();
1136  #ifdef PRINT_DEBUG_MESSAGES
1137  Serial.println("disconnected.");
1138  #endif
1139 
1140  if(status != OK_SUCCESS)
1141  {
1142  // return status;
1143  return String("");
1144  }
1145 
1146  // This is a workaround to a bug in the Spark implementation of String
1147  return String("") + content;
1148  };
1149 
1184  {
1185  return this->lastReadStatus;
1186  };
1187 private:
1188 
1189  int abortWriteRaw()
1190  {
1191  this->client->stop();
1192  return ERR_UNEXPECTED_FAIL;
1193  }
1194 
1195  String abortReadRaw()
1196  {
1197  this->client->stop();
1198  #ifdef PRINT_DEBUG_MESSAGES
1199  Serial.println("ReadRaw abort - disconnected.");
1200  #endif
1201  this->lastReadStatus = ERR_UNEXPECTED_FAIL;
1202  return String("");
1203  }
1204 
1205  void setServer(const char * customHostName, unsigned int port)
1206  {
1207  #ifdef PRINT_DEBUG_MESSAGES
1208  Serial.print("ts::setServer (URL: \""); Serial.print(customHostName); Serial.println("\")");
1209  #endif
1210  this->customIP = INADDR_NONE;
1211  this->customHostName = customHostName;
1212  this->port = port;
1213  };
1214 
1215  void setServer(IPAddress customIP, unsigned int port)
1216  {
1217  #ifdef PRINT_DEBUG_MESSAGES
1218  Serial.print("ts::setServer (IP: \""); Serial.print(customIP); Serial.println("\")");
1219  #endif
1220  this->customIP = customIP;
1221  this->customHostName = NULL;
1222  this->port = port;
1223  };
1224 
1225  void setServer()
1226  {
1227  #ifdef PRINT_DEBUG_MESSAGES
1228  Serial.print("ts::setServer (default)");
1229  #endif
1230  this->customIP = INADDR_NONE;
1231  this->customHostName = NULL;
1232  this->port = THINGSPEAK_PORT_NUMBER;
1233  };
1234 
1235  void setClient(Client * client) {this->client = client;};
1236 
1237  Client * client = NULL;
1238  const char * customHostName = NULL;
1239  IPAddress customIP = INADDR_NONE;
1240  unsigned int port = THINGSPEAK_PORT_NUMBER;
1241  String nextWriteField[8];
1242  float nextWriteLatitude;
1243  float nextWriteLongitude;
1244  float nextWriteElevation;
1245  int lastReadStatus;
1246 
1247  bool connectThingSpeak()
1248  {
1249  bool connectSuccess = false;
1250  if(this->customIP == INADDR_NONE && NULL == this->customHostName)
1251  {
1252  #ifdef PRINT_DEBUG_MESSAGES
1253  Serial.print(" Connect to default ThingSpeak URL...");
1254  #endif
1255  connectSuccess = client->connect(THINGSPEAK_URL,THINGSPEAK_PORT_NUMBER);
1256  if(!connectSuccess)
1257  {
1258  #ifdef PRINT_DEBUG_MESSAGES
1259  Serial.print("Failed. Try default IP...");
1260  #endif
1261  connectSuccess = client->connect(THINGSPEAK_IPADDRESS,THINGSPEAK_PORT_NUMBER);
1262  }
1263  }
1264  else
1265  {
1266  if(!(this->customIP == INADDR_NONE))
1267  {
1268  // Connect to the server on port 80 (HTTP) at the customIP address
1269  #ifdef PRINT_DEBUG_MESSAGES
1270  Serial.print(" Connect to ");Serial.print(this->customIP);Serial.print("...");
1271  #endif
1272  connectSuccess = client->connect(this->customIP,this->port);
1273  }
1274  if(NULL != this->customHostName)
1275  {
1276  // Connect to the server on port 80 (HTTP) at the URL address
1277  #ifdef PRINT_DEBUG_MESSAGES
1278  Serial.print(" Connect to ");Serial.print(this->customHostName);Serial.print(" ...");
1279  #endif
1280  connectSuccess = client->connect(customHostName,this->port);
1281  }
1282  }
1283 
1284  #ifdef PRINT_DEBUG_MESSAGES
1285  if (connectSuccess)
1286  {
1287  Serial.println("Success.");
1288  }
1289  else
1290  {
1291  Serial.println("Failed.");
1292  }
1293  #endif
1294  return connectSuccess;
1295  };
1296 
1297  bool writeHTTPHeader(const char * APIKey)
1298  {
1299  if(NULL != this->customHostName)
1300  {
1301  if (!this->client->print("Host: ")) return false;
1302  if (!this->client->print(this->customHostName)) return false;
1303  if (!this->client->print("\n")) return false;
1304  }
1305  else
1306  {
1307  if (!this->client->print("Host: api.thingspeak.com\n")) return false;
1308  }
1309  if (!this->client->print("Connection: close\n")) return false;
1310  if (!this->client->print("User-Agent: ")) return false;
1311  if (!this->client->print(TS_USER_AGENT)) return false;
1312  if (!this->client->print("\n")) return false;
1313  if(NULL != APIKey)
1314  {
1315  if (!this->client->print("X-THINGSPEAKAPIKEY: ")) return false;
1316  if (!this->client->print(APIKey)) return false;
1317  if (!this->client->print("\n")) return false;
1318  }
1319  return true;
1320  };
1321 
1322  int getHTTPResponse(String & response)
1323  {
1324  long startWaitForResponseAt = millis();
1325  while(client->available() == 0 && millis() - startWaitForResponseAt < TIMEOUT_MS_SERVERRESPONSE)
1326  {
1327  delay(100);
1328  }
1329  if(client->available() == 0)
1330  {
1331  return ERR_TIMEOUT; // Didn't get server response in time
1332  }
1333 
1334  if(!client->find(const_cast<char *>("HTTP/1.1")))
1335  {
1336  #ifdef PRINT_HTTP
1337  Serial.println("ERROR: Didn't find HTTP/1.1");
1338  #endif
1339  return ERR_BAD_RESPONSE; // Couldn't parse response (didn't find HTTP/1.1)
1340  }
1341  int status = client->parseInt();
1342  #ifdef PRINT_HTTP
1343  Serial.print("Got Status of ");Serial.println(status);
1344  #endif
1345  if(status != OK_SUCCESS)
1346  {
1347  return status;
1348  }
1349 
1350  if(!client->find(const_cast<char *>("\r\n")))
1351  {
1352  #ifdef PRINT_HTTP
1353  Serial.println("ERROR: Didn't find end of status line");
1354  #endif
1355  return ERR_BAD_RESPONSE;
1356  }
1357  #ifdef PRINT_HTTP
1358  Serial.println("Found end of status line");
1359  #endif
1360 
1361  if(!client->find(const_cast<char *>("\n\r\n")))
1362  {
1363  #ifdef PRINT_HTTP
1364  Serial.println("ERROR: Didn't find end of header");
1365  #endif
1366  return ERR_BAD_RESPONSE;
1367  }
1368  #ifdef PRINT_HTTP
1369  Serial.println("Found end of header");
1370  #endif
1371  // This is a workaround to a bug in the Spark implementation of String
1372  String tempString = client->readStringUntil('\r');
1373  response = tempString;
1374  #ifdef PRINT_HTTP
1375  Serial.print("Response: \"");Serial.print(response);Serial.println("\"");
1376  #endif
1377  return status;
1378  };
1379 
1380  int convertFloatToChar(float value, char *valueString)
1381  {
1382  // Supported range is -999999000000 to 999999000000
1383  if(0 == isinf(value) && (value > 999999000000 || value < -999999000000))
1384  {
1385  // Out of range
1386  return ERR_OUT_OF_RANGE;
1387  }
1388  // assume that 5 places right of decimal should be sufficient for most applications
1389 
1390  #if defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM)
1391  sprintf(valueString, "%.5f", value);
1392  #else
1393  dtostrf(value,1,5, valueString);
1394  #endif
1395  return OK_SUCCESS;
1396  };
1397 
1398  float convertStringToFloat(String value)
1399  {
1400  // There's a bug in the AVR function strtod that it doesn't decode -INF correctly (it maps it to INF)
1401  float result = value.toFloat();
1402  if(1 == isinf(result) && *value.c_str() == '-')
1403  {
1404  result = (float)-INFINITY;
1405  }
1406  return result;
1407  };
1408 
1409  void resetWriteFields()
1410  {
1411  for(size_t iField = 0; iField < 8; iField++)
1412  {
1413  this->nextWriteField[iField] = "";
1414  }
1415  this->nextWriteLatitude = NAN;
1416  this->nextWriteLongitude = NAN;
1417  this->nextWriteElevation = NAN;
1418  };
1419 };
1420 
1421 extern ThingSpeakClass ThingSpeak;
1422 
1423 #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:799
+
String readStringField(unsigned long channelNumber, unsigned int field, const char *readAPIKey)
Read the latest string from a private ThingSpeak channel.
Definition: ThingSpeak.h:890
+
String readStringField(unsigned long channelNumber, unsigned int field)
Read the latest string from a public ThingSpeak channel.
Definition: ThingSpeak.h:923
+
int setField(unsigned int field, long value)
Set the value of a single field that will be part of a multi-field update. To write multiple fields a...
Definition: ThingSpeak.h:426
+
int writeRaw(unsigned long channelNumber, String postMessage, const char *writeAPIKey)
Write a raw POST to a ThingSpeak channel.
Definition: ThingSpeak.h:820
+
bool begin(Client &client, IPAddress customIP, unsigned int port)
Initializes the ThingSpeak library and network settings using a custom installation of ThingSpeak...
Definition: ThingSpeak.h:171
+
int writeFields(unsigned long channelNumber, const char *writeAPIKey)
Write a multi-field update. Call setField() for each of the fields you want to write, setLatitude() / setLongitude() / setElevation(), and then call writeFields()
Definition: ThingSpeak.h:717
+
int setField(unsigned int field, int value)
Set the value of a single field that will be part of a multi-field update. To write multiple fields a...
Definition: ThingSpeak.h:385
+
int setLatitude(float latitude)
Set the latitude of a multi-field update. To record latitude, longitude and elevation of a write...
Definition: ThingSpeak.h:587
+
bool begin(Client &client, const char *customHostName, unsigned int port)
Initializes the ThingSpeak library and network settings using a custom installation of ThingSpeak...
Definition: ThingSpeak.h:138
+
int getLastReadStatus()
Get the status of the previous read.
Definition: ThingSpeak.h:1183
+
int writeField(unsigned long channelNumber, unsigned int field, int value, const char *writeAPIKey)
Write an integer value to a single field in a ThingSpeak channel.
Definition: ThingSpeak.h:230
+
Enables an Arduino, ESP8266, Particle or other compatible hardware to write or read data to or from T...
Definition: ThingSpeak.h:108
+
long readLongField(unsigned long channelNumber, unsigned int field, const char *readAPIKey)
Read the latest long from a private ThingSpeak channel.
Definition: ThingSpeak.h:987
+
int writeField(unsigned long channelNumber, unsigned int field, String value, const char *writeAPIKey)
Write a String to a single field in a ThingSpeak channel.
Definition: ThingSpeak.h:339
+
int setField(unsigned int field, const char *value)
Set the value of a single field that will be part of a multi-field update. To write multiple fields a...
Definition: ThingSpeak.h:505
+
String readRaw(unsigned long channelNumber, String URLSuffix)
Read a raw response from a public ThingSpeak channel.
Definition: ThingSpeak.h:1071
+
long readLongField(unsigned long channelNumber, unsigned int field)
Read the latest long from a public ThingSpeak channel.
Definition: ThingSpeak.h:1008
+
int writeField(unsigned long channelNumber, unsigned int field, float value, const char *writeAPIKey)
Write a floating point value to a single field in a ThingSpeak channel.
Definition: ThingSpeak.h:277
+
int readIntField(unsigned long channelNumber, unsigned int field, const char *readAPIKey)
Read the latest int from a private ThingSpeak channel.
Definition: ThingSpeak.h:1030
+
int setField(unsigned int field, String value)
Set the value of a single field that will be part of a multi-field update. To write multiple fields a...
Definition: ThingSpeak.h:541
+
int setLongitude(float longitude)
Set the longitude of a multi-field update. To record latitude, longitude and elevation of a write...
Definition: ThingSpeak.h:630
+
float readFloatField(unsigned long channelNumber, unsigned int field, const char *readAPIKey)
Read the latest float from a private ThingSpeak channel.
Definition: ThingSpeak.h:945
+
bool begin(Client &client)
Initializes the ThingSpeak library and network settings using the ThingSpeak.com service.
Definition: ThingSpeak.h:202
+
float readFloatField(unsigned long channelNumber, unsigned int field)
Read the latest float from a public ThingSpeak channel.
Definition: ThingSpeak.h:966
+
int writeField(unsigned long channelNumber, unsigned int field, const char *value, const char *writeAPIKey)
Write a string to a single field in a ThingSpeak channel.
Definition: ThingSpeak.h:310
+
int readIntField(unsigned long channelNumber, unsigned int field)
Read the latest int from a public ThingSpeak channel.
Definition: ThingSpeak.h:1051
+
int setField(unsigned int field, float value)
Set the value of a single field that will be part of a multi-field update. To write multiple fields a...
Definition: ThingSpeak.h:465
+
String readRaw(unsigned long channelNumber, String URLSuffix, const char *readAPIKey)
Read a raw response from a private ThingSpeak channel.
Definition: ThingSpeak.h:1092
+
int setElevation(float elevation)
Set the elevation of a multi-field update. To record latitude, longitude and elevation of a write...
Definition: ThingSpeak.h:673
+
int writeField(unsigned long channelNumber, unsigned int field, long value, const char *writeAPIKey)
Write a long value to a single field in a ThingSpeak channel.
Definition: ThingSpeak.h:253
- + - +
@@ -245,18 +234,7 @@ -
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);
-
}
-
+
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);
}
@@ -281,18 +259,7 @@ -
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);
-
}
-
+
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);
}
@@ -323,22 +290,7 @@
  • -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);
    -
    }
    -
    +
    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);
    }
    @@ -381,14 +333,7 @@ -
    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);
    -
    }
    -
    +
    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);
    }
    @@ -424,14 +369,7 @@ -
    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);
    -
    }
    -
    +
    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);
    }
    @@ -475,13 +413,7 @@
    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);
    -
    }
    -
    +
    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);
    }
    @@ -518,13 +450,7 @@
    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);
    -
    }
    -
    +
    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);
    }
    @@ -567,13 +493,7 @@ -
    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);
    -
    }
    -
    +
    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);
    }
    @@ -609,13 +529,7 @@ -
    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);
    -
    }
    -
    +
    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);
    }
    @@ -652,13 +566,7 @@
    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);
    -
    }
    -
    +
    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);
    }
    @@ -702,13 +610,7 @@
    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);
    -
    }
    -
    +
    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);
    }
    @@ -751,13 +653,7 @@ -
    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);
    -
    }
    -
    +
    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);
    }
    @@ -793,13 +689,7 @@ -
    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);
    -
    }
    -
    +
    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);
    }
    @@ -825,31 +715,7 @@
    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);
    - -
    ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
    -
    delay(20000);
    -
    }
    -
    +
    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);
    ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
    delay(20000);
    }
    @@ -886,28 +752,7 @@
    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);
    -
    }
    -
    +
    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);
    }
    @@ -944,28 +789,7 @@
    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);
    -
    }
    -
    +
    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);
    }
    @@ -1002,28 +826,7 @@
    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);
    -
    }
    -
    +
    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);
    }
    @@ -1060,28 +863,7 @@
    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);
    -
    }
    -
    +
    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);
    }
    @@ -1118,28 +900,7 @@
    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);
    -
    }
    -
    +
    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);
    }
    @@ -1165,31 +926,7 @@
    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);
    - -
    delay(20000);
    -
    }
    -
    +
    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);
    delay(20000);
    }
    @@ -1215,31 +952,7 @@
    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);
    - -
    ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
    -
    delay(20000);
    -
    }
    -
    +
    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);
    ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
    delay(20000);
    }
    @@ -1290,12 +1003,7 @@
    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);
    -
    }
    -
    +
    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);
    }
    @@ -1346,12 +1054,7 @@
    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);
    -
    }
    -
    +
    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);
    }
    @@ -1402,13 +1105,7 @@
    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);
    -
    }
    -
    +
    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);
    }
    @@ -1459,17 +1156,7 @@
    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);
    -
    }
    -
    +
    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);
    }
    @@ -1520,20 +1207,7 @@
    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);
    -
    }
    -
    +
    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);
    }
    @@ -1570,31 +1244,7 @@
    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);
    - -
    ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
    -
    delay(20000);
    -
    }
    -
    +
    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);
    ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
    delay(20000);
    }
    @@ -1638,17 +1288,7 @@
    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);
    -
    }
    -
    +
    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);
    }
    @@ -1692,12 +1332,7 @@
    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);
    -
    }
    -
    +
    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);
    }
    diff --git a/extras/documentation/classes.html b/extras/documentation/classes.html index 5802220..dbcb472 100644 --- a/extras/documentation/classes.html +++ b/extras/documentation/classes.html @@ -8,7 +8,7 @@ - + ThingSpeak Communication Library For Arduino, ESP8266, and Particle @@ -31,7 +31,7 @@ - +
    - +
    diff --git a/extras/documentation/dir_339e8c1d13ed9d171a31356d80f51341.html b/extras/documentation/dir_339e8c1d13ed9d171a31356d80f51341.html index 311dace..e8e74d7 100644 --- a/extras/documentation/dir_339e8c1d13ed9d171a31356d80f51341.html +++ b/extras/documentation/dir_339e8c1d13ed9d171a31356d80f51341.html @@ -8,7 +8,7 @@ - +ThingSpeak Communication Library For Arduino, ESP8266, and Particle @@ -31,7 +31,7 @@
      T  
    - + diff --git a/extras/documentation/dir_9eb8a1162b9e86c4bf1f8e762bfe83d1.html b/extras/documentation/dir_9eb8a1162b9e86c4bf1f8e762bfe83d1.html index 013a2d8..5b7ea0a 100644 --- a/extras/documentation/dir_9eb8a1162b9e86c4bf1f8e762bfe83d1.html +++ b/extras/documentation/dir_9eb8a1162b9e86c4bf1f8e762bfe83d1.html @@ -8,7 +8,7 @@ - + ThingSpeak Communication Library For Arduino, ESP8266, and Particle @@ -31,7 +31,7 @@ - + diff --git a/extras/documentation/doxygen.css b/extras/documentation/doxygen.css index a000833..1425ec5 100644 --- a/extras/documentation/doxygen.css +++ b/extras/documentation/doxygen.css @@ -1,4 +1,4 @@ -/* The standard CSS for doxygen 1.8.9.1 */ +/* The standard CSS for doxygen 1.8.11 */ body, table, div, p, dl { font: 400 14px/22px Roboto,sans-serif; @@ -206,6 +206,11 @@ div.line { transition-duration: 0.5s; } +div.line:after { + content:"\000A"; + white-space: pre; +} + div.line.glow { background-color: cyan; box-shadow: 0 0 10px cyan; @@ -242,7 +247,7 @@ div.ah, span.ah { -webkit-box-shadow: 2px 2px 3px #999; -moz-box-shadow: rgba(0, 0, 0, 0.15) 2px 2px 2px; background-image: -webkit-gradient(linear, left top, left bottom, from(#eee), to(#000),color-stop(0.3, #444)); - background-image: -moz-linear-gradient(center top, #eee 0%, #444 40%, #000); + background-image: -moz-linear-gradient(center top, #eee 0%, #444 40%, #000 110%); } div.classindex ul { @@ -832,6 +837,10 @@ address { color: #2A3D61; } +table.doxtable caption { + caption-side: top; +} + table.doxtable { border-collapse:collapse; margin-top: 4px; @@ -997,6 +1006,18 @@ div.summary a white-space: nowrap; } +table.classindex +{ + margin: 10px; + white-space: nowrap; + margin-left: 3%; + margin-right: 3%; + width: 94%; + border: 0; + border-spacing: 0; + padding: 0; +} + div.ingroups { font-size: 8pt; @@ -1108,6 +1129,11 @@ dl.section dd { border: 0px none; } +#projectalign +{ + vertical-align: middle; +} + #projectname { font: 300% Tahoma, Arial,sans-serif; @@ -1191,7 +1217,7 @@ div.toc { border-radius: 7px 7px 7px 7px; float: right; height: auto; - margin: 0 20px 10px 10px; + margin: 0 8px 10px 10px; width: 200px; } diff --git a/extras/documentation/functions.html b/extras/documentation/functions.html index a449aec..907e1ca 100644 --- a/extras/documentation/functions.html +++ b/extras/documentation/functions.html @@ -8,7 +8,7 @@ - + ThingSpeak Communication Library For Arduino, ESP8266, and Particle @@ -31,7 +31,7 @@ - + - + - +