Skip to content

LWM2M Standalone

Joakim Eriksson edited this page Nov 20, 2016 · 1 revision

LWM2M Standalone

The LWM2M Standalone is an effort to make it possible to use CoAP and LWM2M without using uIP. This is useful in the case when using LWM2M over SMS or other non-IP based communication.

Needed changes

  • Removing processes from CoAP and LWM2M - this is done by changing the processes to periodic callback or regular callbacks depending what the process made use of.
  • Replacing all e-timers, etc with periodic callbacks and a Network timer.
  • Replacing the hard connection to uIP for sending / receiving data, handling IP addresses, etc.
  • Creating more clean and separated ip-buf and ip-address modules
  • Examples of how to use CoAP and LWM2M both over uIP and serial communication (e.g. for configuring slip radio or similar).

Requirement for supporting standalone CoAP and LWM2M

  • periodic calls into a timer subsystem (the ntimer or network timer)
  • handling input/output of the CoAP / LWM2M payload

Current status

  • Initial effort to remove hard dependency to uip_buf
  • All processes, e-timers and other process and protothread oriented code removed or moved out to separat parts.
  • CoAP Transport API defined and implemented for incoming and outgoing data to/from CoAP
  • New CoAP callback API for clients not using a process.
  • Example of how to use the standalone CoAP/LWM2M code in examples/oma-lwm2m/standalone which make use of a regular IPv4 connection for the IP-parts (illustrating that it is no longer bound to uIP). And another example with text-based in/output (hex-dump).

Needed by implementations for any other transport then uIP.

  1. The network timer (ntimer) needs to have a full implementation in order to keep all periodic activities working in CoAP and LWM2M. There is an example implementation in examples/oma-lwm2m that show how to implement ntimer on linux.
  typedef struct {
    void     (* init)(void);
    uint64_t (* uptime)(void);
    void     (* update)(void);
  } ntimer_driver_t;
  1. The coap_endpoint needs to be implemented (support for the addressing using this specific transport)
/* Copy the information in an endpoint */
void coap_endpoint_copy(coap_endpoint_t *destination,
                        const coap_endpoint_t *from);

/* Compare two endpoints */
int coap_endpoint_cmp(const coap_endpoint_t *e1, const coap_endpoint_t *e2);

/* Print the content of an endpoint */
void coap_endpoint_print(const coap_endpoint_t *ep);

/* Parse a string to an endpoint */
int coap_endpoint_parse(const char *text, size_t size, coap_endpoint_t *ep)
  1. Finally there is need for a coap_transport
/* Initialisation of the transport */
void coap_transport_init(void);

/* send a CoAP message to a specified endpoint */
void coap_send_message(const coap_endpoint_t *ep, const uint8_t *data,
                       uint16_t length);

/* Get the data-buffer for reception of packets */
uint8_t *coap_databuf(void);

/* Get length of the data in the buffer */
uint16_t coap_datalen(void);

/* Get the endpoint of a received CoAP packet */
const coap_endpoint_t *coap_src_endpoint(void);

Note that the CoAP transport also needs to call coap_receive() when a packet arrived. Typically this will be like:

  coap_receive(coap_src_endpoint(), coap_databuf(), coap_datalen());

Testing

Running the OMA LWM2M example

Start the stand-alone example by doing the following:

cd contiki/exampls/oma-lwm2m/standalone
make
./lwm2m-example

The example application will start a CoAP server listening on localhost port 5683 with an example OMA LWM2M device object.

To test that the LWM2M standalone can produce data the Copper (Cu) Firefox addon can be used to access the LWM2M objects.

  1. Start the OMA LWM2M example as described above.

  2. Get the Copper (Cu) CoAP user-agent from https://addons.mozilla.org/en-US/firefox/addon/copper-270430.

  3. Start Copper and discover resources at coap://127.0.0.1:5683/ It should find three objects named 0, 1, and 3.

  4. Browse to the device type resource at coap://127.0.0.1:5683/3/0/17 (object 3, instance 0, resource 17) and then click GET. As device type the LWM2M example should return the text "lwm2m-example".

  5. Browse to the time resource at coap://127.0.0.1:5683/3/0/13 Every time you click GET, it should return the number of seconds since the example application was started.

Moving the example outside Contiki

cd contiki/examples/oma-lwm2m/standalone
make copy

Copy the example directory contents to a directory outside Contiki. Remove the Makefile Makefile.contiki and the remaining Makefile will compile the example independent of the Contiki source tree.