Skip to content

Commit 61b510c

Browse files
author
Abhijit A. Mahajani
committed
Merge pull request #8 from mayank-sirotiya-imgtec/master
Merge dev to master
2 parents 3019f90 + b02cf23 commit 61b510c

File tree

4 files changed

+388
-2
lines changed

4 files changed

+388
-2
lines changed

Makefile

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
PACKAGES_DIR=../../packages
2+
LWM2M_DIR=$(PACKAGES_DIR)/AwaLWM2M
3+
CONTIKI_PROJECT=lwm2m-client-button-sensor
4+
VERSION?=$(shell git describe --abbrev=4 --dirty --always --tags)
5+
CONTIKI=../../constrained-os/contiki
6+
CONTIKI_WITH_IPV6 = 1
7+
CONTIKI_WITH_RPL = 0
8+
9+
CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\" -DVERSION='\"$(VERSION)\"'
10+
CFLAGS += -Wall -Wno-pointer-sign -DLWM2M_CLIENT
11+
CFLAGS += -I$(LWM2M_DIR)/api/include
12+
13+
ifneq (,$(filter $(TARGET),seedeye mikro-e))
14+
CFLAGS += -fno-short-double
15+
LDFLAGS += -Wl,--defsym,_min_heap_size=64000
16+
endif
17+
18+
APPS += er-coap
19+
APPS += rest-engine
20+
APPS += client
21+
APPS += common
22+
APPS += jsmn
23+
APPS += b64
24+
APPS += hmac
25+
APPS += libobjects
26+
27+
ifeq ($(TARGET),minimal-net)
28+
APPS += xml
29+
endif
30+
31+
APPDIRS += $(LWM2M_DIR)/lib
32+
APPDIRS += $(LWM2M_DIR)/core/src
33+
APPDIRS += $(PACKAGES_DIR)
34+
35+
all: $(CONTIKI_PROJECT)
36+
xc32-bin2hex $(CONTIKI_PROJECT).$(TARGET)
37+
38+
distclean: cleanall
39+
40+
cleanall:
41+
rm -f $(CONTIKI_PROJECT).hex
42+
rm -f symbols.*
43+
44+
include $(CONTIKI)/Makefile.include

README.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,19 @@
1-
# button-sensor
2-
MikroE 6loWPAN Clicker based lwm2m client button sensor application
1+
#Button Sensor Application
2+
3+
This application registers Flow, Flow Access and Digital Input object to Flow server and sends Button press events.
4+
5+
How To Compile
6+
7+
Assuming you have creator-contiki source code with directories constrained-os, packages/button-sensor, packages/libobjects and packages/AwaLWM2M
8+
9+
```
10+
$ cd button-sensor
11+
$ make TARGET=mikro-e
12+
```
13+
14+
This will generate hex file which can be flashed onto the MikroE clicker.
15+
16+
## Revision History
17+
| Revision | Changes from previous revision |
18+
| :---- | :------------------------------|
19+
| 0.9.0 | External Beta Trial Release |

