Enabled forcing CON packet for observer notifications each 20 packets

This commit is contained in:
Lars Schmertmann 2014-04-30 11:48:37 +02:00 committed by Matthias Kovatsch
parent 386d708b56
commit 351ba413e2
2 changed files with 21 additions and 15 deletions

View file

@ -68,7 +68,7 @@
#define COAP_MAX_OBSERVERS COAP_MAX_OPEN_TRANSACTIONS - 1 #define COAP_MAX_OBSERVERS COAP_MAX_OPEN_TRANSACTIONS - 1
#endif /* COAP_MAX_OBSERVERS */ #endif /* COAP_MAX_OBSERVERS */
/* Interval in seconds in which NON notifies are changed to CON notifies to check client. */ /* Interval in notifies in which NON notifies are changed to CON notifies to check client. */
#define COAP_OBSERVE_REFRESH_INTERVAL 60 #define COAP_OBSERVE_REFRESH_INTERVAL 20
#endif /* ER_COAP_CONF_H_ */ #endif /* ER_COAP_CONF_H_ */

View file

@ -75,8 +75,9 @@ coap_add_observer(uip_ipaddr_t *addr, uint16_t port, const uint8_t *token,
memcpy(o->token, token, token_len); memcpy(o->token, token, token_len);
o->last_mid = 0; o->last_mid = 0;
PRINTF("Adding observer for /%s [0x%02X%02X]\n", o->url, o->token[0], PRINTF("Adding observer (%u/%u) for /%s [0x%02X%02X]\n",
o->token[1]); list_length(observers_list) + 1, COAP_MAX_OBSERVERS,
o->url, o->token[0], o->token[1]);
list_add(observers_list, o); list_add(observers_list, o);
} }
@ -192,8 +193,12 @@ coap_notify_observers(resource_t *resource)
/*TODO implement special transaction for CON, sharing the same buffer to allow for more observers */ /*TODO implement special transaction for CON, sharing the same buffer to allow for more observers */
if((transaction = if((transaction = coap_new_transaction(coap_get_mid(), &obs->addr, obs->port))) {
coap_new_transaction(coap_get_mid(), &obs->addr, obs->port))) { if (obs->obs_counter % COAP_OBSERVE_REFRESH_INTERVAL == 0) {
PRINTF(" Force Confirmable for\n");
notification->type = COAP_TYPE_CON;
}
PRINTF(" Observer "); PRINTF(" Observer ");
PRINT6ADDR(&obs->addr); PRINT6ADDR(&obs->addr);
PRINTF(":%u\n", obs->port); PRINTF(":%u\n", obs->port);
@ -213,8 +218,6 @@ coap_notify_observers(resource_t *resource)
} }
coap_set_token(notification, obs->token, obs->token_len); coap_set_token(notification, obs->token, obs->token_len);
/* TODO use resource-specific COAP_OBSERVE_REFRESH_INTERVAL for CON to check client interest */
transaction->packet_len = transaction->packet_len =
coap_serialize_message(notification, transaction->packet); coap_serialize_message(notification, transaction->packet);
@ -240,14 +243,17 @@ coap_observe_handler(resource_t *resource, void *request, void *response)
resource->url)) { resource->url)) {
coap_set_header_observe(coap_res, 0); coap_set_header_observe(coap_res, 0);
/* /*
* for demonstration purposes only. A subscription should return the same representation as a normal GET * Following payload is for demonstration purposes only.
* FIXME comment the following command for any real application * A subscription should return the same representation as a normal GET.
* Uncomment if you want an information about the avaiable observers.
*/
/*
* coap_set_payload(coap_res,
* content,
* snprintf(content, sizeof(content), "Added %u/%u",
* list_length(observers_list),
* COAP_MAX_OBSERVERS));
*/ */
coap_set_payload(coap_res,
content,
snprintf(content, sizeof(content), "Added %u/%u",
list_length(observers_list),
COAP_MAX_OBSERVERS));
} else { } else {
coap_res->code = SERVICE_UNAVAILABLE_5_03; coap_res->code = SERVICE_UNAVAILABLE_5_03;
coap_set_payload(coap_res, "TooManyObservers", 16); coap_set_payload(coap_res, "TooManyObservers", 16);