Ping Plugin

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
Neutrino
Normal user
Posts: 3
Joined: 10 Sep 2017, 14:41

Ping Plugin

#1 Post by Neutrino » 13 Oct 2017, 08:12

Hello everybody,
In my Home automation system, a wemos reboots my raspberry in case of crash.
I made a plugin which pings an IP address.
I use the ESP8266Ping library. https://github.com/dancol90/ESP8266Ping

Here the plugin :

Code: Select all

//#######################################################################################################
//#################################### Plugin 085: Ping  ################################################
//#######################################################################################################

#define PLUGIN_085
#define PLUGIN_ID_085         85
#define PLUGIN_NAME_085       "Ping Device"
#define PLUGIN_VALUENAME1_085 "Ping"

#include <ESP8266Ping.h>

boolean Plugin_085(byte function, struct EventStruct *event, String& string)
{
  boolean success = false;
  static byte switchstate[TASKS_MAX];
  static byte outputstate[TASKS_MAX];
  char deviceTemplate[1][41];    // variable for saving the subscription topics

  switch (function)
  {

    case PLUGIN_DEVICE_ADD:
      {
        Device[++deviceCount].Number = PLUGIN_ID_085;
        Device[deviceCount].VType = SENSOR_TYPE_SINGLE;
        Device[deviceCount].ValueCount = 1;
        Device[deviceCount].SendDataOption = true;
        Device[deviceCount].TimerOption = true;
        Device[deviceCount].GlobalSyncOption = true;
        break;
      }

    case PLUGIN_GET_DEVICENAME:
      {
        string = F(PLUGIN_NAME_085);
        break;
      }

    case PLUGIN_GET_DEVICEVALUENAMES:
      {
        strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_VALUENAME1_085));
        break;
      }

    case PLUGIN_WEBFORM_LOAD:
      {
        LoadCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemplate, sizeof(deviceTemplate));


          addFormTextBox(string, String(F("IP ")), String(F("Plugin_085_template")), deviceTemplate[0], 40);
              
        success = true;
        break;
      }

    case PLUGIN_WEBFORM_SAVE:
      {
        String argName;

          argName = F("Plugin_085_template");
          strncpy(deviceTemplate[0], WebServer.arg(argName).c_str(), sizeof(deviceTemplate[0]));
        

        SaveCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemplate, sizeof(deviceTemplate));
         success = true;
        break;
      }
    case PLUGIN_READ:
      {
        char deviceTemplate[1][41];
        String AdrIp;
      
      //  Loop over all tasks looking for a 085 instance

      for (byte y = 0; y < TASKS_MAX; y++)
       {
          if (Settings.TaskDeviceNumber[y] == PLUGIN_ID_085)
          {
            LoadCustomTaskSettings(y, (byte*)&deviceTemplate, sizeof(deviceTemplate));

            // Now loop over all import variables and subscribe to those that are not blank
              AdrIp = deviceTemplate[0];
          }
        }
        int Parts[4] = {0,0,0,0};
        int Part = 0;
        for ( int i=0; i<AdrIp.length(); i++ )
        {
          char c = AdrIp[i];
          if ( c == '.' )
          {
            Part++;
            continue;
          }
          Parts[Part] *= 10;
          Parts[Part] += c - '0';
        }
        IPAddress ip( Parts[0], Parts[1], Parts[2], Parts[3] ); // The remote ip to ping
        String log = F("Ping ");
        bool ret = Ping.ping(ip);
        log += AdrIp;
        log += " state ";
        log += ret;
        addLog(LOG_LEVEL_INFO,log);
        UserVar[event->BaseVarIndex] = ret;
        event->sensorType = SENSOR_TYPE_SWITCH;
        success = true;
        break;
      }

  }
  return success;
}
You are free to use it, edit it, improve it ;)
Capture.PNG
Capture.PNG (18.86 KiB) Viewed 4574 times
Last edited by Neutrino on 13 Oct 2017, 22:54, edited 1 time in total.

Jeff
Normal user
Posts: 26
Joined: 18 Nov 2016, 18:35

Re: Ping Plugin

#2 Post by Jeff » 13 Oct 2017, 22:13

It's a WOL function :?

Neutrino
Normal user
Posts: 3
Joined: 10 Sep 2017, 14:41