lwm2m-client-button-sensor.c

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
/**
2+
* @file
3+
* LightWeightM2M LWM2M client button application.
4+
*
5+
* @author Imagination Technologies
6+
*
7+
* @copyright Copyright (c) 2016, Imagination Technologies Limited and/or its affiliated group
8+
* companies and/or licensors.
9+
*
10+
* All rights reserved.
11+
*
12+
* Redistribution and use in source and binary forms, with or without modification, are permitted
13+
* provided that the following conditions are met:
14+
*
15+
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
16+
* and the following disclaimer.
17+
*
18+
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
19+
* conditions and the following disclaimer in the documentation and/or other materials provided
20+
* with the distribution.
21+
*
22+
* 3. Neither the name of the copyright holder nor the names of its contributors may be used to
23+
* endorse or promote products derived from this software without specific prior written
24+
* permission.
25+
*
26+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
27+
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
28+
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
29+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
32+
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
33+
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34+
*/
35+
36+
/***************************************************************************************************
37+
* Includes
38+
**************************************************************************************************/
39+
40+
#include <stdio.h>
41+
#include <stdlib.h>
42+
#include <string.h>
43+
#include "contiki.h"
44+
#include "contiki-net.h"
45+
46+
#include "lib/sensors.h"
47+
#include "button-sensor.h"
48+
49+
50+
#include "awa/static.h"
51+
52+
53+
#include "lwm2m-client-flow-object.h"
54+
#include "lwm2m-client-flow-access-object.h"
55+
#include "lwm2m-client-ipso-digital-input.h"
56+
#include "lwm2m-client-device-object.h"
57+
/***************************************************************************************************
58+
* Definitions
59+
**************************************************************************************************/
60+
61+
//! \{
62+
#define COAP_PORT (6000)
63+
#define IPC_PORT (12345)
64+
#define BOOTSTRAP_PORT "15683"
65+
#define END_POINT_NAME "ButtonDevice"
66+
//! \}
67+
68+
/***************************************************************************************************
69+
* Typedefs
70+
**************************************************************************************************/
71+
72+
/**
73+
* A structure to contain lwm2m client's options.
74+
*/
75+
typedef struct
76+
{
77+
//! \{
78+
int CoapPort;
79+
int IpcPort;
80+
bool Verbose;
81+
char * EndPointName;
82+
char * BootStrap;
83+
//! \}
84+
} Options;
85+
86+
/***************************************************************************************************
87+
* Globals
88+
**************************************************************************************************/
89+
90+
//! \{
91+
92+
Options options =
93+
{
94+
.CoapPort = COAP_PORT,
95+
.IpcPort = IPC_PORT,
96+
.Verbose = true,
97+
.BootStrap = "coap://["BOOTSTRAP_IPv6_ADDR"]:"BOOTSTRAP_PORT"/",
98+
.EndPointName = END_POINT_NAME,
99+
};
100+
101+
/***************************************************************************************************
102+
* Implementation
103+
**************************************************************************************************/
104+
105+
106+
void ConstructObjectTree(AwaStaticClient *client)
107+
{
108+
DefineDeviceObject(client);
109+
DefineFlowObject(client);
110+
DefineFlowAccessObject(client);
111+
DefineDigitalInputObject(client);
112+
}
113+
114+
void AwaStaticClient_Start(AwaStaticClient *client)
115+
{
116+
AwaStaticClient_SetLogLevel((options.Verbose) ? AwaLogLevel_Debug : AwaLogLevel_Warning);
117+
printf("LWM2M client - CoAP port %d\n", options.CoapPort);
118+
printf("LWM2M client - IPC port %d\n", options.IpcPort);
119+
AwaStaticClient_SetEndPointName(client, options.EndPointName);
120+
AwaStaticClient_SetCoAPListenAddressPort(client, "0.0.0.0", options.CoapPort);
121+
AwaStaticClient_SetBootstrapServerURI(client, options.BootStrap);
122+
AwaStaticClient_Init(client);
123+
ConstructObjectTree(client);
124+
}
125+
126+
PROCESS(lwm2m_client, "LwM2M Client");
127+
#ifndef BUTTON_PRESS_SIMULATION
128+
AUTOSTART_PROCESSES(&lwm2m_client);
129+
#else
130+
PROCESS(button_press_simulator, "Button Press Simulator");
131+
AUTOSTART_PROCESSES(&lwm2m_client, &button_press_simulator);
132+
#endif
133+
134+
PROCESS_THREAD(lwm2m_client, ev, data)
135+
{
136+
PROCESS_BEGIN();
137+
138+
PROCESS_PAUSE();
139+
140+
printf("Starting LWM2M Client for lwm2m-client-button-sensor\n");
141+
142+
#ifdef RF_CHANNEL
143+
printf("RF channel: %u\n", RF_CHANNEL);
144+
#endif
145+
#ifdef IEEE802154_PANID
146+
printf("PAN ID: 0x%04X\n", IEEE802154_PANID);
147+
#endif
148+
149+
printf("uIP buffer: %u\n", UIP_BUFSIZE);
150+
printf("LL header: %u\n", UIP_LLH_LEN);
151+
printf("IP+UDP header: %u\n", UIP_IPUDPH_LEN);
152+
#ifdef REST_MAX_CHUNK_SIZE
153+
printf("REST max chunk: %u\n", REST_MAX_CHUNK_SIZE);
154+
#endif
155+
156+
uip_ipaddr_t ipaddr;
157+
uip_ip6addr(&ipaddr, BOOTSTRAP_IPv6_ADDR1, BOOTSTRAP_IPv6_ADDR2, BOOTSTRAP_IPv6_ADDR3,
158+
BOOTSTRAP_IPv6_ADDR4, BOOTSTRAP_IPv6_ADDR5, BOOTSTRAP_IPv6_ADDR6, BOOTSTRAP_IPv6_ADDR7,
159+
BOOTSTRAP_IPv6_ADDR8);
160+
uip_ds6_defrt_add(&ipaddr, 0);
161+
162+
static AwaStaticClient *client;
163+
client = AwaStaticClient_New();
164+
AwaStaticClient_Start(client);
165+
166+
167+
/* Define application-specific events here. */
168+
while(1)
169+
{
170+
static struct etimer et;
171+
static int WaitTime;
172+
WaitTime = AwaStaticClient_Process(client);
173+
etimer_set(&et, (WaitTime * CLOCK_SECOND) / 1000);
174+
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et) || (ev == sensors_event));
175+
176+
if (data == &button_sensor)
177+
{
178+
printf("Button press event received\n");
179+
DigitalInput_IncrementCounter(client, 0);
180+
}
181+
}
182+
183+
PROCESS_END();
184+
}
185+
186+
/*---------------------------------------------------------------------------*/
187+
#ifdef BUTTON_PRESS_SIMULATION
188+
/**
189+
* @brief Simulate button presses periodically (required for automated testing).
190+
*/
191+
PROCESS_THREAD(button_press_simulator, ev, data)
192+
{
193+
PROCESS_BEGIN();
194+
static struct etimer button_timer;
195+
int wait_time = BUTTON_PRESS_PERIOD * CLOCK_SECOND;
196+
etimer_set(&button_timer, wait_time);
197+
while(1) {
198+
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&button_timer));
199+
process_post(PROCESS_BROADCAST, sensors_event, (void *)&button_sensor);
200+
etimer_reset(&button_timer);
201+
}
202+
PROCESS_END();
203+
}
204+
#endif
205+
206+
/*---------------------------------------------------------------------------*/
207+
//! \}

