Page 1 of 1

Ping Plugin

Posted: 13 Oct 2017, 08:12
by Neutrino
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 30031 times

Re: Ping Plugin

Posted: 13 Oct 2017, 22:13
by Jeff
It's a WOL function :?

Re: Ping Plugin

Posted: 13 Oct 2017, 23:01
by Neutrino
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.

Re: Ping Plugin

Posted: 13 Oct 2017, 23:05
by grovkillen
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?

Re: Ping Plugin

Posted: 06 Oct 2018, 00:20
by lyndondr
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.

Re: Ping Plugin

Posted: 06 Oct 2018, 10:38
by grovkillen
I haven't seen the request on GitHub. Maybe you could open one?

Re: Ping Plugin

Posted: 06 Oct 2018, 12:31
by TD-er
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.

Re: Ping Plugin

Posted: 06 Oct 2018, 13:04
by grovkillen
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.

Re: Ping Plugin

Posted: 06 Oct 2018, 22:46
by lyndondr
Anything else you can think of for my post?

Re: Ping Plugin

Posted: 06 Oct 2018, 23:11
by grovkillen
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.

Re: Ping Plugin

Posted: 07 Oct 2018, 01:21
by lyndondr
I was wondering if there were any other ways to solve my problem without that type of plugin?

Re: Ping Plugin

Posted: 07 Oct 2018, 02:52
by boby1
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

Re: Ping Plugin

Posted: 07 Oct 2018, 11:14
by TD-er
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

Re: Ping Plugin

Posted: 07 Oct 2018, 15:36
by Neutrino
Hi,
I'm very happy to see that !
I'm using it with an LCD 16x2 without any problem since 1 year. :)

Re: Ping Plugin

Posted: 13 Nov 2018, 11:33
by etrubin
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

Re: Ping Plugin

Posted: 25 Nov 2018, 21:00
by enesbcs
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

Re: Ping Plugin

Posted: 21 Mar 2019, 16:01
by Wiki
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?

Re: Ping Plugin

Posted: 23 Mar 2019, 22:01
by enesbcs
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.)

Re: Ping Plugin

Posted: 24 Mar 2019, 12:11
by Wiki
Hi,

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

Only thing thats missing now is the max6675.

Re: Ping Plugin

Posted: 24 Mar 2019, 16:03
by enesbcs
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...

Re: Ping Plugin

Posted: 24 Mar 2019, 16:24
by mahodk
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

Re: Ping Plugin

Posted: 24 Mar 2019, 16:58
by Wiki
@enesbcs: "Temperature Thermocouple " doesn't work, there is no chip available to be chosen.
Thermo1.JPG
Thermo1.JPG (60.77 KiB) Viewed 27278 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 27278 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.

Re: Ping Plugin

Posted: 24 Mar 2019, 17:02
by Wiki
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.

Re: Ping Plugin

Posted: 24 Mar 2019, 19:10
by enesbcs
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.

Re: Ping Plugin

Posted: 24 Mar 2019, 21:06
by Wiki
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).

Re: Ping Plugin

Posted: 25 Mar 2019, 10:17
by enesbcs
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.

Re: Ping Plugin

Posted: 11 Apr 2021, 08:53
by Piratee
Hello
Maybe someone has compiled the current version of EspEasy with "Ping" plugin and option
"Restart WiFi on lost conn".
Is it possible to upload the firmware file.
There is no "Ping" plug in the current version and the firmware posted on the forum does not contain any functions from 2019.
Greetings.

Re: Ping Plugin

Posted: 11 Apr 2021, 20:37
by TD-er
It should be part of the "testing" build (ESP8266 at least)

Re: Ping Plugin

Posted: 12 Apr 2021, 22:43
by Piratee
I once tried to complicate EspEasy from source but failed. I will do another approach.

Re: Ping Plugin