Re: Ping Plugin

#3 Post by Neutrino » 13 Oct 2017, 23:01

Jeff wrote:
13 Oct 2017, 22:13
It's a WOL function :?
No, just ping (icmp), not a WOL function. ;)
I use it with a dummy and rules.
If 10 pings fail, it resets my raspberry with a relay.

User avatar
grovkillen
Core team member
Posts: 3269
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Ping Plugin

#4 Post by grovkillen » 13 Oct 2017, 23:05

Aaah, and you could also have a ESP Easy unit ping Google DNS server (8.8.8.8) and see if the internet connection is working. If not, kill the power to your router for a sec and reboot it. Will try!

Wouldn't mind this being a part of the main code. Will you propose that on GitHub?
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

lyndondr
Normal user
Posts: 12
Joined: 20 Aug 2018, 22:03

Re: Ping Plugin

#5 Post by lyndondr » 06 Oct 2018, 00:20

Is this going to be added to the build?
I'd like to setup a ESP Easy outlet to detect if the internet connection is down and if it is power off the router for a few seconds and then turn back on.
Is this possible with the current mega builds?
I see in the system info there is a web traffic output but I havn't found the details of what it is tracking and it seems to reset and I don't know why.

User avatar
grovkillen
Core team member
Posts: 3269
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Ping Plugin

#6 Post by grovkillen » 06 Oct 2018, 10:38

I haven't seen the request on GitHub. Maybe you could open one?
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

TD-er
Core team member
Posts: 1651
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Ping Plugin

#7 Post by TD-er » 06 Oct 2018, 12:31

There is only one minor thing about using this ping library.
It will block execution of other code as long as it is waiting for a reply.
So if you combine this with plugins that really need some real-time behavior, data/connections will be lost when a ping is taking a long time to reply.

User avatar
grovkillen
Core team member
Posts: 3269
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Ping Plugin

#8 Post by grovkillen » 06 Oct 2018, 13:04

Ah, I now remember you telling me that way back. So we should somehow make blocking plugins/commands stand out so users understand that these are in fact blocking.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

lyndondr
Normal user
Posts: 12
Joined: 20 Aug 2018, 22:03

Re: Ping Plugin

#9 Post by lyndondr » 06 Oct 2018, 22:46

Anything else you can think of for my post?

User avatar
grovkillen
Core team member
Posts: 3269
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Ping Plugin

#10 Post by grovkillen » 06 Oct 2018, 23:11

lyndondr wrote:
06 Oct 2018, 22:46
Anything else you can think of for my post?
It's not in the official repository so you first need to add a request for it to be merged/included. If you do that you will get notifications on any update on the matter.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

lyndondr
Normal user
Posts: 12
Joined: 20 Aug 2018, 22:03

Re: Ping Plugin

#11 Post by lyndondr » 07 Oct 2018, 01:21

I was wondering if there were any other ways to solve my problem without that type of plugin?

boby1
Normal user
Posts: 1
Joined: 07 Oct 2018, 02:44

Re: Ping Plugin

#12 Post by boby1 » 07 Oct 2018, 02:52

Hello guys,

I am freshly starting my experience on ESP8266 and I plan for my first project to make a king of "reset plug" for my internet modem.

The idea is not new, but I did not find anywhere a ready to use solution for my ESP. The plugin you propose here may perfectly answer my need but I am stuck on compiling the firmware after adding the plugin.

--> Would you please help me, I would really appreciate if anyone could send me a compiled binary ? I wanted to do it with ESPeasy 2.0.0 for ESP8266 normal 4096.

Thanks

TD-er
Core team member
Posts: 1651
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Ping Plugin

#13 Post by TD-er » 07 Oct 2018, 11:14

We can add it to the official repository, and later make it less blocking.

I just added it to the GitHub:
https://github.com/letscontrolit/ESPEasy/issues/1863

Neutrino
Normal user
Posts: 3
Joined: 10 Sep 2017, 14:41

Re: Ping Plugin

#14 Post by Neutrino » 07 Oct 2018, 15:36

Hi,
I'm very happy to see that !
I'm using it with an LCD 16x2 without any problem since 1 year. :)

etrubin
Normal user
Posts: 2
Joined: 15 Feb 2017, 16:55

Re: Ping Plugin

