全国协议5人面授小班,企业级独立开发考核,零基础的软硬件工程师基地

登录/注册
当前位置:首页  >   > 嵌入式干货之无线传感器网络

嵌入式干货之无线传感器网络

来源:汉码未来
发布人:xqq
时间: 2024-11-27 21:46:35 1711417071

现代社会提倡节能减排,人们不良的用电习惯往往带来不必要的浪费。这就需要能够对各类用电器进行监测和控制的系统。智能家居在传统的家居环境中引入自动化控制等技术,可以解决以上问题,但是布线复杂,价格昂贵[1?2]。而物联网是当今学术和应用研究的热点之一,接入互联网需要专用的适配器[3?4]6LOWPAN技术的提出,将IP 网络扩展到无线传感器网络成为可能[5]。本文将物联网技术运用到家电系统,在不改变旧式家电的基础上,提出在灯座插线增加转接器的非侵入低成本手段,该转换器利用6LOWPAN网络协议搭建低功耗的无线传感网络,实现对家电终端的远程监测和控制功能。

 

1 系统方案设计

 

基于6LOWPAN 的智能家电监测与控制系统框架图如图1所示,系统由手持客户终端、嵌入式网关、IPv6无线传感器网络主智能节点和从转换器节点等部分构成。手持客户终端采用Android手机,安装开发的APP软件就能通过互联网远程监测和控制家电;嵌入式网关提供互联网访问服务和转发无线传感器网络指令的功能,负责接收手机发来的指令,并将其转换为无线传感器网络可识别的指令以及转发到对应的智能节点上。

 

网关采用STM32W108STM32F107双核处理器方案,STM32W108 处理无线传感器网络的6LOWPAN 数据,STM32F107处理互联网数据。嵌入式网关是整个系统的核心,担任数据格式转换和转发工作,需要很强的可靠性和稳定性[6]。无线传感器网络由主节点和从节点组成,主节点作为嵌入式网关与从节点之间数据传输的路由器,从节点嵌入到家电中,监测和控制家电状态。

 

2 硬件电路设计

 

该系统采用Android智能手机作为客户端;嵌入式网关的STM32F107STM32W108处理器之间通过Uart接口连接;网络物理层芯片采用DP83848IPv6 无线传感网络所有节点采用都是STM32W108处理器。嵌入式网关和IPv6无线传感网络的无线收发模块采用的都是STM32W108内部自带的RF模块,外接一个陶瓷天线构成。硬件总体框架图如图2所示。

 

2.1 无线传感器网络

 

IPv6 无线传感网络拓扑结构如图3 所示。主节点“R”和从节点“N”都采用STM32W108处理器,不同之处在于节点“N”比节点“R”增加传感器和控制电路模块。

 

STM32W108是意法半导体(ST)公司推出的一个完全集成的系统级芯片,该芯片集成符合IEEE 802.15.4标准的2.4 GHz 收发器、32 ARM Cortex?M3 微处理器、flash闪存、RAM储存器和其他通用外设。在保持低功耗的基础上,采用32ARM Cortex?M3内核,它有别于其他的8 16 位处理器,其提供更强大的处理能力,并有广泛的ARM开发工具,群体支持;芯片内部带有功率放大器,发射输出功率可达7 dBm,无需外部功放就可以获得较远的通信距离[7]

 

2.2 嵌入式网关

 

嵌入式网关主要由STM32F107STM32W108 DP83848三部分电路模块构成。STM32F107也是由ST公司推出全新SMT32互联型系列控制器中的一款性能较强的产品,此芯片集成各种共性能工业标准接口,并且STM32F10X不用型号产品在引脚和软件上具有完美的兼容性,可以轻松适应更多的应用。此芯片的标准外设包括10个定时器,212A/D212D/A2I2C接口,5USART接口,3SPI接口,高质量数字音频接口I2S。另外拥有全速USBOTG)接口,2CAN 2.0B接口和10M/100M 以太网MAC 模块。STM32F107内部自带以太网模块,以及嵌入式网关无需用户显示界面,不需要性能很高的处理器,所以选用性价比较好的STM32F107处理器。

 

DP83848是美国国家半导体(NS)公司生产的集成以太网控制芯片,是一种10M/100M 单路物理层以太网收发器器件,支持MIIRMII接口模式,集成度高,具有全功能、低功耗等性能。本系统采用RMII接口,配置成100 Mb/s以太网模式。

 

3 软件设计

 

3.1 无线传感器网络

 

