1

I'm using ESP8266Ping lib inside my iot lib which hanldes Wifi connectivity and MQTT messages. Since it create its own instance called Ping when calling #include <ESP8266Ping.h>- it had to be place in iot.cpp.

I writing another library, IPmonitor which checks clients on the network (using pings), I wanted to use ESP8266Ping again.

My sketch file, create an instance of iot and IPmonitor for check/ log errors on monitored clients.

But I get error of using the same library twice.

I guess that since ESP8366Ping.h library is defined it creates an instance of the class ( see mark below ):

class PingClass {
 public:
 PingClass();
 bool ping(IPAddress dest, byte count = 5);
 bool ping(const char* host, byte count = 5);
 int averageTime();
 protected:
 static void _ping_sent_cb(void *opt, void *pdata);
 static void _ping_recv_cb(void *opt, void *pdata);
 IPAddress _dest;
 ping_option _options;
 static byte _expected_count, _errors, _success;
 static int _avg_time;
};
#include "ESP8266Ping.impl.h"
PingClass Ping; // <----- This
#endif

How can it be solved ?

asked Apr 13, 2021 at 7:48
0

1 Answer 1

2

With that library... you can't. All the code is in one big monolithic .h file. As you well know by now that is a big no-no. The author should be given a big slap on the wrists.

The closest you could do without re-writing the whole library is to just copy the class definition from the outer .h file and create an extern to the existing object - maybe make your own copy of the ESP8266Ping.h file without the #include "ESP8266Ping.impl.h" and PingClass Ping; (the latter of which you change to an extern).

answered Apr 13, 2021 at 9:13
3
  • Thank you. Since I don’t any future mishappens after lib update, I’ll probably use calling external function in ‘IPmonitor’ to call the relevant function from ‘iot’ class. And slapping Commented Apr 13, 2021 at 9:19
  • @Guy.D I have submitted a pull request with the required changes. You may like to test with my fork: github.com/majenkotech/ESP8266Ping Commented Apr 13, 2021 at 9:28
  • Well... this is very nice of you! Cheers Commented Apr 13, 2021 at 9:32

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.