I am using an Adafruit MAX31855 thermocouple breakout board to read temperature values to my Photon. The Photon then publishes the values to the cloud so that I can view them. Additionally, the values are being converted to a string, then webhooked to the Thingspeak website. I am having issues where my temp sensor is publishing correct temp values, but the webhook is publishing zero values.
Here is a picture of the event logs:
You can see that the temp sensor has normal values, but the webhook is still zero.
Below is my code:
#include "math.h"
#include "Adafruit_MAX31855.h"
#define publish_cycle 20000 // Only publish every 20 seconds
int thermo1CLK = A3;
int thermo1CS = A2;
int thermo1DO = A4;
int thermo2CLK = D4;
int thermo2CS = D5;
int thermo2DO = D3;
double c; // Temp 1
double v; // Temp 2
unsigned long lastPublish = 0;
unsigned long TIME;
const String key = "NUMBERS"; //ThinkSpeak Key (removed for privacy)
Adafruit_MAX31855 thermocouple1(thermo1CLK, thermo1CS, thermo1DO);
Adafruit_MAX31855 thermocouple2(thermo2CLK, thermo2CS, thermo2DO);
void setup() {
Serial.begin(9600);
Serial.println("Templogger Output");
// wait for MAX chip to stabilize
delay(500);
}
void loop() {
TIME = millis();
///////////////////////////////////////////////////////
// Temperature 1 //
///////////////////////////////////////////////////////
c = thermocouple1.readFarenheit();
//String x = String(thermocouple1.readInternal());
//Particle.publish("temperature internal 1", x);
if (isnan(c)) {
Serial.println("Something wrong with thermocouple!");
} else {
Serial.print("temperature one = ");
Serial.println(c);
String temp1 = String(c);
Particle.variable("temp1", c);
Particle.publish("temperature one", temp1);
}
///////////////////////////////////////////////////////
// Temperature 2 //
///////////////////////////////////////////////////////
v = thermocouple2.readFarenheit();
//String y = String(thermocouple2.readInternal());
//Particle.publish("temperature internal 2", y);
if (isnan(v)) {
Serial.println("Something wrong with thermocouple!");
} else {
Serial.print("temperature two = ");
Serial.println(v);
String temp2 = String(v);
Particle.variable("temp2", v);
Particle.publish("temperature two", temp2);
}
// Publish to thinkspeak
if (((TIME - lastPublish) > publish_cycle)) {
Serial.println("Wedhook!!");
Particle.publish("thingSpeakWrite_All", "{ \"1\": \"" + String(c,2) + "\"," + "\"2\": \"" + String(v,2) + "\"," + "\"k\": \"" + key + "\" }", 60, PRIVATE);
lastPublish = TIME;
}
delay(5000);
}
Please let me know if you have any ideas as to why the webhook is doing this. Thanks!