pbecchi / ESP32_ping

Ping library for ESP32
15 stars 13 forks source link

'inet_addr_to_ipaddr' was not declared in this scope [SOLVED] #8

Open wieb18 opened 5 years ago

wieb18 commented 5 years ago

Thanks a lot for excellent library.

It works fine on ESP32, no compiler error.

Because something wrong on my PC, I did fresh install Windows 10 and Arduino IDE 1.8.8.

But after fresh install, ESP32 Ping doesn't work anymore.

Arduino IDE Compiler error in Ping.cpp line:

inet_addr_from_ipaddr(&to.sin_addr, addr);

The error message: 'inet_addr_to_ipaddr' was not declared in this scope

It seems this error cause by broken lwip library.

ESP32 Ping use 2 separate lwip libraries (Arduino library in C:\Program Files (x86)\Arduino and ESP32 library in C:\Users\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.1\tools\sdk\include\lwip\lwip folder).

But somehow the library connection is broken and cause _'inet_addr_toipaddr' was not declared in this scope error

Instead using Board Manager to install ESP32 package, also tried install ESP32 package by using git, but didn't help either. Still _'inet_addr_toipaddr' was not declared in this scope error

How to fix this error?

Please help...

wieb18 commented 5 years ago

Tried very dumb solution by adding these lines:

#define inet_addr_from_ipaddr 
#define inet_addr_to_ipaddr 

in Ping.cpp.

No compiler error and able upload the sketch into ESP32.

But ping doesn't work because it didn't find _inet_addr_fromipaddr and _inet_addr_toipaddr functions.

How to fix this?

Please help...

wieb18 commented 5 years ago

Done this steps:

1. Uninstall Arduino IDE 1.8.8
2. Delete C:\Users\AppData\Local\
3. Rename C:\Users\Documents\Arduino into C:\Users\Documents\Arduino_OLD
4. Restart the PC
5. Install Arduino IDE 1.8.8
6. Install ESP32 Core version 1.0.0 using Boards Manager

Then.... compile my sketch.

And now.... it WORKS.... :) :) :)

My previous mistake is not installing ESP32 Core version 1.0.0.

I did it by installing version 1.0.1 - the Boards Manager default version - which didn't work.

It seems some change in ESP32 Core version 1.0.1 broke ESP32 Ping library connection.

atanisoft commented 5 years ago

Ping.cpp does not include the header that defines this function, you can alter the library to add the following to fix this likely:

#include <lwip/inet.h>
bill-orange commented 5 years ago

I added #include <lwip/inet.h> to Ping.cpp.. Compilation with Core 1.0.1 resulted in the same error.

atanisoft commented 5 years ago

The "function" is defined in that file, additional code may be required but I don't have this library setup on my system but I do use this function in my own code without issues.

atanisoft commented 5 years ago

a fix for this: https://github.com/PotatoX/ESP32_ping/commit/4b8688e013933af6459b3816bafb6b3a0debb371

bill-orange commented 5 years ago

@atanisoft That works, thanks! I use ping to test for a live internet connection.

dachshund-digital commented 5 years ago

When will PotatoX fix be merged to mater? I am getting the same issue with ESP core 1.0.1 right now.

dachshund-digital commented 5 years ago

Found another bug, typo...

In Ping.cpp... free() call is malformed, missing ";"... throws errors on compile.

if ((err = sendto(s, iecho, ping_size, 0, (struct sockaddr*)&to, sizeof(to)))) {
    transmitted++;
}
free(iecho)
return (err ? ERR_OK : ERR_VAL);
chillitomato commented 5 years ago

to make this work for v1.01 just change

inet_addr_from_ipaddr to inet_addr_from_ip4addr inet_addr_to_ipaddr to inet_addr_to_ip4addr

in file Ping.cpp in your library path

Thats it

BojanJurca commented 4 years ago

The solution that works for me is changing the following lines:

to.sin_addr = (in_addr ) addr; // inet_addr_from_ipaddr (&to.sin_addr, addr);

fromaddr = (ip4_addr_t ) &from.sin_addr; // inet_addr_to_ipaddr (&fromaddr, &from.sin_addr);

pvint commented 4 years ago

I'm using ESP 1.0.4 and could not easily get any of the above methods to work, but I have gotten it to work using ip4addr_aton(AF_INET, &to.sin_addr, inet_addr(addr));

Please test with my fork at https://github.com/pvint/ESP32_ping and let me know if it works with your version(s)

zyklone92 commented 4 years ago

Thanks @pvint, that totally worked for me (using ESP 1.0.4 here). Saved me a bunch of time, much appreciated.

pvint commented 4 years ago

Good to hear @zyklone92 (and thanks for the feedback!) I've been running a few devices for a few months now with those changes - I'll have another look at my code tomorrow to make sure it looks clean and submit a PR. It's a great library, but it looks like it may possibly be abandoned. I foresee using this a lot for a long time... @pbecchi : Do you have plans to maintain this in the future? If so, I'm glad to help out, and if not, I'd be happy to take it over (if you so desire) or simply do some maintenance/bugfixes on my fork.

Cheers Paul

marian-craciunescu commented 4 years ago

https://github.com/marian-craciunescu/ESP32Ping not abandoned input may is welcomed