Hi guys,
I am using Spark Interval Timer library and MQTT library to control publishing interval.
But in the interrupt function, the MQTT publish function can’t act then the entire code is stopped.
Then the photon blink stops(light blue)
Here is my entire code
#include "SparkIntervalTimer.h"
#include "MQTT.h"
// Declare timer class
IntervalTimer myTimer;
char buf[250];
void callback(char* topic, byte* payload, unsigned int length);
void interruptFunc();
// Set the server domain and port
MQTT client("quickstart.messaging.internetofthings.ibmcloud.com", 1883, callback);
void setup() {
delay(5000);
Serial.begin(9600);
pinMode(A0,INPUT);
// connect to the server
client.connect("d:quickstart:Photon:00FFBBCCDE10");
Serial.println("Connected");
myTimer.begin(interruptFunc,2000,hmSec);
}
// recieve message
void callback(char* topic, byte* payload, unsigned int length) {
}
// Interrupt Function
void interruptFunc(){
sprintf(buf, "{\"d\":{\"myName\":\"Photon\",\"potentiometer\": %d }}", analogRead(A0));
client.publish("iot-2/evt/status/fmt/json",buf);
}
void loop(void) {
if (client.isConnected()) {
}
else {
Serial.println("Disconnected");
client.connect("d:quickstart:Photon:00FFBBCCDE10");
}
}
I think something is crashed between Interval Timer function and MQTT publish function.
What do you think about this problem?