节点“N”和“R”移植Contiki操作系统,Contiki系统由瑞典计算机科学研究所开发,是一个开源多任务事件驱动操作系统,专为网络嵌入式设备设计。轻量级的足印很适合内存有限的MCU。一个Contiki系统只需2 KBRAM 40 KB ROM。包含一个事件驱动的内核,使用轻量级的protothreads 进程模型,可以在事件驱动内核上提供一个线性的、类似于线程的编程风格,Contiki操作系统可运行于各种平台[8?9]

 

Windows 系统环境下,采用Cygwin 开发平台。Cygwin是许多自由软件的集合,最初由Cygnus Solutions开发,在各种版本的Microsoft Windows上运行Unix类系统。在Cygwin环境下移植Contiki操作系统,需要另外借助EWARM编译工具。安装好相应软件后,打开Cygwin软件,需要设置编译软件PATH环境变量。命令如下:

exportPATH=/cygdrive/c/Program\Files/IAR\Systems/Embed?ded\Workbench\5.4\Evaluation/arm/bin$PATH智能节点软件流程图如图4所示,智能节点上电初始化之后,处于监听嵌入式网关的状态。一旦嵌入式网关发来无线数据包,智能节点就对数据包进行解析。如果是监测家电状态的指令,智能节点就查询当前家电的状态,把数据打包之后通过射频模块发送给嵌入式网关;如果是控制指令,智能节点将会控制家电的开关状态,完成指令控制后,智能节点也会通过射频模块向嵌入式网关发送应答信号。

 

3.2 嵌入式网关

 

嵌入式网关内部有2 个独立的操作系统,其中STM32F107处理器移植μC/OS操作系统[10]STM32W108移植Contiki 系统。操作系统之间通过Uart 协议通信,通信自定义帧格式如表格1所示。自定义帧由帧头、网络标识、节点地址与端口号、节点状态、传感器类型、节点数据、保留字节和帧尾组成,长度为16 B。通过读取节点的状态和节点数据,客户端就可以监测和控制传感器节点。帧格式保留2 B,当有更多的数据传输时,保留的字节可以直接扩展。

 

嵌入式网关软件流程图如图5所示,网关上电初始化之后,处于监听UDP端口信息状态,等待客户端的访问。一旦有客户端访问,需要验证客户端的远程口令是否正确。如果口令不正确,不再解析数据包,返回监听UDP 端口信息状态;如果口令正确,将会解析数据包。解析后的数据包由网关的射频模块向IPv6无线传感网络发送无线数据。在设定的时间内,不管IPv6 无线传感网络有无响应嵌入式网关,网关都会向客户端返回指令响应状态的应答信号。

 

3.3 Android客户端

 

客户端用Android手机为载体,软件设计流程图如图6所示。在登录界面用户输入嵌入式网关的IP地址、UDP端口号和远程口令,点击界面“登陆”按钮后,软件通过IP 网络向嵌入式网关发送登陆命令,如果通过嵌入式网关的远程口令验证,软件进入功能界面;如果没通过嵌入式网关的远程口令验证,软件则停留在登录界面。功能界面提供友好的操作,软件等待用户按下触屏按钮,一旦按钮被按下,软件向嵌入式网关发送相应的指令后,等待嵌入式网关响应,软件根据响应的信息更改对应的界面显示。

 

4 实验测试

 

7为手机客户端登陆界面,输入正确的嵌入式网关IP 地址、UDP 端口号以及远程口令访问嵌入式网关。系统需要测试无线数据和互联网数据的传输。在客户端侧安装网络抓包工具,并开启手机root权限,捕获发送和接收的数据。图8UDP数据在网络中的传输数据信息,与自定义帧格式一致。图9为客户端功能操作界面。

 

本文提出一种基于6LOWPAN 的智能家电监测和控制系统的非侵入解决方案,对系统的软硬件设计进行论述,最后对系统进行测试。系统各模块正常稳定工作,实现IPv6无线传感器网络与互联网的互联,用户通过客户端可以实时监测和控制家电的目标。

 

以上就是汉码未来今天给大家分享的文章,想了解更多关于物联网嵌入式的相关内容,可以登录汉码未来官网咨询,主打5人小班,全程面授,主打物联网嵌入式(人工智能)、Java全栈开发、鸿蒙应用开发、Linux云计算SRE工程师、C/C++AI人工智能大模型算法、游戏开发、Web前端开发、Python大数据、PHP等学习进修,有专业的授课老师为你答疑解惑。

