Adding an LED Alert to WavesBlock Full Node Monitor

Whilst I have found the WavesBlock monitor useful for checking on my Full Node (See original WavesBlock post here) And I often give it a quick glance to check everything is fine, sometimes when I'm busy and not paying much attention to it, It would be easy to miss when there's an issue.

I decided to add a small LED to the block that can simply switch on when there's something that needs reviewing, for example, Disk usage high, Server not responding, or even positive alerts like on mining a block.

The feature is divided up into 3 tasks; - Add an LED to the case and connect it to the NodeMcu - Modify the server page to return an alert status - Modify the NodeMcu code to switch on the LED when theres an alert, or connectivity issues

Here's how it turned out, and below I'll describe how to implement it.

close.jpg

Step 1 - Add the LED I drilled a small hole in the case and glued in an LED, connecting the + pin (The longest pin) to pin 7 on the node MCU, and the ground to GND.

boxled.jpg

Step 2 - Modify the server code I modified the server response to contain a boolean flag named 'alert'. Now, it's up to you what you want to alert for here, I opted for High Disk, Mem, CPU, and when the server is not mining. It's easy enough to add to this in future, I initially set it to true, so I can test the LED.

if($disk > 80 || $ram > 80 || $cpupc > 90 || $debugStatus['minerState'] != 'mining blocks') {
  $alert = true;
}

Step 3 - Modify the NodeMCU code. Here we need to check the alert flag, and set the pin we attached the LED to (Pin 7 in this case) to HIGH. Because this code runs every 60 seconds, I'm happy that the LED will light for a full cycle, should there be an issue, and if its resolved by the next cycle, it will go out. I also lit it if there's a HTTP connection error. Additionally, we set up the pin in init.lua.

If all is well, and you have set alert to true in the PHP script, your LED should light up on the next cycle. Now, it's time to try and max out your CPU and test it for real!

Hope this was useful, and if you have an questions feel free to comment.

desk.jpg



Posted on Utopian.io - Rewarding Open Source Contributors