An intelligent network watchdog is a small device that monitors devices on the network and restarts them when they are abnormal. The intelligent network watchdog determines whether the network node is normal by pinging the devices in the network (switches, routers, wireless routers, other network devices, etc.). When it fails to ping multiple times , restart it by powering down and powering on the relay. Among them, it is of greater significance to key network equipment such as switches and routers. If these equipment unfortunately crash during operation, the network will be paralyzed. Therefore, using a network watchdog to monitor them has certain practical significance.
The practical module ESP32-WROVER-E of this project is the main control. Its wifi and Ethernet functions can meet the monitoring of wired and wireless networks. The officially provided Internet of Things development framework ESP-IDF is also very convenient to use and provides many practical The API saves a lot of development time, and the rich routines also provide a good reference for function development. Another important reason for using this main control is that I want to learn how to use ESP32 by the way , so that I can do something convenient in the future, hehe. Ethernet phy uses dp83848ksq , QFN package, small size. Two relays are controlled through 2 GPIOs , and both normally open and normally closed interfaces are drawn out, which is convenient and practical. The power supply part uses lm2596 and ams1117-3.3 to provide 5V and 3.3V.
The circuit board of this project will build its own AP . After connecting with a mobile phone or computer, the parameters of the circuit board can be configured through the Web . As two independent network cards, wired Ethernet and wireless STA can configure parameters independently. Web pages are developed using Bootstrap front-end architecture, and interact with programs through Get and Post methods. Configurable parameters include:
1) Wired Ethernet enabled
2) Whether wired Ethernet DHCP is enabled or not
3) Wired Ethernet IP address
4) Wired Ethernet gateway address
5) Wired Ethernet subnet mask
6) Wired Ethernet MAC address
7) Wired Ethernet Ping target address
8) Wired Ethernet Ping Cycle
9) Maximum number of pings on wired Ethernet
10) Wired Ethernet Ping shutdown time
11) Wired Ethernet Ping restart time
12) Wifi STA enable
13) Wifi STA SSID
14) Wifi STA password
15) Whether Wifi STA DHCP is turned on or not
16) Wifi STA IP address
17) Wifi STA gateway address
18) Wifi STA subnet mask
19) Wifi STA MAC address
20) Wifi STA Ping target address
21) Wifi STA Ping cycle
22) Wifi STA maximum number of pings
23) Wifi STA Ping shutdown time
24) Wifi STA Ping restart time
25) Wifi AP SSID
26) Wifi AP password
27) Relay 0 binding rules
28) Relay 1 binding rules
Ping cycle: Under normal circumstances, the time interval at which the host initiates a Ping test to the target.
Maximum number of Pings : The maximum number of retries when Ping fails .
Ping off time: When the Ping test fails, the relay will be turned off and then turned back on after a period of time. This interval is the Ping off time.
Ping重启时间:当继电器关闭后重启,要过一段时间再重新进行Ping测试,这段时间给与目标重启的时间,这段时间叫Ping重启时间。
继电器绑定规则:继电器能绑定在有线以太网、wifi sta ping测试失败后进行动作,可绑定为有线以太网、wifi sta、有线以太网或wifi sta、有线以太网与wifi sta。
电路板会按照配置的参数向目标地址发起Ping测试,Ping不通时,会进行限制次数内重试,如果还是不通,则判为Ping测试失败。之后会按照继电器规则关断继电器,一段时间后重新打开,再一段时间后重新开始Ping测试。
原创/首次公开/没在其他比赛中获奖
GPL3.0
电路板PCB使用KiCAD来设计,分为ESP32-WROVER-E模块最小系统模块、电源模块、网口模块和继电器模块。
ESP32-WROVER-E模块最小系统模块
模块最小系统的设计难度不大,按照数据手册来就行,这里使用IO33来控制运行灯,通过排针J3引出UART0,用于下载程序和调试程序,感觉一般的开发不用用到jtag接口来跟踪,esp-idf的串口debug能力已经足够好用了。J2引出boot脚,因为这里RMII接口使用了这个脚,用排针引出,跳线帽选择,下载程序时接地,运行时接CLK。
电源模块
继电器驱动需要5V,其他芯片需要3.3V,这里使用lm2596s-5和ams1117-3.3提供,允许7-40V输入。
网口模块
网口PHY使用dp83848ksq,网口使用HR911105A,设计一定要仔细看数据手册。这里使用ESP32发生的50MHZ时钟作为dp83848ksq的的时钟,中间需要经过一个非门。
继电器模块
采用一个三极管bc817去驱动继电器,同时并联一个led作为显示,并联一个二极管方便电流回流。
软件开发环境:eclipse2020+esp-idf v4.2(编译时请关闭360~)
Web网页:bootstrap+jquery
软件部分有主程序、网络模块、参数模块、继电器驱动模块、web模块组成。
网络模块
网络模块负责读取网络参数,然后通过网络参数调用api对eth、sta、ap进行初始化,同时定义一些处理网络基本的回调函数。
参数模块
参数模块使用nvs_flash api,在flash中对参数进行读写以及默认的设置。
继电器驱动模块
继电器驱动模块封装了一些GPIO初始化和置位的函数。
Web模块
Web模块使用http_server api,定义对应的url以及完成相应的回调函数。包括读参数、写参数、设置默认参数。
主程序
主程序采用状态机机制,状态机的状态切换图如下。
程序过程分成四个状态:空闲态、测试态、关断态、重启态。
在空闲态中,以系统时间戳为参考,检测是否到达测试周期,如果到达则发起测试并进入测试态;
在测试态中,通过回调函数判断ping的结果,如果成功则返回空闲态,如果失败则重试,重试都失败就关断继电器并进入关断态;
在关断态中,以系统时间戳为参考,检测是否到达关断时间,如果到达则开启继电器进入重启态;
在重启态中,以系统时间戳为参考,检测是否到达重启时间,如果到达则发起测试并进入测试态;
注:在开发过程中发现了ESP-idf v4.2的一个bug
由于项目使用了多个网卡接入LWIP,因而使用ping api时需要指点网卡号。
在网卡初始化时可通过esp_netif_get_netif_impl_index来获取网卡号;
Using the ping api , you can specify the network card number by configuring the interface attribute. However, such a setting will report an error.
Open esp-idfesp-idf-v4.2componentslwipappspingping_sock.c
Found a bug here , causing an error to be reported after selecting the network card.
can be based on
Use the following methods to bypass this bug
All reference designs on this site are sourced from major semiconductor manufacturers or collected online for learning and research. The copyright belongs to the semiconductor manufacturer or the original author. If you believe that the reference design of this site infringes upon your relevant rights and interests, please send us a rights notice. As a neutral platform service provider, we will take measures to delete the relevant content in accordance with relevant laws after receiving the relevant notice from the rights holder. Please send relevant notifications to email: bbs_service@eeworld.com.cn.
It is your responsibility to test the circuit yourself and determine its suitability for you. EEWorld will not be liable for direct, indirect, special, incidental, consequential or punitive damages arising from any cause or anything connected to any reference design used.
Supported by EEWorld Datasheet