Hardware: arduino mkr nb1500
Library: GitHub - mjksinc/TIC2019: Code repo for connecting MKRNB 1500 device to Azure IoT Hub as part of the Telstra Innovation Challenge 2019
Cloud: azure iot central
Using the code from the library i am able to send data from device to cloud. Now i am trying to send data from cloud to device to change a threshold value remotely.
In the code setup the following function is created, which print some stuff when a message is received:
// Set the message callback, this function is
// called when the MQTTClient receives a message
mqttClient.onMessage(onMessageReceived);
/*
Handles the messages received through the subscribed topic and prints to Serial
*/
void onMessageReceived(int messageSize) {
String topic = mqttClient.messageTopic();
// when receiving a message, print out the topic and contents
Serial.print("Received a message with topic '");
Serial.print(topic);
Serial.print("', length ");
Serial.print(messageSize);
Serial.println(" bytes:");
// use the Stream interface to print the contents
while (mqttClient.available()) {
Serial.print((char)mqttClient.read());
}
Serial.println();
// Responds with confirmation to direct methods and IoT Central commands
if (topic.startsWith(F("$iothub/methods"))) {
String msgId = topic.substring(topic.indexOf("$rid=") + 5);
String responseTopic = "$iothub/methods/res/200/?$rid=" + msgId; //Returns a 200 received message
mqttClient.beginMessage(responseTopic);
mqttClient.print("");
mqttClient.endMessage();
}
}
When connecting the device to the MQTT broker the following code can be used to subscribe to a topic:
// subscribe to a topic
mqttClient.subscribe("devices/" + deviceId + "/messages/devicebound/#"); //This is for cloud-to-device messages
mqttClient.subscribe("$iothub/methods/POST/#"); //This is for direct methods + IoT Central commands
I would like to subscribe to the topic: testVal. I tried several options, but none of them work.
// subscribe to a topic
mqttClient.subscribe("devices/" + deviceId + "/messages/devicebound/testVal"); //This is for cloud-to-device messages
mqttClient.subscribe("devices/" + deviceId + "/messages/devicebound/#testVal"); //This is for cloud-to-device messages
mqttClient.subscribe("devices/" + deviceId + "/messages/devicebound/{\"testVal\"}"); //This is for cloud-to-device messages
In the azure iot cloud i am sending the job as shown below:
Does someone know what i am doing wrong?
Thanks in advance!