Skip to content

Commit b675d13

Browse files
authored
Merge pull request #145 from cruise2018/iot_link
Iot link
2 parents b13d5a7 + 7a904c4 commit b675d13

10 files changed

Lines changed: 441 additions & 89 deletions

File tree

demos/oc_lwm2m_demo/oc_lwm2m_demo.mk

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ else ifeq ($(CONFIG_OC_LWM2M_DEMO_TYPE), "oc_lwm2m_demo_nodtls")
2323
oc_lwm2m_demo_src = ${wildcard $(TOP_DIR)/demos/oc_lwm2m_demo/oc_lwm2m_demo_nodtls/oc_lwm2m_demo_nodtls.c}
2424
oc_lwm2m_demo_inc = -I $(TOP_DIR)/demos/oc_lwm2m_demo
2525
oc_lwm2m_demo_defs = -D CONFIG_OC_LWM2M_DEMO_ENABLE=1
26+
27+
else ifeq ($(CONFIG_OC_LWM2M_DEMO_TYPE), "oc_lwm2m_demo_nodtls_bs")
28+
oc_lwm2m_demo_src = ${wildcard $(TOP_DIR)/demos/oc_lwm2m_demo/oc_lwm2m_demo_nodtls_bs/oc_lwm2m_demo_nodtls_bs.c}
29+
oc_lwm2m_demo_inc = -I $(TOP_DIR)/demos/oc_lwm2m_demo
30+
oc_lwm2m_demo_defs = -D LWM2M_BOOTSTRAP=1 -D CONFIG_OC_LWM2M_DEMO_ENABLE=1
2631

2732
endif
2833

demos/oc_lwm2m_demo/oc_lwm2m_demo_dtls/oc_lwm2m_demo_dtls.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ static int app_report_task_entry()
220220
//install a dealer for the led message received
221221
while(1) //--TODO ,you could add your own code here
222222
{
223-
223+
lux++;
224224
lux= lux%10000;
225225

226226
light.msgid = cn_app_light;

demos/oc_lwm2m_demo/oc_lwm2m_demo_dtls_bs/oc_lwm2m_demo_dtls_bs.c

Lines changed: 98 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -36,60 +36,90 @@
3636
* 2019-05-14 17:21 zhangqianfu The first version
3737
*
3838
*/
39+
3940
#include <stdint.h>
4041
#include <stddef.h>
4142
#include <string.h>
4243

4344
#include <osal.h>
4445
#include <oc_lwm2m_al.h>
4546

46-
47-
//#define cn_endpoint_id "987a0150-f855-4648-b771-fe0c7c7c1c2b"
48-
#define cn_endpoint_id "coap_verify_code"
49-
#define cn_app_server "119.3.184.255"
47+
#define cn_endpoint_id "lwm2m_002"
48+
#define cn_app_server "119.3.251.30"
5049
#define cn_app_port "5684"
51-
#define cn_psk_id "coap_verify_code"
52-
unsigned char s_app_psk[] = {0x87,0x65,0x43,0x21};
53-
50+
const unsigned char s_app_psk[]={0x01,0x02,0x03,0x04,0x05,0x06};
5451

52+
#define cn_app_connectivity 0
53+
#define cn_app_lightstats 1
54+
#define cn_app_light 2
55+
#define cn_app_ledcmd 3
56+
#define cn_app_cmdreply 4
5557

56-
#define cn_app_light 0
57-
#define cn_app_ledcmd 1
58-
#define cn_app_csq 2
5958
#pragma pack(1)
6059
typedef struct
6160
{
6261
int8_t msgid;
63-
char intensity[5];
62+
int16_t rsrp;
63+
int16_t ecl;
64+
int16_t snr;
65+
int32_t cellid;
66+
}app_connectivity_t;
67+
68+
typedef struct
69+
{
70+
int8_t msgid;
71+
int16_t tog;
72+
}app_toggle_t;
73+
74+
typedef struct
75+
{
76+
int8_t msgid;
77+
int16_t intensity;
6478
}app_light_intensity_t;
6579

6680

6781
typedef struct
6882
{
6983
int8_t msgid;
70-
char led[3];
84+
uint16_t mid;
85+
char led[3];
7186
}app_led_cmd_t;
7287

7388
typedef struct
7489
{
7590
int8_t msgid;
76-
char csq[3];
77-
}app_net_csq_t;
91+
uint16_t mid;
92+
int8_t errorcode;
93+
char curstats[3];
94+
}app_cmdreply_t;
95+
7896
#pragma pack()
7997

98+
99+
100+
80101
//if your command is very fast,please use a queue here--TODO
81102
#define cn_app_rcv_buf_len 128
82103
static int s_rcv_buffer[cn_app_rcv_buf_len];
83104
static int s_rcv_datalen;
84105
static osal_semp_t s_rcv_sync;
85106

