Skip to content

Commit

Permalink
Merge pull request #145 from cruise2018/iot_link
Browse files Browse the repository at this point in the history
Iot link
  • Loading branch information
cruise2018 authored Jul 31, 2019
2 parents b13d5a7 + 7a904c4 commit b675d13
Show file tree
Hide file tree
Showing 10 changed files with 441 additions and 89 deletions.
5 changes: 5 additions & 0 deletions demos/oc_lwm2m_demo/oc_lwm2m_demo.mk
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ else ifeq ($(CONFIG_OC_LWM2M_DEMO_TYPE), "oc_lwm2m_demo_nodtls")
oc_lwm2m_demo_src = ${wildcard $(TOP_DIR)/demos/oc_lwm2m_demo/oc_lwm2m_demo_nodtls/oc_lwm2m_demo_nodtls.c}
oc_lwm2m_demo_inc = -I $(TOP_DIR)/demos/oc_lwm2m_demo
oc_lwm2m_demo_defs = -D CONFIG_OC_LWM2M_DEMO_ENABLE=1

else ifeq ($(CONFIG_OC_LWM2M_DEMO_TYPE), "oc_lwm2m_demo_nodtls_bs")
oc_lwm2m_demo_src = ${wildcard $(TOP_DIR)/demos/oc_lwm2m_demo/oc_lwm2m_demo_nodtls_bs/oc_lwm2m_demo_nodtls_bs.c}
oc_lwm2m_demo_inc = -I $(TOP_DIR)/demos/oc_lwm2m_demo
oc_lwm2m_demo_defs = -D LWM2M_BOOTSTRAP=1 -D CONFIG_OC_LWM2M_DEMO_ENABLE=1

endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ static int app_report_task_entry()
//install a dealer for the led message received
while(1) //--TODO ,you could add your own code here
{

lux++;
lux= lux%10000;

light.msgid = cn_app_light;
Expand Down
136 changes: 98 additions & 38 deletions demos/oc_lwm2m_demo/oc_lwm2m_demo_dtls_bs/oc_lwm2m_demo_dtls_bs.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,60 +36,90 @@
* 2019-05-14 17:21 zhangqianfu The first version
*
*/

#include <stdint.h>
#include <stddef.h>
#include <string.h>

#include <osal.h>
#include <oc_lwm2m_al.h>


//#define cn_endpoint_id "987a0150-f855-4648-b771-fe0c7c7c1c2b"
#define cn_endpoint_id "coap_verify_code"
#define cn_app_server "119.3.184.255"
#define cn_endpoint_id "lwm2m_002"
#define cn_app_server "119.3.251.30"
#define cn_app_port "5684"
#define cn_psk_id "coap_verify_code"
unsigned char s_app_psk[] = {0x87,0x65,0x43,0x21};

const unsigned char s_app_psk[]={0x01,0x02,0x03,0x04,0x05,0x06};

#define cn_app_connectivity 0
#define cn_app_lightstats 1
#define cn_app_light 2
#define cn_app_ledcmd 3
#define cn_app_cmdreply 4

#define cn_app_light 0
#define cn_app_ledcmd 1
#define cn_app_csq 2
#pragma pack(1)
typedef struct
{
int8_t msgid;
char intensity[5];
int16_t rsrp;
int16_t ecl;
int16_t snr;
int32_t cellid;
}app_connectivity_t;

typedef struct
{
int8_t msgid;
int16_t tog;
}app_toggle_t;

typedef struct
{
int8_t msgid;
int16_t intensity;
}app_light_intensity_t;


typedef struct
{
int8_t msgid;
char led[3];
uint16_t mid;
char led[3];
}app_led_cmd_t;

typedef struct
{
int8_t msgid;
char csq[3];
}app_net_csq_t;
uint16_t mid;
int8_t errorcode;
char curstats[3];
}app_cmdreply_t;

#pragma pack()




//if your command is very fast,please use a queue here--TODO
#define cn_app_rcv_buf_len 128
static int s_rcv_buffer[cn_app_rcv_buf_len];
static int s_rcv_datalen;
static osal_semp_t s_rcv_sync;

static void *s_lwm2m_handle = NULL;