#15 Post by etrubin » 13 Nov 2018, 11:33

Hi!
Pease help.
try to do but have an errors after adding this plugin.

Code: Select all

P085_esp8266ping.ino: In function 'boolean Plugin_085(byte, EventStruct*, String&)':

_P085_esp8266ping:53:107: error: invalid conversion from 'char*' to 'int' [-fpermissive]

           addFormTextBox(string, String(F("IP ")), String(F("Plugin_085_template")), deviceTemplate[0], 40);

                                                                                                           ^

_P085_esp8266ping:53:107: error: too many arguments to function 'void addFormTextBox(const String&, const String&, const String&, int)'

\arduino-1.8.7\ESPEasy_mega-20181112\source\src\ESPEasy\WebServer.ino:3048:6: note: declared here

 void addFormTextBox(const String& label, const String& id, const String&  value, int maxlength)

      ^
Or maybe somebody can give compiled firmware to update by web?

Thank you

User avatar
enesbcs
Normal user
Posts: 410
Joined: 18 Jun 2017, 11:02
Location: Békéscsaba, Hungary
Contact:

Re: Ping Plugin

#16 Post by enesbcs » 25 Nov 2018, 21:00

etrubin wrote:
13 Nov 2018, 11:33
Hi!
Pease help.
try to do but have an errors after adding this plugin.

Code: Select all

P085_esp8266ping.ino: In function 'boolean Plugin_085(byte, EventStruct*, String&)':

_P085_esp8266ping:53:107: error: invalid conversion from 'char*' to 'int' [-fpermissive]

           addFormTextBox(string, String(F("IP ")), String(F("Plugin_085_template")), deviceTemplate[0], 40);

                                                                                                           ^

_P085_esp8266ping:53:107: error: too many arguments to function 'void addFormTextBox(const String&, const String&, const String&, int)'

\arduino-1.8.7\ESPEasy_mega-20181112\source\src\ESPEasy\WebServer.ino:3048:6: note: declared here

 void addFormTextBox(const String& label, const String& id, const String&  value, int maxlength)

      ^
Or maybe somebody can give compiled firmware to update by web?

Thank you
Hi!
I rewrite Neutrino's plugin with using a non-blocking pinger library.
Some changes: only 3 ping device can be added, only IP address can be specified by entering all four octets as plugin parameters.

Source:
https://github.com/enesbcs/ESPEasyPlugi ... 6_Ping.ino

4M binary download

Wiki
Normal user
Posts: 141
Joined: 23 Apr 2018, 17:55

Re: Ping Plugin

#17 Post by Wiki » 21 Mar 2019, 16:01

Hi,

works pretty good, tested with the custom bin posted before.

I want to try to get more stability on four critical nodes concerning the WD timeout reboots following the recommendation of TD-er on github. On the device I want to use for continuous pings I need the max6675 plugin, too.

Is there any possibility to get a binary version which allows one more ping device, means four instead of three and which is based on the actual sources?

User avatar
enesbcs
Normal user
Posts: 410
Joined: 18 Jun 2017, 11:02
Location: Békéscsaba, Hungary
Contact:

Re: Ping Plugin

#18 Post by enesbcs » 23 Mar 2019, 22:01

Wiki wrote:
21 Mar 2019, 16:01
I want to try to get more stability on four critical nodes concerning the WD timeout reboots following the recommendation of TD-er on github. On the device I want to use for continuous pings I need the max6675 plugin, too.

Is there any possibility to get a binary version which allows one more ping device, means four instead of three and which is based on the actual sources?
New binary attached. UNTESTED! Use only your own risk.
(Prepare with some screwdrivers and soldering iron and serial-USB programmer, before using these binaries.)
Last edited by enesbcs on 24 Mar 2019, 19:10, edited 1 time in total.

Wiki
Normal user
Posts: 141
Joined: 23 Apr 2018, 17:55

Re: Ping Plugin

#19 Post by Wiki » 24 Mar 2019, 12:11

Hi,

you're the best. Pinging four devices works like a charme. Thank you.

Only thing thats missing now is the max6675.

User avatar
enesbcs
Normal user
Posts: 410
Joined: 18 Jun 2017, 11:02
Location: Békéscsaba, Hungary
Contact:

Re: Ping Plugin

#20 Post by enesbcs » 24 Mar 2019, 16:03

