Radmon.org Mini Monitor
8 months 1 day ago - 7 months 3 weeks ago #6900
by Simomax
I knocked up a simple monitor to easily see if radmon.org is up or down. It uses an ESP8266 (Wemos D1 mini clone) and a single RGB LED. It simply polls radmon.org by asking for a response from the server. If it gets the reply it is expecting in a timely manner it lights the LED green. If it doesn't get the reply it wants, or times out, the LED changes to orange and sets a fail counter +1. If it receives the correct reply again it goes back to green, but after 3 consecutive failures the LED lights red. There really isn't much more to it. There are positions in the code where an alarm or something else could be activated and also deactivated. It has two modes - lightweight or not. In lightweight mode (lightweight = true) the monitor calls a simple HTML page with the text 'pong' in it. The other mode (lightweight = false) sends a query to the radmon api and the request is processed by radmon core. It then chucks out the same 'pong' for the monitor. The latter method uses more CPU cycles so unless some specific testing is being done the lightweight mode works fine.
The LED is one from a kit or something. It has the resistors already on the PCB with the LED, so make sure you use the right resistors for each colour of the LED if you decide to make this. The LED was very bright (clear type) so I threw a splodge of hot glue on it to diffuse it. Now it looks a little like a small glowing grape as it sits at the back of my breadboard!
Radmon.org Mini Monitor was created by Simomax
I knocked up a simple monitor to easily see if radmon.org is up or down. It uses an ESP8266 (Wemos D1 mini clone) and a single RGB LED. It simply polls radmon.org by asking for a response from the server. If it gets the reply it is expecting in a timely manner it lights the LED green. If it doesn't get the reply it wants, or times out, the LED changes to orange and sets a fail counter +1. If it receives the correct reply again it goes back to green, but after 3 consecutive failures the LED lights red. There really isn't much more to it. There are positions in the code where an alarm or something else could be activated and also deactivated. It has two modes - lightweight or not. In lightweight mode (lightweight = true) the monitor calls a simple HTML page with the text 'pong' in it. The other mode (lightweight = false) sends a query to the radmon api and the request is processed by radmon core. It then chucks out the same 'pong' for the monitor. The latter method uses more CPU cycles so unless some specific testing is being done the lightweight mode works fine.
The LED is one from a kit or something. It has the resistors already on the PCB with the LED, so make sure you use the right resistors for each colour of the LED if you decide to make this. The LED was very bright (clear type) so I threw a splodge of hot glue on it to diffuse it. Now it looks a little like a small glowing grape as it sits at the back of my breadboard!
//Radmon.org mini monitor by Simomax
//
//This uses an RGB LED to show the online status of radmon.org by requesting a reply from a web page there. If the monitor receives the
//reply it expects it will light up green. When it hasn't received a reply, or the wrong reply, it starts a fail counter and the LED lights
//yellow. After 3 subsequent failures the LED lights red. Upon receiving the correct reply the LED will light green again and the fail
//counter is reset.
//
//TThere are two methods of receiving the reply. One is a simple html page with the reply (lightWeight = true), and the other passes the
//query through the radmon api. The latter taking more time and using more cpu cycles. Unless specific testing it is recommended to use
//'lightWeight = true'. The interval in which the monitor polls can be configured with the 'interval' variable. Recommended times are 10-30
//seconds for 'lightWeight = true', and 30-60 seconds for 'lightWeight = false'.
//
//The LED colours can be customised to your preference and you can add extra code for external alarms and such below where commented.
//
//There is no license with this. You are free to do as you choose with this code. It may break. If it does, you get to keep all the parts.
int interval = 10; //Poll every X seconds. Suggested time/operations: 10-30 seconds for light weight mode, 30-60 seconds for regular mode.
int lightWeight = true; //Mode.
int counter = 0;
const char* URL = "";
#define red D2 // LED pins
#define green D3
#define blue D4
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>
ESP8266WiFiMulti WiFiMulti;
void ledsOff() {
digitalWrite(red, LOW);
digitalWrite(green, LOW);
digitalWrite(blue, LOW);
}
void setup() {
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
pinMode(blue, OUTPUT);
ledsOff();
Serial.begin(115200);
Serial.println("Starting...");
Serial.println();
Serial.println();
delay(1000); // It is good to have a small delay between the ESP starting and initializing the WiFi. The LEDs light to save boredom.
digitalWrite(red, HIGH);
delay(1000);
digitalWrite(green, HIGH);
delay(1000);
digitalWrite(blue, HIGH);
delay(1000);
ledsOff();
delay(1000);
WiFi.mode(WIFI_STA);
WiFiMulti.addAP("YourWiFiSSID", "YourWiFiPassword");
}
void loop() {
// Wait for WiFi connection
if ((WiFiMulti.run() == WL_CONNECTED)) {
WiFiClient client;
HTTPClient http;
//Serial.print("[HTTP] begin...\n");
if (lightWeight == true) {
URL = "http://radmon.org/radmon-simomax/ping.html"; // Very basic and fast html page.
} else {
URL = "http://radmon.org/radmon.php?function=ping"; // Passes the query through the radmon api, thus using more cpu cycles.
}
if (http.begin(client, URL)) { // HTTP
//Serial.print("[HTTP] GET...\n");
Serial.println("ping...");
// Start connection and send HTTP header
int httpCode = http.GET();
// HttpCode will be negative on error
if (httpCode > 0) {
// HTTP header has been sent and server response header has been handled
//Serial.printf("[HTTP] GET... code: %d\n", httpCode);
// File found at server
if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
String payload = http.getString();
Serial.println(payload);
if (payload == "pong") // We got the reply we wanted. Green LED on.
{
ledsOff();
digitalWrite(green, HIGH);
counter = 0;
//Serial.println("Fail counter reset");
} else // We got a reply, but it wasn't what we wanted. Green+red LED on. Set the fail counter + 1
{
ledsOff();
digitalWrite(red, HIGH);
digitalWrite(green, HIGH);
counter += 1;
Serial.println("Fail count: " + (String)counter);
}
}
} else { // We didn't get a reply. Green+red LED on. Set the fail counter + 1
Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
ledsOff();
digitalWrite(red, HIGH);
digitalWrite(green, HIGH);
counter += 1;
Serial.println("Fail count: " + (String)counter);
}
http.end();
} else { // We couldn't connect. Green+red LED on. Set the fail counter + 1
Serial.printf("[HTTP} Unable to connect\n");
ledsOff();
digitalWrite(red, HIGH);
digitalWrite(green, HIGH);
counter += 1;
Serial.println("Fail count: " + (String)counter);
}
}
if (counter >= 3) { // When the fail counter reaches 3 set the LED red.
ledsOff();
digitalWrite(red, HIGH);
//*************** Your alarm ON code can go here ***************
} else {
//*************** Your alarm OFF code can go here ***************
}
delay(interval * 1000);
}
Attachments:
Last edit: 7 months 3 weeks ago by Simomax.
The following user(s) said Thank You: Juzzie, steadramon
Please Log in or Create an account to join the conversation.
7 months 3 weeks ago - 7 months 3 weeks ago #6904
by jnissen
Replied by jnissen on topic Radmon.org Mini Monitor
Great little project. I may have to duplicate! Only thing I can see as a potential add is to include a watchdog timer. On ESP projects they work for a week or two then seem to get lost! At least that is my experience. I normally will have checks for my local network as well as a standard watchdog reset if the code gets lost. Makes the nodes a bit more robust.
Last edit: 7 months 3 weeks ago by jnissen.
Please Log in or Create an account to join the conversation.
7 months 3 weeks ago #6905
by Simomax
Replied by Simomax on topic Radmon.org Mini Monitor
A watchdog may be a good idea. Not something I have really had to use on my projects though as I rarely have any lock-ups with the ESPs. I have had code that crashed an ESP at random intervals, but never really have them lock up. That said, I used to occasionally have them drop off the WiFi, but that all went away when I changed my WiFi APs for a much better quality make. So generally I have some code that will reconnect the WiFi if it looses connection, but that is about it. I have also had issues in the past where the AP going off line would stop the ESP reconnecting, but that may be more down to the older code/libraries and also my lack of programming skills back then or maybe something to do with using older APs back then. I do think having a good WiFi network is kind of paramount with these small WiFi nodes as I have had ESPs online for 100's of days.
Please Log in or Create an account to join the conversation.
Moderators: Gamma-Man
Time to create page: 0.192 seconds