NB-IOT通过LWM2M协议发送4个实例到ONENET

2023-12-18 11:32

本文主要是介绍NB-IOT通过LWM2M协议发送4个实例到ONENET,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

STM32L BC26初体验-上传多个实例到ONENET
对官方Example(UDP传输与接收数据液晶屏显示)进行的修改,使用LWM2M向平台发送4个实例,temperature instance(5700),Light instance (5850), digit input (5500), Battery Percentage (5700).

main.c
int main(void)
{
BOOL Read_75_Flag = TRUE;
if (SysTick_Config(SystemCoreClock / 1000))//ÉèÖÃ24bit¶¨Ê±Æ÷ 1msÖжÏÒ»´Î
{
/* Capture error */
while (1);
}

GPIO_CONFIGURATION();uart1_init(115200);
uart2_init(115200);
uart3_init(115200);delay_init();while(DHT11_Init());//³õʼ»¯DHT11while(BC26_Init());BC26_PDPACT();BC26_ConLWM2M();// Éϱ¨100%ʱºòµÄµçÁ¿memcpy(sendata,"100",strlen("100"));memset(lenstr,0,BUFLEN);sprintf(lenstr,"%d",strlen((char *)sendata));  BC26_Senddata(3,(u8 *)lenstr,(u8 *)sendata);//·¢ËÍÊý¾Ýwhile(1){

// DHT11_Read_Data(&temp,&humi);//¶ÁÈ¡ÎÂʪ¶ÈÊý¾Ý
// printf(“ζȣº%d C \r\n”,temp);
// printf(“ʪ¶È£º%d RH\r\n”,humi);
// memset(sendata,0,100);
// memset(tempstr,0,100);
// sprintf(tempstr,"%d",temp);
// strcat(sendata,tempstr);
// strcat(sendata,".00");

// memset(lenstr,0,BUFLEN);
// sprintf(lenstr,"%d",strlen((char *)sendata)); //»ñÈ¡·¢Ë͵ij¤¶È

// printf(“sendata = %s len = %s \r\n”, sendata, lenstr);
// BC26_Senddata(0,(u8 *)lenstr,(u8 *)sendata);//·¢ËÍÊý¾Ý
// delay_ms(1000);
if(Read_75_Flag){
if(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_11) == Bit_SET)
{
printf(“75 battery remaining\r\n”);
memcpy(sendata,“75”,strlen(“75”));
memset(lenstr,0,BUFLEN);
sprintf(lenstr,"%d",strlen((char *)sendata));
BC26_Senddata(3,(u8 *)lenstr,(u8 *)sendata);//·¢ËÍÊý¾Ý
Read_75_Flag = FALSE;
}
}

		  if(LED_FLAG == SET){if(led_status == RESET){printf("Open the door\r\n");memcpy(sendata,"1",strlen("1"));}else{printf("Close the door\r\n");memcpy(sendata,"0",strlen("0"));}memset(lenstr,0,BUFLEN);sprintf(lenstr,"%d",strlen((char *)sendata));  BC26_Senddata(1,(u8 *)lenstr,(u8 *)sendata);//·¢ËÍÊý¾ÝLED_FLAG = RESET;}if(AED_FLAG == SET){if(sd_status == SD_PRESENT){printf("insert AED device\r\n");memcpy(sendata,"1",strlen("1"));}else{printf("remove AED device\r\n");memcpy(sendata,"0",strlen("0"));}memset(lenstr,0,BUFLEN);sprintf(lenstr,"%d",strlen((char *)sendata));  BC26_Senddata(2,(u8 *)lenstr,(u8 *)sendata);//·¢ËÍÊý¾ÝAED_FLAG = RESET;}
}

}

