Hi. I am new to ubidots and am trying to write a simple actuator program. I have an Intel Edison board, and I am programming using Eclipse IDE. I am using Paho MQTT library and APIs. So far I have been able to connect to the dashboard and can publish data. Now I want to simulate actuation, where if my data reaches 50, a buzzer = 1 event should be sent to my device.
In my dashboard, I have created 2 variables. dummy which stores the published data and buzzer. I have created an event that when dummy = 50, buzzer = 1. This is also reflecting in the dashboard. But the notification is not received by my program.
In my code, I have registered callback, subscribed to variable and also implemented the callback function. Yet my callback is not being invoked.
code snippet:
#define MESSAGE_TOPIC "/v1.6/devices/dummy_db"
#define TOPIC "/v1.6/devices/dummy_db/#"
main()
{
MQTTClient_setCallbacks(client, NULL,
&connection_lost, &message_arrived, &delivery_complete);
data.username = const_cast<char *>(ubidots_username);
data.password = NULL;
rc = MQTTClient_connect(client, &data);
if (rc != MQTTCLIENT_SUCCESS) {
std::cerr << "Failed to connect MQTT client, exiting :" << rc <<std::endl;
exit(rc);
}
rc = MQTTClient_subscribe(client, const_cast<char *>(TOPIC), MQTT_DEFAULT_QOS);
if (rc != MQTTCLIENT_SUCCESS) {
std::cerr << "Failed to subscribe, exiting :" << rc <<std::endl;
exit(rc);
}
for(;;)
{
//publish dummy data
int rc = MQTTClient_publish(client, const_cast<char *>(MESSAGE_TOPIC), message_size,
const_cast<char *>(payload), MQTT_DEFAULT_QOS, retained, &dt);
}
}
int message_arrived(void * context, char * topic, int topic_len, MQTTClient_message * message)
{
int i;
char* payloadptr;
printf("inside function message arrived\n");
printf("Message arrived\n");
printf("topic: %s\n", topic);
printf("message : ");
payloadptr = (char *)message->payload;
for(i=0; i<(int)message->payloadlen; i++)
{
putchar(*payloadptr++);
}
putchar('\n');
MQTTClient_freeMessage(&message);
MQTTClient_free(topic);
return true;
}