//use this function to push all the message to the buffer
static int app_msg_deal(void *usr_data,char *msg, int len)
{
int ret = -1;

if(len <= cn_app_rcv_buf_len)
{
if (msg[0] == 0xaa && msg[1] == 0xaa)
{
printf("OC respond message received! \n\r");
return ret;
}
memcpy(s_rcv_buffer,msg,len);
s_rcv_datalen = len;

Expand All @@ -105,21 +135,51 @@ static int app_msg_deal(void *usr_data,char *msg, int len)
static int app_cmd_task_entry()
{
int ret = -1;
int msgid;
app_led_cmd_t *led_cmd;
app_cmdreply_t replymsg;
int8_t msgid;

while(1)
{
if(osal_semp_pend(s_rcv_sync,cn_osal_timeout_forever))
{
msgid = s_rcv_buffer[0];

msgid = s_rcv_buffer[0] & 0x000000FF;
switch (msgid)
{
case cn_app_ledcmd:
led_cmd = (app_led_cmd_t *)s_rcv_buffer;
printf("LEDCMD:msgid:%d msg:%s \n\r",led_cmd->msgid,led_cmd->led);
//if you need response,do it here--TODO
printf("LEDCMD:msgid:%d mid:%d msg:%s \n\r",led_cmd->msgid,ntohs(led_cmd->mid),led_cmd->led);
//add command action--TODO
if (led_cmd->led[0] == 'O' && led_cmd->led[1] == 'N')
{
//if you need response message,do it here--TODO
replymsg.msgid = cn_app_cmdreply;
replymsg.mid = led_cmd->mid;
printf("reply mid is %d. \n\r",ntohs(replymsg.mid));
replymsg.errorcode = 0;
replymsg.curstats[0] = 'O';
replymsg.curstats[1] = 'N';
replymsg.curstats[2] = ' ';
oc_lwm2m_report(s_lwm2m_handle,(char *)&replymsg,sizeof(replymsg),1000); ///< report cmd reply message
}

else if (led_cmd->led[0] == 'O' && led_cmd->led[1] == 'F' && led_cmd->led[2] == 'F')
{

//if you need response message,do it here--TODO
replymsg.msgid = cn_app_cmdreply;
replymsg.mid = led_cmd->mid;
printf("reply mid is %d. \n\r",ntohs(replymsg.mid));
replymsg.errorcode = 0;
replymsg.curstats[0] = 'O';
replymsg.curstats[1] = 'F';
replymsg.curstats[2] = 'F';
oc_lwm2m_report(s_lwm2m_handle,(char *)&replymsg,sizeof(replymsg),1000); ///< report cmd reply message
}
else
{

}
break;
default:
break;
Expand All @@ -130,59 +190,61 @@ static int app_cmd_task_entry()
return ret;
}



static int app_report_task_entry()
{
int ret = -1;
int lux = 0;

oc_config_param_t oc_param;
app_light_intensity_t light;
app_net_csq_t csq;
void *context;

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

oc_param.app_server.ep_id = cn_endpoint_id;
// oc_param.app_server.address = cn_app_server;
// oc_param.app_server.port = cn_app_port;
// oc_param.app_server.psk = (char *)s_app_psk;
// oc_param.app_server.psk_len = sizeof(s_app_psk);
// oc_param.app_server.psk_id = cn_psk_id;
oc_param.app_server.psk = (char *)s_app_psk;
oc_param.app_server.psk_len = sizeof(s_app_psk);
oc_param.app_server.psk_id = cn_endpoint_id;

oc_param.boot_server.address = cn_app_server;
oc_param.boot_server.port = cn_app_port;
oc_param.boot_server.ep_id = cn_endpoint_id;
oc_param.boot_server.psk = (char *)s_app_psk;
oc_param.boot_server.psk_len = sizeof(s_app_psk);
oc_param.boot_server.psk_id = cn_psk_id;
oc_param.boot_server.psk_id = cn_endpoint_id;

oc_param.boot_mode = en_oc_boot_strap_mode_client_initialize;
oc_param.rcv_func = app_msg_deal;

context = oc_lwm2m_config(&oc_param);
s_lwm2m_handle = oc_lwm2m_config(&oc_param);

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

csq.msgid = cn_app_csq;
memcpy(csq.csq,"012",3);
oc_lwm2m_report(context,(char *)&csq,sizeof(csq),1000); ///< report the light message
lux++;
lux= lux%10000;

light.msgid = cn_app_light;
light.intensity = htons(lux);
oc_lwm2m_report(s_lwm2m_handle,(char *)&light,sizeof(light),1000); ///< report the light message
osal_task_sleep(10*1000);
}
}

return ret;
}




int oc_lwm2m_demo_main()
{
osal_semp_create(&s_rcv_sync,1,0);

osal_task_create("app_report",app_report_task_entry,NULL,0x1000,NULL,2);
osal_task_create("app_command",app_cmd_task_entry,NULL,0x1000,NULL,3);

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





Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ static int app_report_task_entry()
//install a dealer for the led message received
while(1) //--TODO ,you could add your own code here
{

lux++;
lux= lux%10000;

light.msgid = cn_app_light;
Expand Down
34 changes: 34 additions & 0 deletions demos/oc_lwm2m_demo/oc_lwm2m_demo_nodtls_bs/defaults.sdkconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
##############################CONFIGURE INTRODUCTION############################
#configure type configure value
#------------------:------------------
#CONFIG_OS_TYPE : "linux" "macos" "liteos"
#CONFIG_SHELL_ENABLE : y n
#CONFIG_LIBC_ENABLE : y n
#CONFIG_CJSON_ENABLE : y n
#CONFIG_TCPIP_TYPE : "lwip" "linux_socket" "macos_socket" "none"
#CONFIG_DTLS_TYPE : "mbedtls" "none"
#CONFIG_EMBEDTLS_MODE : "crt" "psk" "none"
#CONFIG_MQTT_TYPE : "paho" "none"
#CONFIG_LWM2M_TYPE : "wakaama" "none"
#CONFIG_OC_MQTT_TYPE : "soft" "none"
#CONFIG_OC_LWM2M_TYPE : "soft" "boudica150" "none"
#CONFIG_LOADER_ENABLE : y n
#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"
#CONFIG_OC_MQTT_DEMO_TYPE:"none" "oc_mqtt_demo_static" "oc_mqtt_demo_bs"

CONFIG_OS_TYPE = "liteos"
CONFIG_SHELL_ENABLE = y
CONFIG_DRIVER_ENABLE = n
CONFIG_AT_ENABLE = n
CONFIG_LIBC_ENABLE = y
CONFIG_CJSON_ENABLE = n
CONFIG_TCPIP_TYPE = "lwip"
CONFIG_DTLS_TYPE = "mbedtls"
CONFIG_EMBEDTLS_MODE = "psk"
CONFIG_MQTT_TYPE = "none"
CONFIG_LWM2M_TYPE = "wakaama"
CONFIG_OC_MQTT_TYPE = "none"
CONFIG_OC_LWM2M_TYPE = "soft"
CONFIG_LOADER_ENABLE = n
CONFIG_OC_LWM2M_DEMO_TYPE= "oc_lwm2m_demo_nodtls_bs"
CONFIG_OC_MQTT_DEMO_TYPE= "none"
Loading

0 comments on commit b675d13

Please sign in to comment.