-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from CreatorKit/dev
Merge dev to master
- Loading branch information
Showing
3 changed files
with
340 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
PACKAGES_DIR=../../packages | ||
LWM2M_DIR=$(PACKAGES_DIR)/AwaLWM2M | ||
CONTIKI_PROJECT=lwm2m-client-motion-sensor | ||
VERSION?=$(shell git describe --abbrev=4 --dirty --always --tags) | ||
CONTIKI=../../constrained-os/contiki | ||
CONTIKI_WITH_IPV6 = 1 | ||
CONTIKI_WITH_RPL = 0 | ||
|
||
MOTION_CLICK = motion-click | ||
|
||
CFLAGS += -fno-short-double | ||
LDFLAGS += -Wl,--defsym,_min_heap_size=64000 | ||
|
||
CFLAGS += -DMOTION_CLICK | ||
CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\" -DVERSION='\"$(VERSION)\"' | ||
CFLAGS += -Wall -Wno-pointer-sign -DLWM2M_CLIENT | ||
CFLAGS += -I$(LWM2M_DIR)/api/include | ||
|
||
APPS += er-coap | ||
APPS += rest-engine | ||
APPS += client | ||
APPS += common | ||
APPS += jsmn | ||
APPS += b64 | ||
APPS += hmac | ||
APPS += libobjects | ||
APPS += motion-click | ||
|
||
ifeq ($(TARGET),minimal-net) | ||
APPS += xml | ||
endif | ||
|
||
APPDIRS += $(LWM2M_DIR)/lib | ||
APPDIRS += $(LWM2M_DIR)/core/src | ||
APPDIRS += $(PACKAGES_DIR) | ||
APPDIRS += $(CONTIKI)/platform/mikro-e/dev/ | ||
|
||
all: $(CONTIKI_PROJECT) | ||
xc32-bin2hex $(CONTIKI_PROJECT).$(TARGET) | ||
|
||
distclean: cleanall | ||
|
||
cleanall: | ||
rm -f $(CONTIKI_PROJECT).hex | ||
rm -f symbols.* | ||
|
||
include $(CONTIKI)/Makefile.include |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
/** | ||
* @file | ||
* LightWeightM2M LWM2M client motion sensor 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 <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include "contiki.h" | ||
#include "contiki-net.h" | ||
|
||
#include "lib/sensors.h" | ||
#include "dev/common-clicks.h" | ||
|
||
#include "awa/static.h" | ||
|
||
#include "lwm2m-client-flow-object.h" | ||
#include "lwm2m-client-flow-access-object.h" | ||
#include "lwm2m-client-ipso-presence-sensor.h" | ||
#include "lwm2m-client-device-object.h" | ||
/*************************************************************************************************** | ||
* Definitions | ||
**************************************************************************************************/ | ||
|
||
//! \{ | ||
#define COAP_PORT (6000) | ||
#define IPC_PORT (12345) | ||
#define BOOTSTRAP_PORT "15683" | ||
#define END_POINT_NAME "MotionSensorDevice" | ||
//! \} | ||
|
||
/*************************************************************************************************** | ||
* 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(AwaStaticClient *client) | ||
{ | ||
DefineDeviceObject(client); | ||
DefineFlowObject(client); | ||
DefineFlowAccessObject(client); | ||
DefinePresenceSensorObject(client); | ||
} | ||
|
||
void AwaStaticClient_Start(AwaStaticClient *client) | ||
{ | ||
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"); | ||
AUTOSTART_PROCESSES(&lwm2m_client); | ||
|
||
PROCESS_THREAD(lwm2m_client, ev, data) | ||
{ | ||
PROCESS_BEGIN(); | ||
|
||
PROCESS_PAUSE(); | ||
|
||
printf("Starting LWM2M Client for lwm2m-client-motion-sensor\n"); | ||
|
||
#ifdef RF_CHANNEL | ||
printf("RF channel: %u\n", RF_CHANNEL); | ||
#endif | ||
#ifdef IEEE802154_PANID | ||
printf("PAN ID: 0x%04X\n", IEEE802154_PANID); | ||
#endif | ||
|
||
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 | ||
printf("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 AwaStaticClient *client; | ||
client = AwaStaticClient_New(); | ||
AwaStaticClient_Start(client); | ||
|
||
/* Define application-specific events here. */ | ||
SENSORS_ACTIVATE(motion_sensor); | ||
|
||
while(1) | ||
{ | ||
static struct etimer et; | ||
static int WaitTime; | ||
WaitTime = AwaStaticClient_Process(client); | ||
etimer_set(&et, (WaitTime * CLOCK_SECOND) / 1000); | ||
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et) || (ev == sensors_event)); | ||
|
||
if (data == &motion_sensor) | ||
{ | ||
printf("Motion event received\n"); | ||
PresenceSensor_IncrementCounter(client, 0); | ||
} | ||
} | ||
|
||
PROCESS_END(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/** | ||
* @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. */ | ||
/* Depending upon __USE_CC2520__ or __USE_CA8210__, | ||
this is defined as nullrdc_driver or nullrdc_noframer_driver , | ||
so commenting out from here. | ||
#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:0100::1" | ||
|
||
#endif /* __PROJECT_LWM2M_CONF_H__ */ |