描述
<h3><strong><span style="font-family: 宋体;">1、项目功能介绍</span></strong></h3>
<hr align="center" width="100%">
<p><span style="font-family: 宋体;">智能网络看门狗是监控网络中的设备并在其异常时为其重启的一个小设备。智能网络看门狗通过对网络中设备(交换机、路由器、无线路由器、其他网络设备等)进行</span><span style="font-family: Calibri;">ping</span><span style="font-family: 宋体;">操作,从而判断该网络节点是否正常。当其多次</span><span style="font-family: Calibri;">ping</span><span style="font-family: 宋体;">不通时,通过继电器的掉电和上电对其进行重启。其中,对交换机、路由器等网络组网关键设备的意义更大, 这些设备如果在运行期间不幸死机,就会做成网络的瘫痪,因此使用网络看门狗对其进行监控有着一定的实用意义。</span></p>
<p> </p>
<p><span style="font-family: 宋体;">本项目实用模块</span><span style="font-family: Calibri;">ESP32-WROVER-E</span><span style="font-family: 宋体;">为主控,其具有的</span><span style="font-family: Calibri;">wifi</span><span style="font-family: 宋体;">和以太网功能能满足对有线网络和无线网络的监控,官方提供的</span><span style="font-family: Helvetica;">物联网开发框架</span><span style="font-family: Calibri;">ESP-IDF</span><span style="font-family: 宋体;">使用也很方便,提供很多实用的</span><span style="font-family: Calibri;">API</span><span style="font-family: 宋体;">,节省了很多开发的时间,同时丰富的例程也为功能的开发提供很好的参考。<strong><span style="color: #3598db;">使用该主控还有一个重要的原因,就是我想顺便学习如何使用</span></strong></span><strong><span style="font-family: Calibri; color: #3598db;">ESP32</span></strong><span style="font-family: 宋体;"><strong><span style="color: #3598db;">,日后方便搞点事情,嘿嘿。</span></strong>以太网</span><span style="font-family: Calibri;">phy</span><span style="font-family: 宋体;">使用</span><span style="font-family: Calibri;">dp83848ksq</span><span style="font-family: 宋体;">,</span><span style="font-family: Calibri;">QFN</span><span style="font-family: 宋体;">封装,体积较小。通过</span><span style="font-family: Calibri;">2</span><span style="font-family: 宋体;">个</span><span style="font-family: Calibri;">GPIO</span><span style="font-family: 宋体;">控制两个继电器,常开和常闭接口都引出,方便实用。电源部分使用</span><span style="font-family: Calibri;">lm2596</span><span style="font-family: 宋体;">和</span><span style="font-family: Calibri;">ams1117-3.3</span><span style="font-family: 宋体;">,提供</span><span style="font-family: Calibri;">5V</span><span style="font-family: 宋体;">和</span><span style="font-family: Calibri;">3.3V。</span></p>
<p> </p>
<p><span style="font-family: 宋体;">本项目电路板会自建一个</span><span style="font-family: Calibri;">AP</span><span style="font-family: 宋体;">,用手机或电脑连接后,可通过</span><span style="font-family: Calibri;">Web</span><span style="font-family: 宋体;">配置电路板的参数。有线以太网和无线</span><span style="font-family: Calibri;">STA</span><span style="font-family: 宋体;">作为两个独立的网卡,均可独立配置参数,</span><span style="font-family: Calibri;">Web</span><span style="font-family: 宋体;">网页采用</span><span style="font-family: Calibri;">Bootstrap</span><span style="font-family: 宋体;">前端架构来开发,通过</span><span style="font-family: Calibri;">Get</span><span style="font-family: 宋体;">和</span><span style="font-family: Calibri;">Post</span><span style="font-family: 宋体;">方式与程序进行交互。可配置的参数包括:</span></p>
<p><strong><span style="color: #000000; font-size: 14px;">1)<span style="font-family: 宋体;">有线以太网使能</span></span></strong></p>
<p><strong><span style="color: #000000; font-size: 14px;">2)<span style="font-family: 宋体;">有线以太网</span><span style="font-family: Calibri;">DHCP</span><span style="font-family: 宋体;">开启与否</span></span></strong></p>
<p><strong><span style="color: #000000; font-size: 14px;">3)<span style="font-family: 宋体;">有线以太网</span><span style="font-family: Calibri;">IP</span><span style="font-family: 宋体;">地址</span></span></strong></p>
<p><strong><span style="color: #000000; font-size: 14px;">4)<span style="font-family: 宋体;">有线以太网网关地址</span></span></strong></p>
<p><strong><span style="color: #000000; font-size: 14px;">5)<span style="font-family: 宋体;">有线以太网子网掩码</span></span></strong></p>
<p><strong><span style="color: #000000; font-size: 14px;">6)<span style="font-family: 宋体;">有线以太网</span><span style="font-family: Calibri;">MAC</span><span style="font-family: 宋体;">地址</span></span></strong></p>
<p><strong><span style="color: #000000; font-size: 14px;">7)<span style="font-family: 宋体;">有线以太网</span><span style="font-family: Calibri;">Ping</span><span style="font-family: 宋体;">目标地址</span></span></strong></p>
<p><strong><span style="color: #000000; font-size: 14px;">8)<span style="font-family: 宋体;">有线以太网</span><span style="font-family: Calibri;">Ping</span><span style="font-family: 宋体;">周期</span></span></strong></p>
<p><strong><span style="color: #000000; font-size: 14px;">9)<span style="font-family: 宋体;">有线以太网最大</span><span style="font-family: Calibri;">Ping</span><span style="font-family: 宋体;">次数</span></span></strong></p>
<p><strong><span style="color: #000000; font-size: 14px;">10)<span style="font-family: 宋体;">有线以太网</span><span style="font-family: Calibri;">Ping</span><span style="font-family: 宋体;">关断时间</span></span></strong></p>
<p><strong><span style="color: #000000; font-size: 14px;">11)<span style="font-family: 宋体;">有线以太网</span><span style="font-family: Calibri;">Ping</span><span style="font-family: 宋体;">重启时间</span></span></strong></p>
<p><strong><span style="color: #000000; font-size: 14px;">12)<span style="font-family: Calibri;">Wifi STA</span><span style="font-family: 宋体;">使能</span></span></strong></p>
<p><strong><span style="color: #000000; font-size: 14px;">13)<span style="font-family: Calibri;">Wifi STA SSID</span></span></strong></p>
<p><strong><span style="color: #000000; font-size: 14px;">14)<span style="font-family: Calibri;">Wifi STA </span><span style="font-family: 宋体;">密码</span></span></strong></p>
<p><strong><span style="color: #000000; font-size: 14px;">15)<span style="font-family: Calibri;">Wifi STA DHCP</span><span style="font-family: 宋体;">开启与否</span></span></strong></p>
<p><strong><span style="color: #000000; font-size: 14px;">16)<span style="font-family: Calibri;">Wifi STA IP</span><span style="font-family: 宋体;">地址</span></span></strong></p>
<p><strong><span style="color: #000000; font-size: 14px;">17)<span style="font-family: Calibri;">Wifi STA</span><span style="font-family: 宋体;">网关地址</span></span></strong></p>
<p><strong><span style="color: #000000; font-size: 14px;">18)<span style="font-family: Calibri;">Wifi STA</span><span style="font-family: 宋体;">子网掩码</span></span></strong></p>
<p><strong><span style="color: #000000; font-size: 14px;">19)<span style="font-family: Calibri;">Wifi STA MAC</span><span style="font-family: 宋体;">地址</span></span></strong></p>
<p><strong><span style="color: #000000; font-size: 14px;">20)<span style="font-family: Calibri;">Wifi STA Ping</span><span style="font-family: 宋体;">目标地址</span></span></strong></p>
<p><strong><span style="color: #000000; font-size: 14px;">21)<span style="font-family: Calibri;">Wifi STA Ping</span><span style="font-family: 宋体;">周期</span></span></strong></p>
<p><strong><span style="color: #000000; font-size: 14px;">22)<span style="font-family: Calibri;">Wifi STA</span><span style="font-family: 宋体;">最大</span><span style="font-family: Calibri;">Ping</span><span style="font-family: 宋体;">次数</span></span></strong></p>
<p><strong><span style="color: #000000; font-size: 14px;">23)<span style="font-family: Calibri;">Wifi STA Ping</span><span style="font-family: 宋体;">关断时间</span></span></strong></p>
<p><strong><span style="color: #000000; font-size: 14px;">24)<span style="font-family: Calibri;">Wifi STA Ping</span><span style="font-family: 宋体;">重启时间</span></span></strong></p>
<p><strong><span style="color: #000000; font-size: 14px;">25)<span style="font-family: Calibri;">Wifi AP SSID</span></span></strong></p>
<p><strong><span style="color: #000000; font-size: 14px;">26)<span style="font-family: Calibri;">Wifi AP </span><span style="font-family: 宋体;">密码</span></span></strong></p>
<p><strong><span style="color: #000000; font-size: 14px;">27)<span style="font-family: 宋体;">继电器</span><span style="font-family: Calibri;">0</span><span style="font-family: 宋体;">绑定规则</span></span></strong></p>
<p><strong><span style="color: #000000; font-size: 14px;">28)<span style="font-family: 宋体;">继电器</span><span style="font-family: Calibri;">1</span><span style="font-family: 宋体;">绑定规则</span></span></strong></p>
<p> </p>
<p><strong><span style="font-family: Calibri;">Ping</span></strong><span style="font-family: 宋体;"><strong>周期:</strong>在正常情况下,主机向目标发起一次</span><span style="font-family: Calibri;">Ping</span><span style="font-family: 宋体;">测试的时间间隔。</span></p>
<p><strong><span style="font-family: 宋体;">最大</span><span style="font-family: Calibri;">Ping</span></strong><span style="font-family: 宋体;"><strong>次数:</strong>当</span><span style="font-family: Calibri;">Ping</span><span style="font-family: 宋体;">不通时重试的最大次数。</span></p>
<p><strong><span style="font-family: Calibri;">Ping</span></strong><span style="font-family: 宋体;"><strong>关断时间:</strong>当</span><span style="font-family: Calibri;">Ping</span><span style="font-family: 宋体;">测试失败后,会关闭继电器,过一段时间才重新开启,这个间隔的时间就是</span><span style="font-family: Calibri;">Ping</span><span style="font-family: 宋体;">关断时间。</span></p>
<p><strong><span style="font-family: Calibri;">Ping</span></strong><span style="font-family: 宋体;"><strong>重启时间:</strong>当继电器关闭后重启,要过一段时间再重新进行</span><span style="font-family: Calibri;">Ping</span><span style="font-family: 宋体;">测试,这段时间给与目标重启的时间,这段时间叫</span><span style="font-family: Calibri;">Ping</span><span style="font-family: 宋体;">重启时间。</span></p>
<p><span style="font-family: 宋体;"><strong>继电器绑定规则:</strong>继电器能绑定在有线以太网、</span><span style="font-family: Calibri;">wifi sta ping</span><span style="font-family: 宋体;">测试失败后进行动作,可绑定为有线以太网、</span><span style="font-family: Calibri;">wifi sta</span><span style="font-family: 宋体;">、有线以太网或</span><span style="font-family: Calibri;">wifi sta</span><span style="font-family: 宋体;">、有线以太网与</span><span style="font-family: Calibri;">wifi sta</span><span style="font-family: 宋体;">。</span></p>
<p> </p>
<p><span style="font-family: 宋体;">电路板会按照配置的参数向目标地址发起</span><span style="font-family: Calibri;">Ping</span><span style="font-family: 宋体;">测试,</span><span style="font-family: Calibri;">Ping</span><span style="font-family: 宋体;">不通时,会进行限制次数内重试,如果还是不通,则判为</span><span style="font-family: Calibri;">Ping</span><span style="font-family: 宋体;">测试失败。之后会按照继电器规则关断继电器,一段时间后重新打开,再一段时间后重新开始</span><span style="font-family: Calibri;">Ping</span><span style="font-family: 宋体;">测试。</span></p>
<h3><strong><span style="font-family: 宋体;">2、项目属性</span></strong></h3>
<hr align="center" width="100%">
<p><span style="font-family: 宋体;">原创</span><span style="font-family: Calibri;">/</span><span style="font-family: 宋体;">首次公开</span><span style="font-family: Calibri;">/</span><span style="font-family: 宋体;">没在其他比赛中获奖</span></p>
<h3><strong><span style="font-family: 宋体;">3、开源协议</span></strong></h3>
<hr align="center" width="100%">
<p><span style="font-family: Calibri;">GPL3.0</span></p>
<p> </p>
<h3><strong><span style="font-family: 宋体;">4、硬件部分</span></strong></h3>
<hr align="center" width="100%">
<p><span style="font-family: 宋体;">电路板</span><span style="font-family: Calibri;">PCB</span><span style="font-family: 宋体;">使用</span><span style="font-family: Calibri;">KiCAD</span><span style="font-family: 宋体;">来设计,分为</span><span style="font-family: Calibri;">ESP32-WROVER-E</span><span style="font-family: 宋体;">模块最小系统模块、电源模块、网口模块和继电器模块。</span></p>
<p><strong><span style="font-family: Calibri;">ESP32-WROVER-E</span><span style="font-family: 宋体;">模块最小系统模块</span></strong></p>
<p><img src="//image.lceda.cn/pullimage/pBoILpqjGNzE1pgoyxQPMwFE10zIN0EYjTCXGnYQ.png"></p>
<p><span style="font-family: 宋体;">模块最小系统的设计难度不大,按照数据手册来就行,这里使用</span><span style="font-family: Calibri;">IO33</span><span style="font-family: 宋体;">来控制运行灯,通过排针</span><span style="font-family: Calibri;">J3</span><span style="font-family: 宋体;">引出</span><span style="font-family: Calibri;">UART0</span><span style="font-family: 宋体;">,用于下载程序和调试程序,感觉一般的开发不用用到</span><span style="font-family: Calibri;">jtag</span><span style="font-family: 宋体;">接口来跟踪,</span><span style="font-family: Calibri;">esp-idf</span><span style="font-family: 宋体;">的串口</span><span style="font-family: Calibri;">debug</span><span style="font-family: 宋体;">能力已经足够好用了。</span><span style="font-family: Calibri;">J2</span><span style="font-family: 宋体;">引出</span><span style="font-family: Calibri;">boot</span><span style="font-family: 宋体;">脚,因为这里</span><span style="font-family: Calibri;">RMII</span><span style="font-family: 宋体;">接口使用了这个脚,用排针引出,跳线帽选择,下载程序时接地,运行时接</span><span style="font-family: Calibri;">CLK</span><span style="font-family: 宋体;">。</span></p>
<p> </p>
<p><strong><span style="font-family: 宋体;">电源模块</span></strong></p>
<p><img src="//image.lceda.cn/pullimage/bRwyHbFKaUFd5cjlQfoPMgZ6iEfz7x8J2F5Plo1p.png"></p>
<p><span style="font-family: 宋体;">继电器驱动需要</span><span style="font-family: Calibri;">5V</span><span style="font-family: 宋体;">,其他芯片需要</span><span style="font-family: Calibri;">3.3V</span><span style="font-family: 宋体;">,这里使用</span><span style="font-family: Calibri;">lm2596s-5</span><span style="font-family: 宋体;">和</span><span style="font-family: Calibri;">ams1117-3.3</span><span style="font-family: 宋体;">提供,允许</span><span style="font-family: Calibri;">7-40V</span><span style="font-family: 宋体;">输入。</span></p>
<p> </p>
<p><strong><span style="font-family: 宋体;">网口模块</span></strong></p>
<p><img src="//image.lceda.cn/pullimage/NazwraNiyv42mKIzIrQeTLQ1xcw875LuK4qFRcJB.png"></p>
<p><span style="font-family: 宋体;">网口</span><span style="font-family: Calibri;">PHY</span><span style="font-family: 宋体;">使用</span><span style="font-family: Calibri;">dp83848ksq</span><span style="font-family: 宋体;">,网口使用</span><span style="font-family: Calibri;">HR911105A</span><span style="font-family: 宋体;">,设计一定要仔细看数据手册。这里使用</span><span style="font-family: Calibri;">ESP32</span><span style="font-family: 宋体;">发生的</span><span style="font-family: Calibri;">50MHZ</span><span style="font-family: 宋体;">时钟作为</span><span style="font-family: Calibri;">dp83848ksq</span><span style="font-family: 宋体;">的的时钟,中间需要经过一个非门。</span></p>
<p> </p>
<p><strong><span style="font-family: 宋体;">继电器模块</span></strong></p>
<p><img src="//image.lceda.cn/pullimage/bMjlbGi4uokcHfPENeKRuxL1viy0Ehb2ysNW4Bkt.png"></p>
<p><span style="font-family: 宋体;">采用一个三极管</span><span style="font-family: Calibri;">bc817</span><span style="font-family: 宋体;">去驱动继电器,同时并联一个</span><span style="font-family: Calibri;">led</span><span style="font-family: 宋体;">作为显示,并联一个二极管方便电流回流。</span></p>
<p> </p>
<h3><strong><span style="font-family: 宋体;">5、软件部分</span></strong></h3>
<hr align="center" width="100%">
<p><span style="font-family: 宋体;">软件开发环境:</span><span style="font-family: Calibri;">eclipse2020+esp-idf v4.2</span><span style="font-family: 宋体;">(编译时请关闭</span><span style="font-family: Calibri;">360~</span><span style="font-family: 宋体;">)</span></p>
<p><span style="font-family: Calibri;">Web</span><span style="font-family: 宋体;">网页:</span><span style="font-family: Calibri;">bootstrap+jquery</span></p>
<p><img src="//image.lceda.cn/pullimage/7rc1fsiZcrvIfo3vGRhEWBL18RSOUYODoBbk1tpM.png"></p>
<p><span style="font-family: 宋体;">软件部分有主程序、网络模块、参数模块、继电器驱动模块、</span><span style="font-family: Calibri;">web</span><span style="font-family: 宋体;">模块组成。</span></p>
<p> </p>
<p><strong><span style="font-family: 宋体;">网络模块</span></strong></p>
<p><span style="font-family: 宋体;">网络模块负责读取网络参数,然后通过网络参数调用</span><span style="font-family: Calibri;">api</span><span style="font-family: 宋体;">对</span><span style="font-family: Calibri;">eth</span><span style="font-family: 宋体;">、</span><span style="font-family: Calibri;">sta</span><span style="font-family: 宋体;">、</span><span style="font-family: Calibri;">ap</span><span style="font-family: 宋体;">进行初始化,同时定义一些处理网络基本的回调函数。</span></p>
<p> </p>
<p><strong><span style="font-family: 宋体;">参数模块</span></strong></p>
<p><span style="font-family: 宋体;">参数模块使用</span><span style="font-family: Calibri;">nvs_flash api</span><span style="font-family: 宋体;">,在</span><span style="font-family: Calibri;">flash</span><span style="font-family: 宋体;">中对参数进行读写以及默认的设置。</span></p>
<p> </p>
<p><strong><span style="font-family: 宋体;">继电器驱动模块</span></strong></p>
<p><span style="font-family: 宋体;">继电器驱动模块封装了一些</span><span style="font-family: Calibri;">GPIO</span><span style="font-family: 宋体;">初始化和置位的函数。</span></p>
<p> </p>
<p><strong><span style="font-family: Calibri;">Web</span><span style="font-family: 宋体;">模块</span></strong></p>
<p><span style="font-family: Calibri;">Web</span><span style="font-family: 宋体;">模块使用</span><span style="font-family: Calibri;">http_server api</span><span style="font-family: 宋体;">,定义对应的</span><span style="font-family: Calibri;">url</span><span style="font-family: 宋体;">以及完成相应的回调函数。包括读参数、写参数、设置默认参数。</span></p>
<p> </p>
<p><strong><span style="font-family: 宋体;">主程序</span></strong></p>
<p><span style="font-family: 宋体;">主程序采用状态机机制,状态机的状态切换图如下。</span></p>
<p><img src="//image.lceda.cn/pullimage/ha8OvBlBJjNQFzB477w3NWnJT0XcHINsMEBLcuIX.png"></p>
<p><span style="font-family: 宋体;">程序过程分成四个状态:空闲态、测试态、关断态、重启态。</span></p>
<p><span style="font-family: 宋体;">在空闲态中,以系统时间戳为参考,检测是否到达测试周期,如果到达则发起测试并进入测试态;</span></p>
<p><span style="font-family: 宋体;">在测试态中,通过回调函数判断</span><span style="font-family: Calibri;">ping</span><span style="font-family: 宋体;">的结果,如果成功则返回空闲态,如果失败则重试,重试都失败就关断继电器并进入关断态;</span></p>
<p><span style="font-family: 宋体;">在关断态中,以系统时间戳为参考,检测是否到达关断时间,如果到达则开启继电器进入重启态;</span></p>
<p><span style="font-family: 宋体;">在重启态中,以系统时间戳为参考,检测是否到达重启时间,如果到达则发起测试并进入测试态;</span> </p>
<p> </p>
<p><span style="color: #e03e2d;"><span style="font-family: 宋体;">注:在开发过程中发现了</span><span style="font-family: Calibri;">ESP-idf v4.2</span><span style="font-family: 宋体;">的一个</span><span style="font-family: Calibri;">bug</span></span></p>
<p><span style="font-family: 宋体;">由于项目使用了多个网卡接入</span><span style="font-family: Calibri;">LWIP</span><span style="font-family: 宋体;">,因而使用</span><span style="font-family: Calibri;">ping api</span><span style="font-family: 宋体;">时需要指点网卡号。</span></p>
<p><span style="font-family: 宋体;">在网卡初始化时可通过</span><strong><span style="font-family: Consolas;">esp_netif_get_netif_impl_index</span></strong><span style="font-family: 宋体;">来获取网卡号;</span></p>
<p><span style="font-family: 宋体;">使用</span><span style="font-family: Calibri;">ping api </span><span style="font-family: 宋体;">可通过配置</span><span style="font-family: Calibri;">interface</span><span style="font-family: 宋体;">属性来指定网卡号,然而这样的设置会报错。</span></p>
<p><img src="//image.lceda.cn/pullimage/VJZhZmWosNNXOAQB2SqxCFhO1f88YyFfX7kQi8xC.png"></p>
<p><span style="font-family: 宋体;">打开</span><span style="font-family: Calibri;">esp-idf\esp-idf-v4.2\components\lwip\apps\ping\ping_sock.c</span></p>
<p><img src="//image.lceda.cn/pullimage/16ZRe7wN3UYQhiAQ9fJY1tnSwJxCfPJ0bCySoKU5.png"></p>
<p><span style="font-family: 宋体;">发现这里有个</span><span style="font-family: Calibri;">bug</span><span style="font-family: 宋体;">,导致选择网卡后会报错。</span></p>
<p><span style="font-family: 宋体;">可根据</span></p>
<p><img src="//image.lceda.cn/pullimage/hwPHxw3wZXzliYk8osoQxd1j7Kuufargtfyf80Rx.png"></p>
<p><span style="font-family: 宋体;">使用以下的方法绕开这个</span><span style="font-family: Calibri;">bug</span></p>
<p><img src="//image.lceda.cn/pullimage/2KvcAFFjI9gvp4lSDhlL88Ko6pLQ1iXxbO9P6zUr.png"></p>
<p> </p>
<h3><strong><span style="font-family: 宋体;">6、BOM清单</span></strong></h3>
<hr align="center" width="100%">
<p><img src="//image.lceda.cn/pullimage/GP4CD4N3X7ncNm0Qmh0kCIYQn9BjF5pEI5H4ZwzJ.png"></p>
<p> </p>
<h3><strong><span style="font-family: 宋体;">7、大赛LOGO验证</span></strong></h3>
<hr align="center" width="100%">
<p><img src="//image.lceda.cn/pullimage/N3nl7HcS5xokGnXSOE3pVnNTOI32eEMFZXqteqSi.png"></p>
<p><img src="//image.lceda.cn/pullimage/u3a5gZeJonn7BRK95o6Vs2R7ZGNKkMqm984AqEfc.png"></p>
<p><img src="//image.lceda.cn/pullimage/HneZpIG8MmjGLgYAmnr5iF4SXfPJfyR5er37lpiW.png"></p>
<p><img src="//image.lceda.cn/pullimage/HZ83aGquo0EsgxHjM3txdm3ut0lxSHaFiX0sDRg4.png"></p>
<p><img src="//image.lceda.cn/pullimage/Zmc8W2k1q7F2DqmETskN28duJvV67mlRFCBeAWoc.png"></p>
<p> </p>
<p> </p>
<p> </p>
评论(6)