From c97091a2a32c11721bd338f40e2c8250a83783a9 Mon Sep 17 00:00:00 2001 From: Rahul Daga Date: Fri, 11 Mar 2016 20:16:45 +0530 Subject: [PATCH 1/6] add flow_button_sensor application Signed-off-by: Rahul Daga --- Makefile | 46 ++++++++ lwm2m-client-contiki-button.c | 200 ++++++++++++++++++++++++++++++++++ project-conf.h | 112 +++++++++++++++++++ 3 files changed, 358 insertions(+) create mode 100644 Makefile create mode 100644 lwm2m-client-contiki-button.c create mode 100644 project-conf.h diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..d526c45 --- /dev/null +++ b/Makefile @@ -0,0 +1,46 @@ +PACKAGES_DIR=../../packages +LWM2M_DIR=$(PACKAGES_DIR)/AwaLWM2M +CONTIKI_PROJECT=lwm2m-client-contiki-button +VERSION?=$(shell git describe --abbrev=4 --dirty --always --tags) +CONTIKI=../../constrained-os/contiki +CONTIKI_WITH_IPV6 = 1 +CONTIKI_WITH_RPL = 0 + +CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\" -DVERSION='$(VERSION)' +CFLAGS += -Wall -Wno-pointer-sign -DLWM2M_CLIENT +CFLAGS += -I$(LWM2M_DIR)/core/src/common +CFLAGS += -I$(LWM2M_DIR)/core/src/client +CFLAGS += -I$(LWM2M_DIR)/core/src + +ifneq (,$(filter $(TARGET),seedeye mikro-e)) + CFLAGS += -fno-short-double + LDFLAGS += -Wl,--defsym,_min_heap_size=64000 +endif + +APPS += er-coap +APPS += rest-engine +APPS += client +APPS += common +APPS += jsmn +APPS += b64 +APPS += hmac +APPS += libobjects + +ifeq ($(TARGET),minimal-net) + APPS += xml +endif + +APPDIRS += $(LWM2M_DIR)/lib +APPDIRS += $(LWM2M_DIR)/core/src +APPDIRS += $(PACKAGES_DIR) + +all: $(CONTIKI_PROJECT) + xc32-bin2hex $(CONTIKI_PROJECT).$(TARGET) + +distclean: cleanall + +cleanall: + rm -f $(CONTIKI_PROJECT).hex + rm -f symbols.* + +include $(CONTIKI)/Makefile.include diff --git a/lwm2m-client-contiki-button.c b/lwm2m-client-contiki-button.c new file mode 100644 index 0000000..8ea6b4a --- /dev/null +++ b/lwm2m-client-contiki-button.c @@ -0,0 +1,200 @@ +/** + * @file + * LightWeightM2M LWM2M client button application. + * + * @author Imagination Technologies + * + * @copyright Copyright (c) 2016, Imagination Technologies Limited and/or its affiliated group + * companies and/or licensors. + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions + * and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY + * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/*************************************************************************************************** + * Includes + **************************************************************************************************/ + +#include +#include +#include +#include "contiki.h" +#include "contiki-net.h" + +#include "lib/sensors.h" +#include "button-sensor.h" + +#include "lwm2m_core.h" +#include "lwm2m_object_store.h" +#include "coap_abstraction.h" +#include "client/lwm2m_bootstrap.h" +#include "client/lwm2m_registration.h" +#include "client/lwm2m_device_object.h" +#include "client/lwm2m_security_object.h" +#include "client/lwm2m_server_object.h" + +#include "lwm2m-client-flow-object.h" +#include "lwm2m-client-flow-access-object.h" +#include "lwm2m-client-ipso-digital-input.h" + +/*************************************************************************************************** + * Definitions + **************************************************************************************************/ + +//! \{ +#define COAP_PORT (6000) +#define IPC_PORT (12345) +#define BOOTSTRAP_PORT "15683" +#define END_POINT_NAME "ButtonDevice" +//! \} + +/*************************************************************************************************** + * Typedefs + **************************************************************************************************/ + +/** + * A structure to contain lwm2m client's options. + */ +typedef struct +{ + //! \{ + int CoapPort; + int IpcPort; + bool Verbose; + char * EndPointName; + char * BootStrap; + //! \} +} Options; + +/*************************************************************************************************** + * Globals + **************************************************************************************************/ + +//! \{ + +Options options = +{ + .CoapPort = COAP_PORT, + .IpcPort = IPC_PORT, + .Verbose = true, + .BootStrap = "coap://["BOOTSTRAP_IPv6_ADDR"]:"BOOTSTRAP_PORT"/", + .EndPointName = END_POINT_NAME, +}; + +/*************************************************************************************************** + * Implementation + **************************************************************************************************/ + + +void ConstructObjectTree(Lwm2mContextType * context) +{ + Lwm2m_Debug("Construct object tree\n"); + + Lwm2m_RegisterSecurityObject(context); + if (options.BootStrap != NULL) + { + Lwm2m_PopulateSecurityObject(context, options.BootStrap); + } + Lwm2m_RegisterServerObject(context); + Lwm2m_RegisterDeviceObject(context); + + Lwm2m_RegisterFlowObject(context); + Lwm2m_RegisterFlowAccessObject(context); + + DigitalInput_RegisterDigitalInputObject(context); + DigitalInput_AddDigitialInput(context, 0); + DigitalInput_AddDigitialInput(context, 1); +} + +Lwm2mContextType * Lwm2mClient_Start() +{ + Lwm2m_SetOutput(stdout); + Lwm2m_SetLogLevel((options.Verbose) ? DebugLevel_Debug : DebugLevel_Info); + Lwm2m_PrintBanner(); + Lwm2m_Info("LWM2M client - CoAP port %d\n", options.CoapPort); + Lwm2m_Info("LWM2M client - IPC port %d\n", options.IpcPort); + + CoapInfo * coap = coap_Init("0.0.0.0", options.CoapPort, + (options.Verbose) ? DebugLevel_Debug : DebugLevel_Info); + Lwm2mContextType * context = Lwm2mCore_Init(coap, options.EndPointName); + ConstructObjectTree(context); + + return context; +} + +PROCESS(lwm2m_client, "LwM2M Client"); +AUTOSTART_PROCESSES(&lwm2m_client); + +PROCESS_THREAD(lwm2m_client, ev, data) +{ + PROCESS_BEGIN(); + + PROCESS_PAUSE(); + + Lwm2m_Info("Starting LWM2M Client for flow_button_sensor\n"); + +#ifdef RF_CHANNEL + Lwm2m_Info("RF channel: %u\n", RF_CHANNEL); +#endif +#ifdef IEEE802154_PANID + Lwm2m_Info("PAN ID: 0x%04X\n", IEEE802154_PANID); +#endif + + Lwm2m_Info("uIP buffer: %u\n", UIP_BUFSIZE); + Lwm2m_Info("LL header: %u\n", UIP_LLH_LEN); + Lwm2m_Info("IP+UDP header: %u\n", UIP_IPUDPH_LEN); +#ifdef REST_MAX_CHUNK_SIZE + Lwm2m_Info("REST max chunk: %u\n", REST_MAX_CHUNK_SIZE); +#endif + + uip_ipaddr_t ipaddr; + uip_ip6addr(&ipaddr, BOOTSTRAP_IPv6_ADDR1, BOOTSTRAP_IPv6_ADDR2, BOOTSTRAP_IPv6_ADDR3, + BOOTSTRAP_IPv6_ADDR4, BOOTSTRAP_IPv6_ADDR5, BOOTSTRAP_IPv6_ADDR6, BOOTSTRAP_IPv6_ADDR7, + BOOTSTRAP_IPv6_ADDR8); + uip_ds6_defrt_add(&ipaddr, 0); + + static Lwm2mContextType * context; + + context = Lwm2mClient_Start(); + + /* Define application-specific events here. */ + while(1) + { + static struct etimer et; + static int WaitTime; + WaitTime = Lwm2mCore_Process(context); + etimer_set(&et, (WaitTime * CLOCK_SECOND) / 1000); + PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et) || (ev == sensors_event)); + + if (data == &button_sensor) + { + Lwm2m_Info("Button press event received\n"); + DigitalInput_IncrementCounter(context, 0); + } + } + + PROCESS_END(); +} +//! \} diff --git a/project-conf.h b/project-conf.h new file mode 100644 index 0000000..478ef59 --- /dev/null +++ b/project-conf.h @@ -0,0 +1,112 @@ +/** + * @file + * LightWeightM2M Project Config. + * + * @author Imagination Technologies + * + * @copyright Copyright (c) 2016, Imagination Technologies Limited and/or its affiliated group + * companies and/or licensors. + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions + * and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY + * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __PROJECT_LWM2M_CONF_H__ +#define __PROJECT_LWM2M_CONF_H__ + +/* Custom channel and PAN ID configuration for your project. */ +/* + #define RF_CHANNEL 26 + #define IEEE802154_CONF_PANID 0xABCD + */ + +/* IP buffer size must match all other hops, in particular the border router. */ +/* + #define UIP_CONF_BUFFER_SIZE 256 + */ + +/* Disabling RDC and CSMA for demo purposes. Core updates often + require more memory. */ +/* For projects, optimize memory and enable RDC and CSMA again. */ +#define NETSTACK_CONF_RDC nullrdc_driver + +/* Disabling TCP on CoAP nodes. */ +#define UIP_CONF_TCP 0 + +/* + #define NETSTACK_CONF_MAC nullmac_driver +*/ + +/* Increase rpl-border-router IP-buffer when using more than 64. */ +#define REST_MAX_CHUNK_SIZE 512 + +/* Estimate your header size, especially when using Proxy-Uri. */ +/* + #define COAP_MAX_HEADER_SIZE 70 + */ + +/* Multiplies with chunk size, be aware of memory constraints. */ +#undef COAP_MAX_OPEN_TRANSACTIONS +#define COAP_MAX_OPEN_TRANSACTIONS 4 + +/* Must be <= open transactions, default is COAP_MAX_OPEN_TRANSACTIONS-1. */ +/* + #define COAP_MAX_OBSERVERS 2 + */ + +/* Filtering .well-known/core per query can be disabled to save space. */ +#define COAP_LINK_FORMAT_FILTERING 0 +#define COAP_PROXY_OPTION_PROCESSING 0 + +/* Enable client-side support for COAP observe */ +#define COAP_OBSERVE_CLIENT 1 + +#define UIP_CONF_TCP 0 + +#define UIP_CONF_BUFFER_SIZE 4096 + +/* IP address of device */ +#define GLOBAL_IPv6_ADDR +#define GLOBAL_IPv6_ADDR1 0x2001 +#define GLOBAL_IPv6_ADDR2 0x1418 +#define GLOBAL_IPv6_ADDR3 0x0100 +#define GLOBAL_IPv6_ADDR4 0x823c +#define GLOBAL_IPv6_ADDR5 0x0 +#define GLOBAL_IPv6_ADDR6 0x0 +#define GLOBAL_IPv6_ADDR7 0x0 +#define GLOBAL_IPv6_ADDR8 0x0 + +#define BOOTSTRAP_IPv6_ADDR1 0x2001 +#define BOOTSTRAP_IPv6_ADDR2 0x1418 +#define BOOTSTRAP_IPv6_ADDR3 0x0100 +#define BOOTSTRAP_IPv6_ADDR4 0x0 +#define BOOTSTRAP_IPv6_ADDR5 0x0 +#define BOOTSTRAP_IPv6_ADDR6 0x0 +#define BOOTSTRAP_IPv6_ADDR7 0x0 +#define BOOTSTRAP_IPv6_ADDR8 0x1 + +#define BOOTSTRAP_IPv6_ADDR "2001:1418:100::1" + +#endif /* __PROJECT_LWM2M_CONF_H__ */ From 0146d4a9b2e83fd8420f4000c55b196b261ae621 Mon Sep 17 00:00:00 2001 From: Pratik Prajapati Date: Mon, 21 Mar 2016 18:52:40 +0530 Subject: [PATCH 2/6] update readme with application information Signed-off-by: Pratik Prajapati --- README.md | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4a5ff1e..b0aa9a0 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,14 @@ -# flow_button_sensor -flow button sensor application +#Button Sensor Application + +This application registers Flow, Flow Access and Digital Input object to Flow server and sends Button press events. + +How To Compile + +Assuming you have creator-contiki source code with directories constrained-os, packages/button-sensor, packages/libobjects and packages/AwaLWM2M + +``` +$ cd button-sensor +$ make TARGET=mikro-e +``` + +This will generate hex file which can be flashed onto the MikroE clicker. From 19ce7eb231cae29dbefd70d5b412b9d396d5e075 Mon Sep 17 00:00:00 2001 From: Pratik Prajapati Date: Mon, 21 Mar 2016 19:36:45 +0530 Subject: [PATCH 3/6] change project name and files to lwm2m-client-button-sensor from lwm2m-client-contiki-button Signed-off-by: Pratik Prajapati --- Makefile | 2 +- lwm2m-client-contiki-button.c => lwm2m-client-button-sensor.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename lwm2m-client-contiki-button.c => lwm2m-client-button-sensor.c (98%) diff --git a/Makefile b/Makefile index d526c45..56a79f7 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ PACKAGES_DIR=../../packages LWM2M_DIR=$(PACKAGES_DIR)/AwaLWM2M -CONTIKI_PROJECT=lwm2m-client-contiki-button +CONTIKI_PROJECT=lwm2m-client-button-sensor VERSION?=$(shell git describe --abbrev=4 --dirty --always --tags) CONTIKI=../../constrained-os/contiki CONTIKI_WITH_IPV6 = 1 diff --git a/lwm2m-client-contiki-button.c b/lwm2m-client-button-sensor.c similarity index 98% rename from lwm2m-client-contiki-button.c rename to lwm2m-client-button-sensor.c index 8ea6b4a..779343d 100644 --- a/lwm2m-client-contiki-button.c +++ b/lwm2m-client-button-sensor.c @@ -153,7 +153,7 @@ PROCESS_THREAD(lwm2m_client, ev, data) PROCESS_PAUSE(); - Lwm2m_Info("Starting LWM2M Client for flow_button_sensor\n"); + Lwm2m_Info("Starting LWM2M Client for lwm2m-client-button-sensor\n"); #ifdef RF_CHANNEL Lwm2m_Info("RF channel: %u\n", RF_CHANNEL); From 6f778bc102f7efd4c46d1ce90e75ab7d95741977 Mon Sep 17 00:00:00 2001 From: Mayank Sirotiya Date: Tue, 22 Mar 2016 16:26:59 +0530 Subject: [PATCH 4/6] add revision history in README.md Signed-off-by: Mayank Sirotiya --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index b0aa9a0..204bc6f 100644 --- a/README.md +++ b/README.md @@ -12,3 +12,8 @@ $ make TARGET=mikro-e ``` This will generate hex file which can be flashed onto the MikroE clicker. + +## Revision History +| Revision | Changes from previous revision | +| :---- | :------------------------------| +| 0.9.0 | External Beta Trial Release | From 6b6801680bbe5f9f316137efafa8e4bcdcd67c0d Mon Sep 17 00:00:00 2001 From: Rahul Daga Date: Thu, 7 Apr 2016 13:09:31 +0530 Subject: [PATCH 5/6] add button press simulation Signed-off-by: Rahul Daga --- lwm2m-client-button-sensor.c | 27 +++++++++++++++++++++++++++ project-conf.h | 6 ++++++ 2 files changed, 33 insertions(+) diff --git a/lwm2m-client-button-sensor.c b/lwm2m-client-button-sensor.c index 779343d..890daaa 100644 --- a/lwm2m-client-button-sensor.c +++ b/lwm2m-client-button-sensor.c @@ -145,7 +145,12 @@ Lwm2mContextType * Lwm2mClient_Start() } PROCESS(lwm2m_client, "LwM2M Client"); +#ifndef BUTTON_PRESS_SIMULATION AUTOSTART_PROCESSES(&lwm2m_client); +#else +PROCESS(button_press_simulator, "Button Press Simulator"); +AUTOSTART_PROCESSES(&lwm2m_client, &button_press_simulator); +#endif PROCESS_THREAD(lwm2m_client, ev, data) { @@ -197,4 +202,26 @@ PROCESS_THREAD(lwm2m_client, ev, data) PROCESS_END(); } + +/*---------------------------------------------------------------------------*/ +#ifdef BUTTON_PRESS_SIMULATION +/** + * @brief Simulate button presses periodically (required for automated testing). + */ +PROCESS_THREAD(button_press_simulator, ev, data) +{ + PROCESS_BEGIN(); + static struct etimer button_timer; + int wait_time = BUTTON_PRESS_PERIOD * CLOCK_SECOND; + etimer_set(&button_timer, wait_time); + while(1) { + PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&button_timer)); + process_post(PROCESS_BROADCAST, sensors_event, (void *)&button_sensor); + etimer_reset(&button_timer); + } + PROCESS_END(); +} +#endif + +/*---------------------------------------------------------------------------*/ //! \} diff --git a/project-conf.h b/project-conf.h index 478ef59..9746412 100644 --- a/project-conf.h +++ b/project-conf.h @@ -109,4 +109,10 @@ #define BOOTSTRAP_IPv6_ADDR "2001:1418:100::1" +/* Enable button press simulation */ +/* + #define BUTTON_PRESS_SIMULATION + #define BUTTON_PRESS_PERIOD 5 + */ + #endif /* __PROJECT_LWM2M_CONF_H__ */ From 00f22a47b52ecd67b929109c06c06867803c1827 Mon Sep 17 00:00:00 2001 From: Rahul Daga Date: Tue, 3 May 2016 18:40:11 +0530 Subject: [PATCH 6/6] move to static apis Signed-off-by: Rahul Daga --- Makefile | 6 +-- lwm2m-client-button-sensor.c | 82 ++++++++++++++---------------------- 2 files changed, 33 insertions(+), 55 deletions(-) diff --git a/Makefile b/Makefile index 56a79f7..96c03b3 100644 --- a/Makefile +++ b/Makefile @@ -6,11 +6,9 @@ CONTIKI=../../constrained-os/contiki CONTIKI_WITH_IPV6 = 1 CONTIKI_WITH_RPL = 0 -CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\" -DVERSION='$(VERSION)' +CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\" -DVERSION='\"$(VERSION)\"' CFLAGS += -Wall -Wno-pointer-sign -DLWM2M_CLIENT -CFLAGS += -I$(LWM2M_DIR)/core/src/common -CFLAGS += -I$(LWM2M_DIR)/core/src/client -CFLAGS += -I$(LWM2M_DIR)/core/src +CFLAGS += -I$(LWM2M_DIR)/api/include ifneq (,$(filter $(TARGET),seedeye mikro-e)) CFLAGS += -fno-short-double diff --git a/lwm2m-client-button-sensor.c b/lwm2m-client-button-sensor.c index 890daaa..f824ef9 100644 --- a/lwm2m-client-button-sensor.c +++ b/lwm2m-client-button-sensor.c @@ -46,19 +46,14 @@ #include "lib/sensors.h" #include "button-sensor.h" -#include "lwm2m_core.h" -#include "lwm2m_object_store.h" -#include "coap_abstraction.h" -#include "client/lwm2m_bootstrap.h" -#include "client/lwm2m_registration.h" -#include "client/lwm2m_device_object.h" -#include "client/lwm2m_security_object.h" -#include "client/lwm2m_server_object.h" + +#include "awa/static.h" + #include "lwm2m-client-flow-object.h" #include "lwm2m-client-flow-access-object.h" #include "lwm2m-client-ipso-digital-input.h" - +#include "lwm2m-client-device-object.h" /*************************************************************************************************** * Definitions **************************************************************************************************/ @@ -108,40 +103,24 @@ Options options = **************************************************************************************************/ -void ConstructObjectTree(Lwm2mContextType * context) +void ConstructObjectTree(AwaStaticClient *client) { - Lwm2m_Debug("Construct object tree\n"); - - Lwm2m_RegisterSecurityObject(context); - if (options.BootStrap != NULL) - { - Lwm2m_PopulateSecurityObject(context, options.BootStrap); - } - Lwm2m_RegisterServerObject(context); - Lwm2m_RegisterDeviceObject(context); - - Lwm2m_RegisterFlowObject(context); - Lwm2m_RegisterFlowAccessObject(context); - - DigitalInput_RegisterDigitalInputObject(context); - DigitalInput_AddDigitialInput(context, 0); - DigitalInput_AddDigitialInput(context, 1); + DefineDeviceObject(client); + DefineFlowObject(client); + DefineFlowAccessObject(client); + DefineDigitalInputObject(client); } -Lwm2mContextType * Lwm2mClient_Start() +void AwaStaticClient_Start(AwaStaticClient *client) { - Lwm2m_SetOutput(stdout); - Lwm2m_SetLogLevel((options.Verbose) ? DebugLevel_Debug : DebugLevel_Info); - Lwm2m_PrintBanner(); - Lwm2m_Info("LWM2M client - CoAP port %d\n", options.CoapPort); - Lwm2m_Info("LWM2M client - IPC port %d\n", options.IpcPort); - - CoapInfo * coap = coap_Init("0.0.0.0", options.CoapPort, - (options.Verbose) ? DebugLevel_Debug : DebugLevel_Info); - Lwm2mContextType * context = Lwm2mCore_Init(coap, options.EndPointName); - ConstructObjectTree(context); - - return context; + AwaStaticClient_SetLogLevel((options.Verbose) ? AwaLogLevel_Debug : AwaLogLevel_Warning); + printf("LWM2M client - CoAP port %d\n", options.CoapPort); + printf("LWM2M client - IPC port %d\n", options.IpcPort); + AwaStaticClient_SetEndPointName(client, options.EndPointName); + AwaStaticClient_SetCoAPListenAddressPort(client, "0.0.0.0", options.CoapPort); + AwaStaticClient_SetBootstrapServerURI(client, options.BootStrap); + AwaStaticClient_Init(client); + ConstructObjectTree(client); } PROCESS(lwm2m_client, "LwM2M Client"); @@ -158,20 +137,20 @@ PROCESS_THREAD(lwm2m_client, ev, data) PROCESS_PAUSE(); - Lwm2m_Info("Starting LWM2M Client for lwm2m-client-button-sensor\n"); + printf("Starting LWM2M Client for lwm2m-client-button-sensor\n"); #ifdef RF_CHANNEL - Lwm2m_Info("RF channel: %u\n", RF_CHANNEL); + printf("RF channel: %u\n", RF_CHANNEL); #endif #ifdef IEEE802154_PANID - Lwm2m_Info("PAN ID: 0x%04X\n", IEEE802154_PANID); + printf("PAN ID: 0x%04X\n", IEEE802154_PANID); #endif - Lwm2m_Info("uIP buffer: %u\n", UIP_BUFSIZE); - Lwm2m_Info("LL header: %u\n", UIP_LLH_LEN); - Lwm2m_Info("IP+UDP header: %u\n", UIP_IPUDPH_LEN); + printf("uIP buffer: %u\n", UIP_BUFSIZE); + printf("LL header: %u\n", UIP_LLH_LEN); + printf("IP+UDP header: %u\n", UIP_IPUDPH_LEN); #ifdef REST_MAX_CHUNK_SIZE - Lwm2m_Info("REST max chunk: %u\n", REST_MAX_CHUNK_SIZE); + printf("REST max chunk: %u\n", REST_MAX_CHUNK_SIZE); #endif uip_ipaddr_t ipaddr; @@ -180,23 +159,24 @@ PROCESS_THREAD(lwm2m_client, ev, data) BOOTSTRAP_IPv6_ADDR8); uip_ds6_defrt_add(&ipaddr, 0); - static Lwm2mContextType * context; + static AwaStaticClient *client; + client = AwaStaticClient_New(); + AwaStaticClient_Start(client); - context = Lwm2mClient_Start(); /* Define application-specific events here. */ while(1) { static struct etimer et; static int WaitTime; - WaitTime = Lwm2mCore_Process(context); + WaitTime = AwaStaticClient_Process(client); etimer_set(&et, (WaitTime * CLOCK_SECOND) / 1000); PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et) || (ev == sensors_event)); if (data == &button_sensor) { - Lwm2m_Info("Button press event received\n"); - DigitalInput_IncrementCounter(context, 0); + printf("Button press event received\n"); + DigitalInput_IncrementCounter(client, 0); } }