107+
static void *s_lwm2m_handle = NULL;
108+
109+
110+
86111
//use this function to push all the message to the buffer
87112
static int app_msg_deal(void *usr_data,char *msg, int len)
88113
{
89114
int ret = -1;
90115

91116
if(len <= cn_app_rcv_buf_len)
92117
{
118+
if (msg[0] == 0xaa && msg[1] == 0xaa)
119+
{
120+
printf("OC respond message received! \n\r");
121+
return ret;
122+
}
93123
memcpy(s_rcv_buffer,msg,len);
94124
s_rcv_datalen = len;
95125

@@ -105,21 +135,51 @@ static int app_msg_deal(void *usr_data,char *msg, int len)
105135
static int app_cmd_task_entry()
106136
{
107137
int ret = -1;
108-
int msgid;
109138
app_led_cmd_t *led_cmd;
139+
app_cmdreply_t replymsg;
140+
int8_t msgid;
110141

111142
while(1)
112143
{
113144
if(osal_semp_pend(s_rcv_sync,cn_osal_timeout_forever))
114145
{
115-
msgid = s_rcv_buffer[0];
116-
146+
msgid = s_rcv_buffer[0] & 0x000000FF;
117147
switch (msgid)
118148
{
119149
case cn_app_ledcmd:
120150
led_cmd = (app_led_cmd_t *)s_rcv_buffer;
121-
printf("LEDCMD:msgid:%d msg:%s \n\r",led_cmd->msgid,led_cmd->led);
122-
//if you need response,do it here--TODO
151+
printf("LEDCMD:msgid:%d mid:%d msg:%s \n\r",led_cmd->msgid,ntohs(led_cmd->mid),led_cmd->led);
152+
//add command action--TODO
153+
if (led_cmd->led[0] == 'O' && led_cmd->led[1] == 'N')
154+
{
155+
//if you need response message,do it here--TODO
156+
replymsg.msgid = cn_app_cmdreply;
157+
replymsg.mid = led_cmd->mid;
158+
printf("reply mid is %d. \n\r",ntohs(replymsg.mid));
159+
replymsg.errorcode = 0;
160+
replymsg.curstats[0] = 'O';
161+
replymsg.curstats[1] = 'N';
162+
replymsg.curstats[2] = ' ';
163+
oc_lwm2m_report(s_lwm2m_handle,(char *)&replymsg,sizeof(replymsg),1000); ///< report cmd reply message
164+
}
165+
166+
else if (led_cmd->led[0] == 'O' && led_cmd->led[1] == 'F' && led_cmd->led[2] == 'F')
167+
{
168+
169+
//if you need response message,do it here--TODO
170+
replymsg.msgid = cn_app_cmdreply;
171+
replymsg.mid = led_cmd->mid;
172+
printf("reply mid is %d. \n\r",ntohs(replymsg.mid));
173+
replymsg.errorcode = 0;
174+
replymsg.curstats[0] = 'O';
175+
replymsg.curstats[1] = 'F';
176+
replymsg.curstats[2] = 'F';
177+
oc_lwm2m_report(s_lwm2m_handle,(char *)&replymsg,sizeof(replymsg),1000); ///< report cmd reply message
178+
}
179+
else
180+
{
181+
182+
}
123183
break;
124184
default:
125185
break;
@@ -130,59 +190,61 @@ static int app_cmd_task_entry()
130190
return ret;
131191
}
132192

193+
194+
133195
static int app_report_task_entry()
134196
{
135197
int ret = -1;
198+
int lux = 0;
136199

137200
oc_config_param_t oc_param;
138201
app_light_intensity_t light;
139-
app_net_csq_t csq;
140-
void *context;
141202

142203
memset(&oc_param,0,sizeof(oc_param));
143204

144205
oc_param.app_server.ep_id = cn_endpoint_id;
145-
// oc_param.app_server.address = cn_app_server;
146-
// oc_param.app_server.port = cn_app_port;
147-
// oc_param.app_server.psk = (char *)s_app_psk;
148-
// oc_param.app_server.psk_len = sizeof(s_app_psk);
149-
// oc_param.app_server.psk_id = cn_psk_id;
206+
oc_param.app_server.psk = (char *)s_app_psk;
207+
oc_param.app_server.psk_len = sizeof(s_app_psk);
208+
oc_param.app_server.psk_id = cn_endpoint_id;
150209

151210
oc_param.boot_server.address = cn_app_server;
152211
oc_param.boot_server.port = cn_app_port;
153212
oc_param.boot_server.ep_id = cn_endpoint_id;
154213
oc_param.boot_server.psk = (char *)s_app_psk;
155214
oc_param.boot_server.psk_len = sizeof(s_app_psk);
156-
oc_param.boot_server.psk_id = cn_psk_id;
215+
oc_param.boot_server.psk_id = cn_endpoint_id;
157216

158217
oc_param.boot_mode = en_oc_boot_strap_mode_client_initialize;
159218
oc_param.rcv_func = app_msg_deal;
160219

161-
context = oc_lwm2m_config(&oc_param);
220+
s_lwm2m_handle = oc_lwm2m_config(&oc_param);
162221

163-
if(NULL != context) //success ,so we could receive and send
222+
if(NULL != s_lwm2m_handle) //success ,so we could receive and send
164223
{
165224
//install a dealer for the led message received
166225
while(1) //--TODO ,you could add your own code here
167226
{
168-
light.msgid = cn_app_light;
169-
memcpy(light.intensity,"12345",5);
170-
oc_lwm2m_report(context,(char *)&light,sizeof(light),1000); ///< report the light message
171-
osal_task_sleep(10*1000);
172227

173-
csq.msgid = cn_app_csq;
174-
memcpy(csq.csq,"012",3);
175-
oc_lwm2m_report(context,(char *)&csq,sizeof(csq),1000); ///< report the light message
228+
lux++;
229+
lux= lux%10000;
230+
231+
light.msgid = cn_app_light;
232+
light.intensity = htons(lux);
233+
oc_lwm2m_report(s_lwm2m_handle,(char *)&light,sizeof(light),1000); ///< report the light message
176234
osal_task_sleep(10*1000);
177235
}
178236
}
179237

180238
return ret;
181239
}
182240

241+
242+
243+
183244
int oc_lwm2m_demo_main()
184245
{
185246
osal_semp_create(&s_rcv_sync,1,0);
247+
186248
osal_task_create("app_report",app_report_task_entry,NULL,0x1000,NULL,2);
187249
osal_task_create("app_command",app_cmd_task_entry,NULL,0x1000,NULL,3);
188250

@@ -191,5 +253,3 @@ int oc_lwm2m_demo_main()
191253

192254

193255

194-
195-

demos/oc_lwm2m_demo/oc_lwm2m_demo_nodtls/oc_lwm2m_demo_nodtls.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ static int app_report_task_entry()
213213
//install a dealer for the led message received
214214
while(1) //--TODO ,you could add your own code here
215215
{
216-
216+
lux++;
217217
lux= lux%10000;
218218

219219
light.msgid = cn_app_light;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
##############################CONFIGURE INTRODUCTION############################
2+
#configure type configure value
3+
#------------------:------------------
4+
#CONFIG_OS_TYPE : "linux" "macos" "liteos"
5+
#CONFIG_SHELL_ENABLE : y n
6+
#CONFIG_LIBC_ENABLE : y n
7+
#CONFIG_CJSON_ENABLE : y n
8+
#CONFIG_TCPIP_TYPE : "lwip" "linux_socket" "macos_socket" "none"
9+
#CONFIG_DTLS_TYPE : "mbedtls" "none"
10+
#CONFIG_EMBEDTLS_MODE : "crt" "psk" "none"
11+
#CONFIG_MQTT_TYPE : "paho" "none"
12+
#CONFIG_LWM2M_TYPE : "wakaama" "none"
13+
#CONFIG_OC_MQTT_TYPE : "soft" "none"
14+
#CONFIG_OC_LWM2M_TYPE : "soft" "boudica150" "none"
15+
#CONFIG_LOADER_ENABLE : y n
16+
#CONFIG_OC_LWM2M_DEMO_TYPE:"none" "oc_lwm2m_demo_dtls" and "oc_lwm2m_demo_nodtls" "oc_lwm2m_demo_bs_dtls" "oc_lwm2m_demo_bearpi_template"
17+
#CONFIG_OC_MQTT_DEMO_TYPE:"none" "oc_mqtt_demo_static" "oc_mqtt_demo_bs"
18+
19+
CONFIG_OS_TYPE = "liteos"
20+
CONFIG_SHELL_ENABLE = y
21+
CONFIG_DRIVER_ENABLE = n
22+
CONFIG_AT_ENABLE = n
23+
CONFIG_LIBC_ENABLE = y
24+
CONFIG_CJSON_ENABLE = n
25+
CONFIG_TCPIP_TYPE = "lwip"
26+
CONFIG_DTLS_TYPE = "mbedtls"
27+
CONFIG_EMBEDTLS_MODE = "psk"
28+
CONFIG_MQTT_TYPE = "none"
29+
CONFIG_LWM2M_TYPE = "wakaama"
30+
CONFIG_OC_MQTT_TYPE = "none"
31+
CONFIG_OC_LWM2M_TYPE = "soft"
32+
CONFIG_LOADER_ENABLE = n
33+
CONFIG_OC_LWM2M_DEMO_TYPE= "oc_lwm2m_demo_nodtls_bs"
34+
CONFIG_OC_MQTT_DEMO_TYPE= "none"

0 commit comments

Comments
 (0)