Skip to content

Commit

Permalink
added periodic lwm2m registration
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuelsearch committed Oct 11, 2017
1 parent 56716bb commit 29b31e4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion examples/javascript/lwm2m.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ void lwm2m_register(void)
gcoap_req_init(&pdu, &buf[0], GCOAP_PDU_BUF_SIZE, 2, "/rd");
gcoap_add_qstring(&pdu, "b", "U");
gcoap_add_qstring(&pdu, "lwm2m", "1.0");
gcoap_add_qstring(&pdu, "lt", "7200");
gcoap_add_qstring(&pdu, "lt", "200");
gcoap_add_qstring(&pdu, "ep", device_id);
memcpy(pdu.payload, lwm2m_resources, strlen(lwm2m_resources));
len = gcoap_finish(&pdu, strlen(lwm2m_resources), COAP_FORMAT_TEXT);
Expand Down
25 changes: 23 additions & 2 deletions examples/javascript/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "xtimer.h"
#include "lwm2m.h"
#include "js.h"
#include "thread.h"

/* include headers generated from *.js */
#include "lib.js.h"
Expand All @@ -35,6 +36,7 @@
static event_queue_t event_queue;

char script[2048];
char lwm2mkeepalive[100];

#define MAIN_QUEUE_SIZE (4)
static msg_t _main_msg_queue[MAIN_QUEUE_SIZE];
Expand Down Expand Up @@ -72,6 +74,20 @@ void js_restart(void)
js_shutdown(&js_start_event);
}

void *lwm2mkeepalive_handler(void *arg)
{
/* remove warning unused parameter arg */
(void)arg;

lwm2m_init();

while(1) {
lwm2m_register();
xtimer_sleep(180);
}
return NULL;
}

int main(void)
{
msg_init_queue(_main_msg_queue, MAIN_QUEUE_SIZE);
Expand All @@ -87,8 +103,13 @@ int main(void)

/* register to LWM2M server */
puts("initializing coap, registering at lwm2m server");
lwm2m_init();
lwm2m_register();

/* launch lwm2m registration & keepalive thread */
thread_create(lwm2mkeepalive, sizeof(lwm2mkeepalive),
THREAD_PRIORITY_MAIN - 1,
THREAD_CREATE_STACKTEST,
lwm2mkeepalive_handler,
NULL, "lwm2m keepalive");

puts("setting up event queue");
event_queue_init(&event_queue);
Expand Down

0 comments on commit 29b31e4

Please sign in to comment.