Use Arduino to monitor the process blocking in MSSQL database



One day I opened a brain hole and filled it in again. I did a process to monitor the process blocking of the MSSQL database that the company is using. You are always happy to be a living boss who works on a PC at the price of one or two cups of star dad. .

This brain hole is like this: Arduino connects to the network module to access the local area network, and regularly (tentatively 8 seconds) visits a webpage. This webpage is used to detect and return the number of MSSQL process blocking at that time. Arduino receives and parses the return result of the webpage, if there is zero blocking, it lights green LED; if there are 1-5 blocks, it lights green and yellow LED at the same time; if there are more than 5 blocks, it lights yellow and red simultaneously; if only The red light indicates that there is an error in this small system.

Of course, because it is refreshed regularly, there will be a certain time lag. In general, try to be a concept toy first.

So the core question is how to access the webpage, and of course the basic foundation is how to access the network.

A treasure got a ENC28J60 network module, tried to learn one. First of all, of course, wiring, this is relatively clear, just follow the SPI definition.
Module-Arduino
SCK-D13
SO-D12
SI-D11
CS-D10 *
RST-RESET
GND-GND
VCC-3.3V **

Note:
*: D10 can be changed to other ones, because it needs to be reflected In the initialization code.
**: 3.3V may cause the power supply of the network module to be insufficient to work. Mine is like this. If VCC is connected to 3.3V of my cottage Arduino Nano, the measured voltage between VCC and GND of the module is only 2.8V. You can use the 5V power supply of that cottage nano, but 28J60 will cause severe fever for a long time. I am cutting a Dupont cable, and a 1N4007 is connected in the middle to use its forward voltage drop to drop it to VCC.

Drive to find what the seller wants, so easy to use. But my actual situation is slightly more complicated: the network is not a standard C network, and there is a gateway and DNS, so I checked the information and used the following code when setting the IP address:
static uint8_t mac [] = {0xF4, 0x8E , 0x38, 0xA4, 0x30, 0x31}; // Ensure that 6 bytes are enough, just write it. But the first byte must be even.
const static uint8_t ip [] = {10, 16, 39, 40};
const static uint8_t gwip [] = {10, 16, 36, 1};
const static uint8_t dns [] = {172.16.10.12};
const static uint8_t subnet [] = {255, 255, 252, 0}; The

calling sequence is: ether.staticSetup (ip, gwip, dns, subnet)

The code for accessing the webpage is from http://www.rogerclark.net/aurduino-ethercard- multiple-browser-request-example / . It's a little complicated, but it's more comprehensive and supports accessing multiple web pages at once. Considering that there may be this demand in the future, I received this article first.

For the sake of simplicity and convenience, and in conjunction with the existing ASP.NET architecture of the organization, the webpage uses ashx, it is nothing more than that it needs to query the current blocking number and return this number. In principle, using php is no problem, anyway, it can return a text / plain stream. The next difficulty after getting the content returned by ashx is how to parse out the results you really want. Because HTTP headers always exist, they need to be thrown away. My approach is to use the lastIndexOf function of the String class to find the position of the last "\ r" in all the characters obtained, and intercept the +2 position from here to the end.

The LED display has nothing to spend, consumes 3 IO ports and is based on business logic digitalWrite high and low levels.

The effect is this:

If this is under the packaging of Zhenger's Eight Classics, then it should be spectacular to make it seventeen or eighty rows into a wall ~

Published 122 original articles · Like 61 · Visits 530,000+

Guess you like

Origin blog.csdn.net/ki1381/article/details/72721773