Wiki wrote:
24 Mar 2019, 12:11
Only thing thats missing now is the max6675.
Temperature Thermocouple is already in these binaries. I do not know any other plugin that supports max6675...

mahodk
Normal user
Posts: 4
Joined: 24 Aug 2017, 09:16

Re: Ping Plugin

#21 Post by mahodk » 24 Mar 2019, 16:24

Was this plugin ever added to the official release?
I have not been able to find it as a device in the device list on any of the precompiled firmwares.
- I do not mind if it is blocking other functions, key functionality would be to ping external server and toggle relay based on that.

If not included in a past release I guess I will have to take the plunge and learn how to compiler a custom version.
Any good tutorials on this? I have done a bit of Arduino work in the past, but I have very limited experience with compiling firmware.

Thanks for your help
mahodk

Wiki
Normal user
Posts: 141
Joined: 23 Apr 2018, 17:55

Re: Ping Plugin

#22 Post by Wiki » 24 Mar 2019, 16:58

@enesbcs: "Temperature Thermocouple " doesn't work, there is no chip available to be chosen.
Thermo1.JPG
Thermo1.JPG (60.77 KiB) Viewed 1821 times
The plugin I was using before is named "Environment Thermocouple", there you get a dropdown to choose the chip.
Thermo2.JPG
Thermo2.JPG (47.93 KiB) Viewed 1821 times
But don't put too much efforts in it, I personally am fine with the four pings - you made my day, seriously. The max6675 would be more or less a nice-to-have.

Wiki
Normal user
Posts: 141
Joined: 23 Apr 2018, 17:55

Re: Ping Plugin

#23 Post by Wiki » 24 Mar 2019, 17:02

mahodk wrote:
24 Mar 2019, 16:24
Was this plugin ever added to the official release?
[...]
No, thats why I was asking for a modified binary. The plugin still is on playground. My coding skills are not sufficient either, even in the past I was not able to get a running environment to compile myself.

User avatar
enesbcs
Normal user
Posts: 410
Joined: 18 Jun 2017, 11:02
Location: Békéscsaba, Hungary
Contact:

Re: Ping Plugin

#24 Post by enesbcs » 24 Mar 2019, 19:10

Wiki wrote:
24 Mar 2019, 16:58
@enesbcs: "Temperature Thermocouple " doesn't work, there is no chip available to be chosen.
Thermo1.JPG
The plugin I was using before is named "Environment Thermocouple", there you get a dropdown to choose the chip.
Thermo2.JPG
But don't put too much efforts in it, I personally am fine with the four pings - you made my day, seriously. The max6675 would be more or less a nice-to-have.
No problem. It seems that you need the P039 plugin which is in fact located in the main ESPEasy repository. Recompiled.

update: I've just tried it on a D1 Mini and it is almost unusable.. (freezing, disconnecting) i reverted back to 2018.dec ESPEasy sources with core 2.4.1 and the device works OK. I guess core 2.5.0 is the reason.
Attachments
ESPEasy_bin_20190311.zip
ESPEasy bin_unstable_core_250
(1.05 MiB) Downloaded 30 times
Last edited by enesbcs on 25 Mar 2019, 10:18, edited 1 time in total.

Wiki
Normal user
Posts: 141
Joined: 23 Apr 2018, 17:55

Re: Ping Plugin

#25 Post by Wiki » 24 Mar 2019, 21:06

You're my hero, works. Thank you.

If you stay one time in DE just come along, I'll buy you a beer (or two).

User avatar
enesbcs
Normal user
Posts: 410
Joined: 18 Jun 2017, 11:02
Location: Békéscsaba, Hungary
Contact:

Re: Ping Plugin

#26 Post by enesbcs » 25 Mar 2019, 10:17

Wiki wrote:
24 Mar 2019, 21:06
You're my hero, works. Thank you.

If you stay one time in DE just come along, I'll buy you a beer (or two).
Thanks! :)
Finally i've succesfully compiled the same on the newest Core 2.6.0-dev which seems a lot more stable than previous "stable" 2.5.0.
Attachments
ESPEasy.core260.zip
ESPEasy-dev-core_260
(1.05 MiB) Downloaded 56 times

Post Reply

Who is online

Users browsing this forum: No registered users and 14 guests