-
Notifications
You must be signed in to change notification settings - Fork 2
Twin Implementation #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -325,11 +325,19 @@ static void mqtt_evt_handler(struct mqtt_client *const c, | |
| printk("MQTT PUBLISH result=%d len=%d\n", evt->result, p->message.payload.len); | ||
| err = get_event_payload(c, p->message.payload.len); | ||
| if (err >= 0) { | ||
|
|
||
| if (config->data_cb) { | ||
| config->data_cb(payload_buf, p->message.payload.len, p->message.topic.topic.utf8); | ||
| if(! strncmp(p->message.topic.topic.utf8,"$iothub/twin/res/",17)){ | ||
| if (config->twin_cb) { | ||
| config->twin_cb(payload_buf, p->message.payload.len, p->message.topic.topic.utf8); | ||
| } else { | ||
| printk("Error: no mqtt twin_cb configured\n"); | ||
| } | ||
| } else{ | ||
| if (config->data_cb) { | ||
| config->data_cb(payload_buf, p->message.payload.len, p->message.topic.topic.utf8); | ||
| } else { | ||
| printk("Error: no mqtt data_cb configured\n"); | ||
| printk("Error: no mqtt data_cb configured\n"); | ||
| } | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this be properly indented to avoid confusion of the double braces back to back. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated in the above latest commit. |
||
| } | ||
|
|
||
| } else { | ||
|
|
@@ -434,22 +442,22 @@ bool iotc_nrf_mqtt_init(IotconnectMqttConfig *c, IotclSyncResponse *sr) { | |
| config = c; | ||
|
|
||
| if (!client_init()) { | ||
| return false; | ||
| return -1; | ||
| } | ||
|
|
||
| err = mqtt_connect(&client); | ||
| if (err != 0) { | ||
| printk("ERROR: mqtt_connect %d\n", err); | ||
| return false; | ||
| return -2; | ||
| } | ||
|
|
||
| err = fds_init(&client); | ||
| if (err != 0) { | ||
| printk("ERROR: fds_init %d\n", err); | ||
| return false; | ||
| return -3; | ||
| } | ||
|
|
||
| return true; | ||
| return 1; | ||
|
|
||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,7 @@ | |
| #include "led_pwm.h" | ||
| #else | ||
| #define ui_leds_init() | ||
| #define ui_led_set_rgb(a,b,c) (void) (a,b,c) | ||
| #define ui_led_set_rgb(a,b,c) | ||
|
||
| #endif | ||
| #include <power/reboot.h> | ||
| #include <dfu/mcuboot.h> | ||
|
|
@@ -189,6 +189,28 @@ static void on_ota(IotclEventData data) { | |
| } | ||
| } | ||
|
|
||
| static void TwinUpdateCallback(IotclEventData payload) | ||
| { | ||
|
|
||
| TwinStrings* result = getTwinStrings(payload); | ||
|
|
||
| /* | ||
| Type : Public Method "updateTwin()" | ||
| Usage : Upate the twin reported property | ||
| Output : | ||
| Input : "key" and "value" as below | ||
| // String key = "<< Desired property key >>"; // Desired proeprty key received from Twin callback message | ||
| // String value = "<< Desired Property value >>"; // Value of respective desired property | ||
| */ | ||
| UpdateTwin(result->key,result->value); | ||
|
|
||
| // Don't forget to free the allocated memory | ||
| free(result); | ||
|
|
||
| } | ||
|
|
||
|
|
||
|
|
||
| static void on_command(IotclEventData data) { | ||
| const char *command = iotcl_clone_command(data); | ||
| if (NULL != command) { | ||
|
|
@@ -663,6 +685,7 @@ void main(void) { | |
| config->cmd_cb = on_command; | ||
| config->ota_cb = on_ota; | ||
| config->status_cb = on_connection_status; | ||
| config->twin_msg_rciv = TwinUpdateCallback; | ||
|
|
||
| #pragma clang diagnostic push | ||
| #pragma ide diagnostic ignored "EndlessLoop" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can the same naming conventions as the other callback be followed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2e1de91
updated in the above latest commit.