Skip to content

Commit

Permalink
Send and receive config message
Browse files Browse the repository at this point in the history
The motivation for this patch is due to the change in the KNoT AMQP API,
which changed the name of config to event and unified the event and
schema messages in a new type of message called config.
The new KNoT AMQP API can be found at
https://github.com/CESARBR/knot-babeltower on the file /docs/events.md,
using the hash 4aa5a91.

This patch makes the following changes:
- Change the API for sending and receiving a config message instead of
a schema;
- Adapts the content of the config message to match the new AMQP API of
KNoT;
- Change the parser to work with the new json messages of the new
KNoT AMQP API.
  • Loading branch information
vitbaq committed Oct 23, 2020
1 parent 41c6a15 commit 1bdb2dd
Show file tree
Hide file tree
Showing 6 changed files with 325 additions and 136 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ KNoT Gateway and KNoT Apps.
To install KNoT Protocol, you have to follow the instructions below:

1. `git clone git@github.com:CESARBR/knot-protocol-source.git`
2. `git checkout 891d01d ` to checkout to a hash on devel branch.
2. `git checkout ead9e66` to checkout to a hash on devel branch.
3. Follow instructions on `README` file


Expand Down
29 changes: 16 additions & 13 deletions src/knot_cloud.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static void knot_cloud_device_free(void *data)
if (unlikely(!device))
return;

l_queue_destroy(device->schema, l_free);
l_queue_destroy(device->config_list, l_free);
l_free(device->id);
l_free(device->uuid);
l_free(device->name);
Expand All @@ -74,15 +74,15 @@ static void knot_cloud_msg_destroy(struct knot_cloud_msg *msg)
}

static void *create_device_item(const char *id, const char *name,
struct l_queue *schema)
struct l_queue *config_list)
{
struct knot_cloud_device *device;

device = l_new(struct knot_cloud_device, 1);
device->id = l_strdup(id);
device->name = l_strdup(name);
device->uuid = l_strdup(id);
device->schema = schema;
device->config_list = config_list;

return device;
}
Expand Down Expand Up @@ -146,7 +146,10 @@ static struct knot_cloud_msg *create_msg(const char *routing_key,
break;
case UNREGISTER_MSG:
case AUTH_MSG:
case SCHEMA_MSG:
break;
case CONFIG_MSG:
msg->list = parser_config_to_list(json_str);
has_err = msg->list ? false : true;
break;
case LIST_MSG:
msg->list = parser_queue_from_json_array(json_str,
Expand Down Expand Up @@ -269,8 +272,8 @@ static int set_knot_cloud_events(const char *id)
l_strdup(MQ_EVENT_DEVICE_UNREGISTERED);
knot_cloud_events[AUTH_MSG] =
l_strdup(binding_key_auth_reply);
knot_cloud_events[SCHEMA_MSG] =
l_strdup(MQ_EVENT_DEVICE_SCHEMA_UPDATED);
knot_cloud_events[CONFIG_MSG] =
l_strdup(MQ_EVENT_DEVICE_CONFIG_UPDATED);
knot_cloud_events[LIST_MSG] =
l_strdup(binding_key_list_reply);

Expand Down Expand Up @@ -444,20 +447,20 @@ int knot_cloud_auth_device(const char *id, const char *token)
}

/**
* knot_cloud_update_schema:
* knot_cloud_update_config:
*
* Requests cloud to update the device schema.
* Requests cloud to update the device config.
* The confirmation that the cloud received the message comes from a callback
* set in function knot_cloud_read_start with message type SCHEMA_MSG.
* set in function knot_cloud_read_start with message type CONFIG_MSG.
*
* Returns: 0 if successful and a KNoT error otherwise.
*/
int knot_cloud_update_schema(const char *id, struct l_queue *schema_list)
int knot_cloud_update_config(const char *id, struct l_queue *config_list)
{
char *json_str;
int result;

json_str = parser_schema_create_object(id, schema_list);
json_str = parser_config_create_object(id, config_list);
if (!json_str)
return KNOT_ERR_CLOUD_FAILURE;

Expand All @@ -466,15 +469,15 @@ int knot_cloud_update_schema(const char *id, struct l_queue *schema_list)
* Type: Direct
* Name: device
* Routing Key
* Name: device.schema.sent
* Name: device.config.sent
* Headers
* [0]: User Token
* Expiration
* 2000 ms
*/
mq_message_data_t mq_message = {
MQ_MESSAGE_TYPE_DIRECT,
MQ_EXCHANGE_DEVICE, MQ_CMD_SCHEMA_SENT,
MQ_EXCHANGE_DEVICE, MQ_CMD_CONFIG_SENT,
MQ_MSG_EXPIRATION_TIME_MS, json_str,
NULL, NULL
};
Expand Down
6 changes: 3 additions & 3 deletions src/knot_cloud.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct knot_cloud_device {
char *uuid;
char *name;
bool online;
struct l_queue *schema;
struct l_queue *config_list;
struct l_timeout *unreg_timeout;
};

Expand All @@ -42,7 +42,7 @@ struct knot_cloud_msg {
REGISTER_MSG,
UNREGISTER_MSG,
AUTH_MSG,
SCHEMA_MSG,
CONFIG_MSG,
LIST_MSG,
MSG_TYPES_LENGTH
} type;
Expand All @@ -61,7 +61,7 @@ int knot_cloud_set_log_priority(int priority);
int knot_cloud_register_device(const char *id, const char *name);
int knot_cloud_unregister_device(const char *id);
int knot_cloud_auth_device(const char *id, const char *token);
int knot_cloud_update_schema(const char *id, struct l_queue *schema_list);
int knot_cloud_update_config(const char *id, struct l_queue *config_list);
int knot_cloud_list_devices(void);
int knot_cloud_publish_data(const char *id, uint8_t sensor_id,
uint8_t value_type, const knot_value_type *value,
Expand Down
4 changes: 2 additions & 2 deletions src/mq.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

#define MQ_EVENT_DEVICE_REGISTERED "device.registered"
#define MQ_EVENT_DEVICE_UNREGISTERED "device.unregistered"
#define MQ_EVENT_DEVICE_SCHEMA_UPDATED "device.schema.updated"
#define MQ_EVENT_DEVICE_CONFIG_UPDATED "device.config.updated"

#define MQ_EVENT_AUTH_REPLY "thingd-auth-reply"
#define MQ_EVENT_LIST_REPLY "thingd-list-reply"
Expand All @@ -45,7 +45,7 @@
#define MQ_CMD_DEVICE_REGISTER "device.register"
#define MQ_CMD_DEVICE_UNREGISTER "device.unregister"
#define MQ_CMD_DEVICE_AUTH "device.auth"
#define MQ_CMD_SCHEMA_SENT "device.schema.sent"
#define MQ_CMD_CONFIG_SENT "device.config.sent"
#define MQ_CMD_DEVICE_LIST "device.list"

#define MQ_DEFAULT_CORRELATION_ID "default-corrId"
Expand Down
Loading

0 comments on commit 1bdb2dd

Please sign in to comment.