tags: it培训
【免责声明】由于政策等各方面情况的不断调整与变化,本网站所提供的信息仅供参考,请以权威部门公布的正式信息为准。本网站在文章内容来源出处标注为其他平台的稿件均为转载稿,免费转载出于非商业性学习目的,版权归原作者所有。如您对内容、版权等问题存在异议请与本站联系,我们会及时进行处理解决。删除,请联系客服。
相关推荐HOT
FreeMarker template error (DEBUG mode; use RETHROW in production!): Template inclusion failed (for parameter value "./public/SingUp.ftl"): Template not found for name "./public/SingUp.ftl" (normalized: "public/SingUp.ftl"). The name was interpreted by this TemplateLoader: FileTemplateLoader(baseDir="/www/wwwroot/ruoyi/templatePath", canonicalBasePath="/www/wwwroot/ruoyi/templatePath/"). ---- FTL stack trace ("~" means nesting-related): - Failed at: #include "./public/SingUp.ftl" [in template "news.ftl" at line 451, column 3] ---- Java stack trace (for programmers): ---- freemarker.core._MiscTemplateException: [... Exception message was already printed; see it above ...] at freemarker.core.Include.accept(Include.java:164) at freemarker.core.Environment.visit(Environment.java:335) at freemarker.core.Environment.visit(Environment.java:341) at freemarker.core.Environment.process(Environment.java:314) at freemarker.template.Template.process(Template.java:383) at com.ruoyi.system.utils.FreeMarkerUtil.analysisTemplate(FreeMarkerUtil.java:39) at com.ruoyi.system.utils.MongoDBUtil.generateStaticFileAndSaveToMongoDBCommon(MongoDBUtil.java:431) at com.ruoyi.system.utils.MongoDBUtil.generateStaticFileAndSaveToMongoDBForTopic(MongoDBUtil.java:559) at com.ruoyi.system.service.impl.computerImpl.HanmaTopicDetailsServiceImpl.insertHanmaTopicDetails(HanmaTopicDetailsServiceImpl.java:149) at com.ruoyi.system.controller.HanmaTopicDetailsController.addSave(HanmaTopicDetailsController.java:130) at com.ruoyi.system.controller.HanmaTopicDetailsController$$FastClassBySpringCGLIB$$c9e76dc6.invoke() at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:792) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:762) at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:58) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:175) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:762) at org.springframework.aop.aspectj.AspectJAfterThrowingAdvice.invoke(AspectJAfterThrowingAdvice.java:64) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:175) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:762) at org.springframework.aop.framework.adapter.AfterReturningAdviceInterceptor.invoke(AfterReturningAdviceInterceptor.java:57) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:175) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:762) at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:58) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:175) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:762) at org.apache.shiro.spring.security.interceptor.AopAllianceAnnotationsAuthorizingMethodInterceptor$1.proceed(AopAllianceAnnotationsAuthorizingMethodInterceptor.java:82) at org.apache.shiro.authz.aop.AuthorizingMethodInterceptor.invoke(AuthorizingMethodInterceptor.java:39) at org.apache.shiro.spring.security.interceptor.AopAllianceAnnotationsAuthorizingMethodInterceptor.invoke(AopAllianceAnnotationsAuthorizingMethodInterceptor.java:115) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:762) at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:762) at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:707) at com.ruoyi.system.controller.HanmaTopicDetailsController$$EnhancerBySpringCGLIB$$8d8871cd.addSave() at jdk.internal.reflect.GeneratedMethodAccessor517.invoke(Unknown Source) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:568) at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:150) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:903) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:809) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1072) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:965) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909) at javax.servlet.http.HttpServlet.service(HttpServlet.java:555) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) at javax.servlet.http.HttpServlet.service(HttpServlet.java:623) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:209) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:153) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:178) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:153) at org.springframework.web.filter.CorsFilter.doFilterInternal(CorsFilter.java:91) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:178) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:153) at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61) at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108) at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137) at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:154) at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66) at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108) at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137) at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:154) at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66) at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108) at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137) at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:154) at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66) at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108) at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137) at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:154) at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66) at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108) at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137) at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:154) at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66) at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:458) at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:373) at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90) at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83) at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:387) at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:370) at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:154) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:178) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:153) at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:114) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:178) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:153) at com.ruoyi.system.filter.AppendSlashFilter.doFilter(AppendSlashFilter.java:25) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:178) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:153) at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:178) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:153) at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:178) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:153) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:178) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:153) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:167) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:90) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:481) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:130) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:93) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:390) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:63) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:926) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1791) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52) at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191) at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.base/java.lang.Thread.run(Thread.java:833) Caused by: freemarker.template.TemplateNotFoundException: Template not found for name "./public/SingUp.ftl" (normalized: "public/SingUp.ftl"). The name was interpreted by this TemplateLoader: FileTemplateLoader(baseDir="/www/wwwroot/ruoyi/templatePath", canonicalBasePath="/www/wwwroot/ruoyi/templatePath/"). at freemarker.template.Configuration.getTemplate(Configuration.java:2957) at freemarker.core.Environment.getTemplateForInclusion(Environment.java:3062) at freemarker.core.Include.accept(Include.java:162) ... 125 more