BC26.C
void BC26_ConLWM2M(void)
{
int errcount = 0;
int i=0,j=0;
Uart2_SendStr(“AT+MIPLCREATE\r\n”); //+MIPLCREATE: 0
Delay(500);
Delay(500);
strx=strstr((const char*)buf_uart2.buf,(const char*)“OK”);
if(strx==NULL)
{
printf(“Æô¶¯LWM2MЭÒéʧ°Ü\r\n”);
Clear_Buffer();
Uart2_SendStr(“AT+MIPLCREATE\r\n”); //+MIPLCREATE: 0
Delay(500);
Delay(500);
strx=strstr((const char*)buf_uart2.buf,(const char*)“OK”);
if(strx)
{
printf(“Æô¶¯LWM2MЭÒé³É¹¦\r\n”);
}
else
{
strx=strstr((const char*)buf_uart2.buf,(const char*)“ERROR: 653”);
if(strx)
{
GPIO_SetBits(GPIOC,GPIO_Pin_7); //Ä£¿éÖØÆô
Delay(500);
GPIO_ResetBits(GPIOC,GPIO_Pin_7);
Delay(300);
NVIC_SystemReset(); //ûÓд´½¨TCP SOCKET¾ÍÖØÆôϵͳµÈµ½·þÎñÆ÷¾ÍÐ÷
}
}
Clear_Buffer();
}
Clear_Buffer();

Uart2_SendStr("AT+MIPLADDOBJ=0,3303,1,1,1,0\r\n");  // Temputure instance 5700
Delay(300);
Clear_Buffer();
Delay(300);Uart2_SendStr("AT+MIPLADDOBJ=0,3311,1,1,1,0\r\n"); // Light instance  5850
Delay(300);
Clear_Buffer();
Delay(300);Uart2_SendStr("AT+MIPLADDOBJ=0,3200,1,1,1,0\r\n"); // Aed device presence 5500
Delay(300);
Clear_Buffer();
Delay(300);Uart2_SendStr("AT+MIPLADDOBJ=0,3320,1,1,1,0\r\n"); // Battery Percentage  5700
Delay(300);
Clear_Buffer();
Delay(300);Uart2_SendStr("AT+MIPLOPEN=0,86400\r\n");//´ò¿ª
Delay(300);while(j<INSTANCE_CNT)	{strx=strstr((const char*)buf_uart2.buf,(const char*)"+MIPLOBSERVE");//·´À¡¹Û²ìºÅmemset(atbuf,0,BUFLEN);memset(objtnum,0,BUFLEN);while(1){Delay(30);if(strlen((const char *)buf_uart2.buf) > 0){strx=strstr((const char*)buf_uart2.buf,(const char*)"+MIPLOBSERVE");//¼ì²âµ½¹Û²ìºÅ½áÊøif(strx){sprintf(atbuf,"%s",buf_uart2.buf);strx=strstr((const char*)strx+1,(const char*)",");for(i=0;;i++)   //²éѯ¹Û²ìºÅ{if(strx[i+1]==',')break;objtnum[i]=strx[i+1];}printf("µÃµ½ATÃüÁî:atbuf = %s \r\n",atbuf);printf("µÃµ½¹Û²ìºÅ:objtnum = %s \r\n",objtnum);break;}else    //Èç¹ûûÓÐÕÒµ½Ä¿±ê¾ÍÇå¿Õ·´À¡µÄÊý×飬ÕÒµ½Á˾ÍÌø³öÀ´{printf("Á¬½Ó·´À¡:%s\r\n",buf_uart2.buf);Clear_Buffer();}}}Clear_Buffer();printf("object number = %s\r\n",objtnum);memset(atstr,0,BUFLEN);sprintf(atstr,"AT+MIPLOBSERVERSP=0,%s,1\r\n",objtnum);Uart2_SendStr(atstr);//·¢Ë͹۲ìÃüÁîDelay(300);Clear_Buffer();if(strstr((const char*)atbuf,(const char*)"3303"))memcpy(objtnum1,objtnum,BUFLEN);        // Temputureelse if(strstr((const char*)atbuf,(const char*)"3311"))memcpy(objtnum2,objtnum,BUFLEN);   // Light Statuselse if(strstr((const char*)atbuf,(const char*)"3200"))memcpy(objtnum3,objtnum,BUFLEN);   // AED device presenceelse if(strstr((const char*)atbuf,(const char*)"3320"))memcpy(objtnum4,objtnum,BUFLEN);   // Battery j++;}j=0;	while(j<INSTANCE_CNT){strx=strstr((const char*)buf_uart2.buf,(const char*)"+MIPLDISCOVER");//·µ»ØOKmemset(atbuf,0,BUFLEN);memset(distnum,0,BUFLEN);while(1){Delay(30);if(strlen((const char *)buf_uart2.buf) > 0){strx=strstr((const char*)buf_uart2.buf,(const char*)"+MIPLDISCOVER");//¼ì²âµ½¹Û²ìºÅ½áÊøif(strx){sprintf(atbuf,"%s",buf_uart2.buf);strx=strstr((const char*)strx+1,(const char*)",");for(i=0;;i++)   //²éѯ¹Û²ìºÅ{if(strx[i+1]==',')break;distnum[i]=strx[i+1];}printf("µÃµ½ATÃüÁî:atbuf = %s \r\n",atbuf);printf("µÃµ½×ÊÔ´ºÅ:distnum = %s \r\n",distnum);break;}else    //Èç¹ûûÓÐÕÒµ½Ä¿±ê¾ÍÇå¿Õ·´À¡µÄÊý×飬ÕÒµ½Á˾ÍÌø³öÀ´{Clear_Buffer();}}}Clear_Buffer();   printf("discover number = %s\r\n",distnum);memset(atstr,0,BUFLEN);if(strstr((const char*)atbuf,(const char*)"3303")) {sprintf(atstr,"AT+MIPLDISCOVERRSP=0,%s,1,4,\"5700\"\r\n",distnum);        // Temputurememcpy(distnum1,distnum,BUFLEN);}else if(strstr((const char*)atbuf,(const char*)"3311")){sprintf(atstr,"AT+MIPLDISCOVERRSP=0,%s,1,4,\"5850\"\r\n",distnum);    // Light Statusmemcpy(distnum2,distnum,BUFLEN);}else if(strstr((const char*)atbuf,(const char*)"3200")){sprintf(atstr,"AT+MIPLDISCOVERRSP=0,%s,1,4,\"5500\"\r\n",distnum);   // AED device presencememcpy(distnum3,objtnum,BUFLEN);}else if(strstr((const char*)atbuf,(const char*)"3320")){sprintf(atstr,"AT+MIPLDISCOVERRSP=0,%s,1,4,\"5700\"\r\n",distnum);   // Battery memcpy(distnum4,objtnum,BUFLEN);}Uart2_SendStr(atstr);//·¢ËÍ×ÊÔ´ÃüÁîDelay(300);strx=strstr((const char*)buf_uart2.buf,(const char*)"OK");//·µ»ØOKwhile(strx==NULL){errcount++;strx=strstr((const char*)buf_uart2.buf,(const char*)"OK");//·µ»ØOKif(errcount>100)     //·ÀÖ¹ËÀÑ­»·{errcount = 0;break;}}	Clear_Buffer();j++;		}

}
完整工程:https://download.csdn.net/download/sinat_16873757/14950707

这篇关于NB-IOT通过LWM2M协议发送4个实例到ONENET的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/508225

相关文章

Nginx服务器部署详细代码实例

《Nginx服务器部署详细代码实例》Nginx是一个高性能的HTTP和反向代理web服务器,同时也提供了IMAP/POP3/SMTP服务,:本文主要介绍Nginx服务器部署的相关资料,文中通过代码... 目录Nginx 服务器SSL/TLS 配置动态脚本反向代理总结Nginx 服务器Nginx是一个‌高性

Go异常处理、泛型和文件操作实例代码

《Go异常处理、泛型和文件操作实例代码》Go语言的异常处理机制与传统的面向对象语言(如Java、C#)所使用的try-catch结构有所不同,它采用了自己独特的设计理念和方法,:本文主要介绍Go异... 目录一:异常处理常见的异常处理向上抛中断程序恢复程序二:泛型泛型函数泛型结构体泛型切片泛型 map三:文

springboot+mybatis一对多查询+懒加载实例

《springboot+mybatis一对多查询+懒加载实例》文章介绍了如何在SpringBoot和MyBatis中实现一对多查询的懒加载,通过配置MyBatis的`fetchType`属性,可以全局... 目录springboot+myBATis一对多查询+懒加载parent相关代码child 相关代码懒

C++中的解释器模式实例详解

《C++中的解释器模式实例详解》这篇文章总结了C++标准库中的算法分类,还介绍了sort和stable_sort的区别,以及remove和erase的结合使用,结合实例代码给大家介绍的非常详细,感兴趣... 目录1、非修改序列算法1.1 find 和 find_if1.2 count 和 count_if1

MySQL中如何求平均值常见实例(AVG函数详解)

《MySQL中如何求平均值常见实例(AVG函数详解)》MySQLavg()是一个聚合函数,用于返回各种记录中表达式的平均值,:本文主要介绍MySQL中用AVG函数如何求平均值的相关资料,文中通过代... 目录前言一、基本语法二、示例讲解1. 计算全表平均分2. 计算某门课程的平均分(例如:Math)三、结合

Java发送SNMP至交换机获取交换机状态实现方式

《Java发送SNMP至交换机获取交换机状态实现方式》文章介绍使用SNMP4J库(2.7.0)通过RCF1213-MIB协议获取交换机单/多路状态,需开启SNMP支持,重点对比SNMPv1、v2c、v... 目录交换机协议SNMP库获取交换机单路状态获取交换机多路状态总结交换机协议这里使用的交换机协议为常

PyQt6 键盘事件处理的实现及实例代码

《PyQt6键盘事件处理的实现及实例代码》本文主要介绍了PyQt6键盘事件处理的实现示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起... 目录一、键盘事件处理详解1、核心事件处理器2、事件对象 QKeyEvent3、修饰键处理(1)、修饰键类

SpringBoot+RustFS 实现文件切片极速上传的实例代码

《SpringBoot+RustFS实现文件切片极速上传的实例代码》本文介绍利用SpringBoot和RustFS构建高性能文件切片上传系统,实现大文件秒传、断点续传和分片上传等功能,具有一定的参考... 目录一、为什么选择 RustFS + SpringBoot?二、环境准备与部署2.1 安装 RustF

HTTP 与 SpringBoot 参数提交与接收协议方式

《HTTP与SpringBoot参数提交与接收协议方式》HTTP参数提交方式包括URL查询、表单、JSON/XML、路径变量、头部、Cookie、GraphQL、WebSocket和SSE,依据... 目录HTTP 协议支持多种参数提交方式,主要取决于请求方法(Method)和内容类型(Content-Ty

基于Python实现自动化邮件发送系统的完整指南

《基于Python实现自动化邮件发送系统的完整指南》在现代软件开发和自动化流程中,邮件通知是一个常见且实用的功能,无论是用于发送报告、告警信息还是用户提醒,通过Python实现自动化的邮件发送功能都能... 目录一、前言:二、项目概述三、配置文件 `.env` 解析四、代码结构解析1. 导入模块2. 加载环