Hi
I am using nRF9160dk board.
I started with the aws_iot example, compiling it within VS Code.
I set up my board as a ‘thing’ in Amazon’s AWS, along with policy, certificates etc.
I will explain an issue I am having, however I will probably use the wrong terminology etc., because I am relatively new to using Nordic, and just as new to Amazon AWS.
Using AWS’s MQTT Test Client, I subscribed to all topics from my board, and I could see that I received the following two topics every 60 seconds:
$aws/things/my-nRF9160dk_thing01/shadow/update
and
$aws/things/my-nRF9160dk_thing01/shadow/update/accepted
All good so far…
The next thing I wanted to do was publish a change of value, using the MQTT Test Client in AWS
So I entered the following:
Topic name:
$aws/things/imme-nRF9160dk_thing01_eu/shadow/update
Message payload:
{
"state": {
"desired": {
"batv": 123
}
}
}
Immediately, I can see on the board’s NRF Terminal output that this message was received, as the board received the following topic:
$aws/things/my-nRF9160dk_thing01/shadow/update/delta
along with the new batv desired value
Still good so far…
The next thing I wanted to do, and this is where |I am struggling, is to parse this received JSON delta topic, and just extract the new value for batv
I added additional code to the print_received_data() function in the aws_iot application:
const cJSON * batVal = NULL; // <-- added this
root_obj = cJSON_Parse(buf);
if (root_obj == NULL) {
printk("cJSON Parse failure");
return;
}
str = cJSON_Print(root_obj);
if (str == NULL) {
printk("Failed to print JSON object");
goto clean_exit;
}
batVal = cJSON_GetObjectItemCaseSensitive(root_obj, "batv"); // <-- added this
However, I think I might be using this function call incorrectly, because I seem to get nothing back.
Any of the following calls, return false:
if (cJSON_IsInvalid(batVal)
if (cJSON_IsFalse (batVal)
if (cJSON_IsTrue (batVal)
if (cJSON_IsNull (batVal)
if (cJSON_IsNumber (batVal)
if (cJSON_IsString (batVal)
if (cJSON_IsArray (batVal)
if (cJSON_IsRaw (batVal)
If anyone can understand this post can you spot what I am doing wrong?
Thanks
Garrett