project-conf.h

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/**
2+
* @file
3+
* LightWeightM2M Project Config.
4+
*
5+
* @author Imagination Technologies
6+
*
7+
* @copyright Copyright (c) 2016, Imagination Technologies Limited and/or its affiliated group
8+
* companies and/or licensors.
9+
*
10+
* All rights reserved.
11+
*
12+
* Redistribution and use in source and binary forms, with or without modification, are permitted
13+
* provided that the following conditions are met:
14+
*
15+
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
16+
* and the following disclaimer.
17+
*
18+
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
19+
* conditions and the following disclaimer in the documentation and/or other materials provided
20+
* with the distribution.
21+
*
22+
* 3. Neither the name of the copyright holder nor the names of its contributors may be used to
23+
* endorse or promote products derived from this software without specific prior written
24+
* permission.
25+
*
26+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
27+
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
28+
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
29+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
32+
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
33+
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34+
*/
35+
36+
#ifndef __PROJECT_LWM2M_CONF_H__
37+
#define __PROJECT_LWM2M_CONF_H__
38+
39+
/* Custom channel and PAN ID configuration for your project. */
40+
/*
41+
#define RF_CHANNEL 26
42+
#define IEEE802154_CONF_PANID 0xABCD
43+
*/
44+
45+
/* IP buffer size must match all other hops, in particular the border router. */
46+
/*
47+
#define UIP_CONF_BUFFER_SIZE 256
48+
*/
49+
50+
/* Disabling RDC and CSMA for demo purposes. Core updates often
51+
require more memory. */
52+
/* For projects, optimize memory and enable RDC and CSMA again. */
53+
#define NETSTACK_CONF_RDC nullrdc_driver
54+
55+
/* Disabling TCP on CoAP nodes. */
56+
#define UIP_CONF_TCP 0
57+
58+
/*
59+
#define NETSTACK_CONF_MAC nullmac_driver
60+
*/
61+
62+
/* Increase rpl-border-router IP-buffer when using more than 64. */
63+
#define REST_MAX_CHUNK_SIZE 512
64+
65+
/* Estimate your header size, especially when using Proxy-Uri. */
66+
/*
67+
#define COAP_MAX_HEADER_SIZE 70
68+
*/
69+
70+
/* Multiplies with chunk size, be aware of memory constraints. */
71+
#undef COAP_MAX_OPEN_TRANSACTIONS
72+
#define COAP_MAX_OPEN_TRANSACTIONS 4
73+
74+
/* Must be <= open transactions, default is COAP_MAX_OPEN_TRANSACTIONS-1. */
75+
/*
76+
#define COAP_MAX_OBSERVERS 2
77+
*/
78+
79+
/* Filtering .well-known/core per query can be disabled to save space. */
80+
#define COAP_LINK_FORMAT_FILTERING 0
81+
#define COAP_PROXY_OPTION_PROCESSING 0
82+
83+
/* Enable client-side support for COAP observe */
84+
#define COAP_OBSERVE_CLIENT 1
85+
86+
#define UIP_CONF_TCP 0
87+
88+
#define UIP_CONF_BUFFER_SIZE 4096
89+
90+
/* IP address of device */
91+
#define GLOBAL_IPv6_ADDR
92+
#define GLOBAL_IPv6_ADDR1 0x2001
93+
#define GLOBAL_IPv6_ADDR2 0x1418
94+
#define GLOBAL_IPv6_ADDR3 0x0100
95+
#define GLOBAL_IPv6_ADDR4 0x823c
96+
#define GLOBAL_IPv6_ADDR5 0x0
97+
#define GLOBAL_IPv6_ADDR6 0x0
98+
#define GLOBAL_IPv6_ADDR7 0x0
99+
#define GLOBAL_IPv6_ADDR8 0x0
100+
101+
#define BOOTSTRAP_IPv6_ADDR1 0x2001
102+
#define BOOTSTRAP_IPv6_ADDR2 0x1418
103+
#define BOOTSTRAP_IPv6_ADDR3 0x0100
104+
#define BOOTSTRAP_IPv6_ADDR4 0x0
105+
#define BOOTSTRAP_IPv6_ADDR5 0x0
106+
#define BOOTSTRAP_IPv6_ADDR6 0x0
107+
#define BOOTSTRAP_IPv6_ADDR7 0x0
108+
#define BOOTSTRAP_IPv6_ADDR8 0x1
109+
110+
#define BOOTSTRAP_IPv6_ADDR "2001:1418:100::1"
111+
112+
/* Enable button press simulation */
113+
/*
114+
#define BUTTON_PRESS_SIMULATION
115+
#define BUTTON_PRESS_PERIOD 5
116+
*/
117+
118+
#endif /* __PROJECT_LWM2M_CONF_H__ */

0 commit comments

Comments
 (0)