Posted: 12 Apr 2021, 23:35
by TD-er
Piratee wrote: 12 Apr 2021, 22:43 I once tried to complicate EspEasy from source but failed. I will do another approach.
Have you tried the 'nightly builds' ? https://github.com/letscontrolit/ESPEasy/releases

Re: Ping Plugin

Posted: 13 Apr 2021, 16:38
by Piratee
I have uploaded the ESP_Easy_mega_20210223_custom_alt_wifi_ESP8266_4M1M.bin and ESP_Easy_mega_20210223_custom_beta_ESP8266_4M1M.bin version / firmware to my ESP.
Unfortunately, I do not have the "ping" plugin there

Greetings

Re: Ping Plugin

Posted: 13 Apr 2021, 19:46
by Ath
You should use a .bin with 'test' in the name (as mentioned before). That 'test' is about the set of plugins included (testing), not about the state of the firmware.

Re: Ping Plugin

Posted: 13 Apr 2021, 22:28
by Piratee
I did not notice that the test versions are packed.
Test versions have Ping plugin, but WiFi is unstable, there is still disconnection from AP
3127: Info: WIFI: DHCP IP: 172.20.1.162 (ESP-Easy) GW: 172.20.1.245 SN: 255.255.255.0 duration: 55 ms
3239: Info: firstLoopConnectionsEstablished
13245: Info: WIFI: Disconnected! Reason: '(200)' Connected for 10 s
14253: Info: WIFI: Set WiFi to STA
14449: Info: WIFI: Start network scan
16649: Info: WIFI: Scan finished, found: 3

Re: Ping Plugin

Posted: 13 Apr 2021, 23:17
by TD-er
What exact build did you use?
The builds should all use the same code base and only differ on the number of plugins included.

There are builds with some additional changes like "alt_wifi" or "beta" in the name.
"alt_wifi" does use a different build of the (closed source) binary blob containing WiFi code.
And to illustrate my own personal frustration on that 'closed source' part... I have no clue what the differences are between "alt_wifi" and those without that label other than "if it doesn't work on a node, try the other one".

The "beta" builds do use a newer core library.

Re: Ping Plugin

Posted: 14 Apr 2021, 09:58
by Piratee
Yesterday I used the ESP8266 nodemcu v3 for testing and for this device I had connection restarts to the AP. Today I uploaded the test version to the Wemos D1 mini Pro and it is ok.
It does not disconnect the connection to the AP.
I will now test the "Ping" plugin
I have used both alpha and beta test versions.
Thank you for informing about the test version.
Greetings

Re: Ping Plugin

Posted: 17 Mar 2023, 09:38
by Andrew Mamohin
Tell me, please, in which firmware can I see this plugin?
The list of plugins says: Status: COLLECTION.
In various collection_[A-F] files I didn't find it.
I need for ESP32.

Re: Ping Plugin

Posted: 17 Mar 2023, 09:58
by TD-er
Just looked at where USES_P089 is defined in define_plugin_sets.h
It should be on each "Collection" build as it is defined when PLUGIN_SET_COLLECTION is defined and this is defined for any collection build.

However, the define check for the plugin itself is:

Code: Select all

#if defined(USES_P089) && defined(ESP8266)
So it appears it is explicitly not compiled into ESP32 builds.

Right now I can't tell why it explicitly is turned off for ESP32 builds.

Re: Ping Plugin

Posted: 17 Mar 2023, 10:07
by Andrew Mamohin
TD-er wrote: 17 Mar 2023, 09:58 So it appears it is explicitly not compiled into ESP32 builds.
Right now I can't tell why it explicitly is turned off for ESP32 builds.
Can I hope this plugin will be included in future builds? Please...

Re: Ping Plugin

Posted: 17 Mar 2023, 10:18
by TD-er

Re: Ping Plugin

Posted: 17 Mar 2023, 10:33
by Ath
I have looked at this (very) recently, but didn't get it to work quickly, though I could get it to compile, after applying the necessary changes to the code (ESP32 makes a distinction between IP4 and IP6 addresses in the internal structures). I'll just have to dive into this some more :P