diff --git a/examples/ReadLastTemperature/ReadLastTemperature.ino b/examples/ReadLastTemperature/ReadLastTemperature.ino index e3c9fd0..8cbbe2e 100644 --- a/examples/ReadLastTemperature/ReadLastTemperature.ino +++ b/examples/ReadLastTemperature/ReadLastTemperature.ino @@ -8,7 +8,7 @@ ThingSpeak ( https://www.thingspeak.com ) is a free IoT service for building systems that collect, analyze, and react to their environments. - 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. @@ -105,7 +105,7 @@ void loop() { Serial.println(" degrees F"); #endif #ifdef SPARK - Spark.publish("thingspeak-lasttemp", "Current temp " + String(temperatureInF) + " degrees F",60,PRIVATE); + Particle.publish("thingspeak-lasttemp", String::format("Current temp %.1f degrees F",temperatureInF),60,PRIVATE); #endif 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 ecd33ba..5c266a7 100644 --- a/examples/ReadPrivateChannel/ReadPrivateChannel.ino +++ b/examples/ReadPrivateChannel/ReadPrivateChannel.ino @@ -9,7 +9,7 @@ ThingSpeak ( https://www.thingspeak.com ) is a free IoT service for prototyping systems that collect, analyze, and react to their environments. - 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. @@ -108,7 +108,7 @@ void loop() { Serial.println("V"); #endif #ifdef SPARK - Spark.publish("thingspeak-readvoltage", "Latest voltage is: " + String(voltage) + "V",60,PRIVATE); + Particle.publish("thingspeak-readvoltage", "Latest voltage is: " + String(voltage) + "V",60,PRIVATE); #endif delay(30000); } diff --git a/examples/ReadWeatherStation/ReadWeatherStation.ino b/examples/ReadWeatherStation/ReadWeatherStation.ino index 4a9a966..db6b9cd 100644 --- a/examples/ReadWeatherStation/ReadWeatherStation.ino +++ b/examples/ReadWeatherStation/ReadWeatherStation.ino @@ -7,7 +7,7 @@ ThingSpeak ( https://www.thingspeak.com ) is a free IoT service for prototyping systems that collect, analyze, and react to their environments. - 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. @@ -126,16 +126,16 @@ void loop() { Serial.println(); #endif #ifdef SPARK - Spark.publish("thingspeak-weather", "Current weather conditions in Natick: ",60,PRIVATE); - Spark.publish("thingspeak-weather", String(temperature) + " degrees F, " + String(humidity) + "% humidity",60,PRIVATE); - Spark.publish("thingspeak-weather", "Wind at " + String(windSpeed) + " MPH at " + String (windDirection) + " degrees",60,PRIVATE); + 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) { - Spark.publish("thingspeak-weather", "Pressure is " + String(pressure) + " inHg, and it's raining",60,PRIVATE); + Particle.publish("thingspeak-weather", "Pressure is " + String(pressure) + " inHg, and it's raining",60,PRIVATE); } else { - Spark.publish("thingspeak-weather", "Pressure is " + String(pressure) + " inHg",60,PRIVATE); + Particle.publish("thingspeak-weather", "Pressure is " + String(pressure) + " inHg",60,PRIVATE); } #endif diff --git a/extras/documentation/_thing_speak_8h_source.html b/extras/documentation/_thing_speak_8h_source.html index 559101e..f1660e1 100644 --- a/extras/documentation/_thing_speak_8h_source.html +++ b/extras/documentation/_thing_speak_8h_source.html @@ -1,7 +1,7 @@ @@ -57,7 +57,7 @@
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 2015, The MathWorks, Inc.
+
10  Copyright 2016, The MathWorks, Inc.
11 
12  See the accompaning licence file for licensing information.
13 */
@@ -234,7 +234,7 @@
377 
378  #ifdef PRINT_DEBUG_MESSAGES
379  #ifdef SPARK
-
380  Spark.publish(SPARK_PUBLISH_TOPIC, "writeField (" + String(channelNumber) + ", " + String(writeAPIKey) + ", " + String(field) + ", " + String(value) + ")", SPARK_PUBLISH_TTL, PRIVATE);
+
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
@@ -283,7 +283,7 @@
581  {
582  #ifdef PRINT_DEBUG_MESSAGES
583  #ifdef SPARK
-
584  Spark.publish(SPARK_PUBLISH_TOPIC, "setField " + String(field) + " to " + String(value), SPARK_PUBLISH_TTL, PRIVATE);
+
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
@@ -410,7 +410,7 @@
876 
877  #ifdef PRINT_DEBUG_MESSAGES
878  #ifdef SPARK
-
879  Spark.publish(SPARK_PUBLISH_TOPIC, "Post " + postMessage, SPARK_PUBLISH_TTL, PRIVATE);
+
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
@@ -672,7 +672,7 @@
1322  // Connect to the server on port 80 (HTTP) at the URL address
1323  #ifdef PRINT_DEBUG_MESSAGES
1324  #ifdef SPARK
-
1325  Spark.publish(SPARK_PUBLISH_TOPIC, "Attempt Connect to URL " + String(this->customHostName), SPARK_PUBLISH_TTL, PRIVATE);
+
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
@@ -685,7 +685,7 @@
1335  if (connectSuccess)
1336  {
1337  #ifdef SPARK
-
1338  Spark.publish(SPARK_PUBLISH_TOPIC, "Connection Success", SPARK_PUBLISH_TTL, PRIVATE);
+
1338  Particle.publish(SPARK_PUBLISH_TOPIC, "Connection Success", SPARK_PUBLISH_TTL, PRIVATE);
1339  #else
1340  Serial.println("Success.");
1341  #endif
@@ -693,7 +693,7 @@
1343  else
1344  {
1345  #ifdef SPARK
-
1346  Spark.publish(SPARK_PUBLISH_TOPIC, "Connection Failure", SPARK_PUBLISH_TTL, PRIVATE);
+
1346  Particle.publish(SPARK_PUBLISH_TOPIC, "Connection Failure", SPARK_PUBLISH_TTL, PRIVATE);
1347  #else
1348  Serial.println("Failed.");
1349  #endif
@@ -742,98 +742,121 @@
1392  if(!client->find(const_cast<char *>("HTTP/1.1")))
1393  {
1394  #ifdef PRINT_HTTP
-
1395  Serial.println("ERROR: Didn't find HTTP/1.1");
-
1396  #endif
-
1397  return ERR_BAD_RESPONSE; // Couldn't parse response (didn't find HTTP/1.1)
-
1398  }
-
1399  int status = client->parseInt();
-
1400  #ifdef PRINT_HTTP
-
1401  Serial.print("Got Status of ");Serial.println(status);
-
1402  #endif
-
1403  if(status != OK_SUCCESS)
-
1404  {
-
1405  return status;
-
1406  }
-
1407 
-
1408  if(!client->find(const_cast<char *>("\n\r\n")))
-
1409  {
-
1410  #ifdef PRINT_HTTP
-
1411  Serial.println("ERROR: Didn't find end of header");
-
1412  #endif
-
1413  return ERR_BAD_RESPONSE;
+
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  #ifdef PRINT_HTTP
-
1416  Serial.println("Found end of header");
-
1417  #endif
-
1418  #ifndef PRINT_HTTP
-
1419  client->parseInt();
-
1420  #else
-
1421  long length = client->parseInt();
-
1422  Serial.print("Got length of ");Serial.println(length);
-
1423  #endif
-
1424  if(!client->find(const_cast<char *>("\r\n")))
-
1425  {
-
1426  #ifdef PRINT_HTTP
-
1427  Serial.println("ERROR: Didn't find end of length");
-
1428  #endif
-
1429  return ERR_BAD_RESPONSE;
-
1430  }
-
1431  #ifdef PRINT_HTTP
-
1432  Serial.println("Found end of length");
+
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  // This is a workaround to a bug in the Spark implementation of String
-
1435  String tempString = client->readStringUntil('\r');
-
1436  response = tempString;
-
1437  #ifdef PRINT_HTTP
-
1438  Serial.print("Response: \"");Serial.print(response);Serial.println("\"");
-
1439  #endif
-
1440  return status;
-
1441  };
-
1442 
-
1443  int convertFloatToChar(float value, char *valueString)
-
1444  {
-
1445  // Supported range is -999999000000 to 999999000000
-
1446  if(0 == isinf(value) && (value > 999999000000 || value < -999999000000))
-
1447  {
-
1448  // Out of range
-
1449  return ERR_OUT_OF_RANGE;
-
1450  }
-
1451  // 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
-
1452  #ifdef PARTICLE_PHOTONELECTRON
-
1453  //Photon doesn't have a dtostrf, but does have dtoa
-
1454  dtoa((double)value,5, valueString);
-
1455  #else
-
1456  dtostrf(value,1,5, valueString);
-
1457  #endif
-
1458  return OK_SUCCESS;
-
1459  };
-
1460 
-
1461  float convertStringToFloat(String value)
-
1462  {
-
1463  // There's a bug in the AVR function strtod that it doesn't decode -INF correctly (it maps it to INF)
-
1464  float result = value.toFloat();
-
1465  if(1 == isinf(result) && *value.c_str() == '-')
-
1466  {
-
1467  result = (float)-INFINITY;
-
1468  }
-
1469  return result;
-
1470  };
-
1471 
-
1472  void resetWriteFields()
-
1473  {
-
1474  for(size_t iField = 0; iField < 8; iField++)
-
1475  {
-
1476  this->nextWriteField[iField] = "";
-
1477  }
-
1478  this->nextWriteLatitude = NAN;
-
1479  this->nextWriteLongitude = NAN;
-
1480  this->nextWriteElevation = NAN;
-
1481  };
-
1482 };
+
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 extern ThingSpeakClass ThingSpeak;
-
1485 
-
1486 #endif //ThingSpeak_h
+
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
ThingSpeakClass::writeRaw
int writeRaw(unsigned long channelNumber, const char *postMessage, const char *writeAPIKey)
Write a raw POST to a ThingSpeak channel.
Definition: ThingSpeak.h:842
ThingSpeakClass::readStringField
String readStringField(unsigned long channelNumber, unsigned int field, const char *readAPIKey)
Read the latest string from a private ThingSpeak channel.
Definition: ThingSpeak.h:937
ThingSpeakClass::readStringField
String readStringField(unsigned long channelNumber, unsigned int field)
Read the latest string from a public ThingSpeak channel.
Definition: ThingSpeak.h:970
@@ -867,6 +890,11 @@
ThingSpeakClass::writeField
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
+ diff --git a/extras/documentation/annotated.html b/extras/documentation/annotated.html index 708b90f..dc5784c 100644 --- a/extras/documentation/annotated.html +++ b/extras/documentation/annotated.html @@ -1,7 +1,7 @@ @@ -57,6 +57,11 @@ + diff --git a/extras/documentation/class_thing_speak_class.html b/extras/documentation/class_thing_speak_class.html index c7ba2e9..3ddf80f 100644 --- a/extras/documentation/class_thing_speak_class.html +++ b/extras/documentation/class_thing_speak_class.html @@ -1,7 +1,7 @@ @@ -1703,6 +1703,11 @@ + diff --git a/extras/documentation/classes.html b/extras/documentation/classes.html index aa46863..5802220 100644 --- a/extras/documentation/classes.html +++ b/extras/documentation/classes.html @@ -1,7 +1,7 @@ @@ -61,6 +61,11 @@
T
+ diff --git a/extras/documentation/dir_339e8c1d13ed9d171a31356d80f51341.html b/extras/documentation/dir_339e8c1d13ed9d171a31356d80f51341.html index 30d6c39..311dace 100644 --- a/extras/documentation/dir_339e8c1d13ed9d171a31356d80f51341.html +++ b/extras/documentation/dir_339e8c1d13ed9d171a31356d80f51341.html @@ -1,7 +1,7 @@ @@ -56,6 +56,11 @@ + diff --git a/extras/documentation/dir_9eb8a1162b9e86c4bf1f8e762bfe83d1.html b/extras/documentation/dir_9eb8a1162b9e86c4bf1f8e762bfe83d1.html index 2c52975..013a2d8 100644 --- a/extras/documentation/dir_9eb8a1162b9e86c4bf1f8e762bfe83d1.html +++ b/extras/documentation/dir_9eb8a1162b9e86c4bf1f8e762bfe83d1.html @@ -1,7 +1,7 @@ @@ -58,6 +58,11 @@ + diff --git a/extras/documentation/functions.html b/extras/documentation/functions.html index ffe321f..a449aec 100644 --- a/extras/documentation/functions.html +++ b/extras/documentation/functions.html @@ -1,7 +1,7 @@ @@ -98,6 +98,11 @@ + diff --git a/extras/documentation/functions_func.html b/extras/documentation/functions_func.html index a5dc999..f8be767 100644 --- a/extras/documentation/functions_func.html +++ b/extras/documentation/functions_func.html @@ -1,7 +1,7 @@ @@ -98,6 +98,11 @@ + diff --git a/extras/documentation/index.html b/extras/documentation/index.html index 4017b85..1393bd4 100644 --- a/extras/documentation/index.html +++ b/extras/documentation/index.html @@ -1,7 +1,7 @@ @@ -67,6 +67,11 @@

Examples

+ diff --git a/library.json b/library.json new file mode 100644 index 0000000..f96db87 --- /dev/null +++ b/library.json @@ -0,0 +1,24 @@ +{ + "name": "ThingSpeak", + "keywords": "iot", + "description": "ThingSpeak Communication Library for Arduino & ESP8266", + "authors": + { + "name": "MathWorks", + "email": "thingspeak@mathworks.com", + "url": "https://www.thingspeak.com/", + "maintainer": true + }, + "repository": + { + "type": "git", + "url": "https://github.com/mathworks/thingspeak-arduino.git" + }, + "examples": [ + "examples/*/*.ino" + ], + "url": "https://www.thingspeak.com/", + "exclude": "extras", + "frameworks": "arduino", + "platforms": "*" +} \ No newline at end of file diff --git a/library.properties b/library.properties index 574b28f..b21a29d 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=ThingSpeak -version=1.1.0 +version=1.1.1 author=MathWorks maintainer=MathWorks sentence=ThingSpeak Communication Library for Arduino & ESP8266 diff --git a/src/ThingSpeak.h b/src/ThingSpeak.h index 6dad1f8..9be667d 100644 --- a/src/ThingSpeak.h +++ b/src/ThingSpeak.h @@ -7,7 +7,7 @@ ThingSpeak ( https://www.thingspeak.com ) is a free IoT service for building systems that collect, analyze, and react to their environments. - Copyright 2015, The MathWorks, Inc. + Copyright 2016, The MathWorks, Inc. See the accompaning licence file for licensing information. */ @@ -377,7 +377,7 @@ class ThingSpeakClass #ifdef PRINT_DEBUG_MESSAGES #ifdef SPARK - Spark.publish(SPARK_PUBLISH_TOPIC, "writeField (" + String(channelNumber) + ", " + String(writeAPIKey) + ", " + String(field) + ", " + String(value) + ")", SPARK_PUBLISH_TTL, PRIVATE); + Particle.publish(SPARK_PUBLISH_TOPIC, "writeField (" + String(channelNumber) + ", " + String(writeAPIKey) + ", " + String(field) + ", " + String(value) + ")", SPARK_PUBLISH_TTL, PRIVATE); #else 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("\")"); #endif @@ -581,7 +581,7 @@ class ThingSpeakClass { #ifdef PRINT_DEBUG_MESSAGES #ifdef SPARK - Spark.publish(SPARK_PUBLISH_TOPIC, "setField " + String(field) + " to " + String(value), SPARK_PUBLISH_TTL, PRIVATE); + Particle.publish(SPARK_PUBLISH_TOPIC, "setField " + String(field) + " to " + String(value), SPARK_PUBLISH_TTL, PRIVATE); #else Serial.print("ts::setField (field: "); Serial.print(field); Serial.print(" value: \""); Serial.print(value); Serial.println("\")"); #endif @@ -876,7 +876,7 @@ class ThingSpeakClass #ifdef PRINT_DEBUG_MESSAGES #ifdef SPARK - Spark.publish(SPARK_PUBLISH_TOPIC, "Post " + postMessage, SPARK_PUBLISH_TTL, PRIVATE); + Particle.publish(SPARK_PUBLISH_TOPIC, "Post " + postMessage, SPARK_PUBLISH_TTL, PRIVATE); #else Serial.print(" POST \"");Serial.print(postMessage);Serial.println("\""); #endif @@ -1322,7 +1322,7 @@ class ThingSpeakClass // Connect to the server on port 80 (HTTP) at the URL address #ifdef PRINT_DEBUG_MESSAGES #ifdef SPARK - Spark.publish(SPARK_PUBLISH_TOPIC, "Attempt Connect to URL " + String(this->customHostName), SPARK_PUBLISH_TTL, PRIVATE); + Particle.publish(SPARK_PUBLISH_TOPIC, "Attempt Connect to URL " + String(this->customHostName), SPARK_PUBLISH_TTL, PRIVATE); #else Serial.print(" Connect to ");Serial.print(this->customHostName);Serial.print(" ..."); #endif @@ -1335,7 +1335,7 @@ class ThingSpeakClass if (connectSuccess) { #ifdef SPARK - Spark.publish(SPARK_PUBLISH_TOPIC, "Connection Success", SPARK_PUBLISH_TTL, PRIVATE); + Particle.publish(SPARK_PUBLISH_TOPIC, "Connection Success", SPARK_PUBLISH_TTL, PRIVATE); #else Serial.println("Success."); #endif @@ -1343,7 +1343,7 @@ class ThingSpeakClass else { #ifdef SPARK - Spark.publish(SPARK_PUBLISH_TOPIC, "Connection Failure", SPARK_PUBLISH_TTL, PRIVATE); + Particle.publish(SPARK_PUBLISH_TOPIC, "Connection Failure", SPARK_PUBLISH_TTL, PRIVATE); #else Serial.println("Failed."); #endif @@ -1392,50 +1392,73 @@ class ThingSpeakClass if(!client->find(const_cast("HTTP/1.1"))) { #ifdef PRINT_HTTP - Serial.println("ERROR: Didn't find HTTP/1.1"); - #endif + #ifdef SPARK + Particle.publish(SPARK_PUBLISH_TOPIC, "ERROR: Didn't find HTTP/1.1", SPARK_PUBLISH_TTL, PRIVATE); + #else + Serial.println("ERROR: Didn't find HTTP/1.1"); + #endif + #endif return ERR_BAD_RESPONSE; // Couldn't parse response (didn't find HTTP/1.1) } int status = client->parseInt(); #ifdef PRINT_HTTP - Serial.print("Got Status of ");Serial.println(status); + #ifdef SPARK + Particle.publish(SPARK_PUBLISH_TOPIC, "Got Status of " + String(status), SPARK_PUBLISH_TTL, PRIVATE); + #else + Serial.print("Got Status of ");Serial.println(status); + #endif #endif if(status != OK_SUCCESS) { return status; } - if(!client->find(const_cast("\n\r\n"))) + if(!client->find(const_cast("\r\n"))) { #ifdef PRINT_HTTP - Serial.println("ERROR: Didn't find end of header"); + #ifdef SPARK + Particle.publish(SPARK_PUBLISH_TOPIC, "ERROR: Didn't find end of status line", SPARK_PUBLISH_TTL, PRIVATE); + #else + Serial.println("ERROR: Didn't find end of status line"); + #endif #endif return ERR_BAD_RESPONSE; } #ifdef PRINT_HTTP - Serial.println("Found end of header"); - #endif - #ifndef PRINT_HTTP - client->parseInt(); - #else - long length = client->parseInt(); - Serial.print("Got length of ");Serial.println(length); + #ifdef SPARK + Particle.publish(SPARK_PUBLISH_TOPIC, "Found end of status line", SPARK_PUBLISH_TTL, PRIVATE); + #else + Serial.println("Found end of status line"); + #endif #endif - if(!client->find(const_cast("\r\n"))) + + if(!client->find(const_cast("\n\r\n"))) { #ifdef PRINT_HTTP - Serial.println("ERROR: Didn't find end of length"); + #ifdef SPARK + Particle.publish(SPARK_PUBLISH_TOPIC, "ERROR: Didn't find end of header", SPARK_PUBLISH_TTL, PRIVATE); + #else + Serial.println("ERROR: Didn't find end of header"); + #endif #endif return ERR_BAD_RESPONSE; } #ifdef PRINT_HTTP - Serial.println("Found end of length"); + #ifdef SPARK + Particle.publish(SPARK_PUBLISH_TOPIC, "Found end of header", SPARK_PUBLISH_TTL, PRIVATE); + #else + Serial.println("Found end of header"); + #endif #endif // This is a workaround to a bug in the Spark implementation of String String tempString = client->readStringUntil('\r'); response = tempString; #ifdef PRINT_HTTP - Serial.print("Response: \"");Serial.print(response);Serial.println("\""); + #ifdef SPARK + Particle.publish(SPARK_PUBLISH_TOPIC, "Response: \"" + tempString + "\"", SPARK_PUBLISH_TTL, PRIVATE); + #else + Serial.print("Response: \"");Serial.print(response);Serial.println("\""); + #endif #endif return status; };