Arduino IDE can not compile a sketch with pinging instructions

I am trying to complete a project in Arduino IDE using an ESP32.

Once a day, the code updates an RTC through NPT. The problem is that if there is no internet connection, the code stops.

To use a conditional that omits this instruction, I would need to verify that there is not an active connection to the Internet.

I've thought about sending a ping and waiting for its return, but I have not found a library that works well for ESP32. I tried the libraries and the examples of ESP32_ping and ESP32Ping without success. The pbecchi library now gives an error that says it can not compile for the module that I use.

I would like to know how else I can verify that the ESP32 has an Internet connection.

I am a newbie in this field with three months since I started learning how to program. Hope someone can help me.

If you post your full sketch, someone might be able to help you fix the root problem that causes the code to stop when there is no Internet connection. If possible, you should always post code directly in the forum thread as text using code tags (</> button on the toolbar). This will make it easy for anyone to look at it, which will increase the likelihood of you getting help. If the sketch is longer than the forum will allow then it's OK to add it as an attachment. After clicking the "Reply" button, you will see an "Attachments and other settings" link.

Please always do an Auto Format (Tools > Auto Format in the Arduino IDE or Ctrl + B in the Arduino Web Editor) on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read.

When your code requires a library that's not included with the Arduino IDE please post a link (using the chain links icon on the toolbar to make it clickable) to where you downloaded that library from or if you installed it using Library Manger (Sketch > Include Library > Manage Libraries in the Arduino IDE or Libraries > Library Manager in the Arduino Web Editor) then say so and state the full name of the library.

Also posted at:

If you're going to do that then please add links to the other places you posted. This will let us avoid wasting time due to duplicate effort and also help others who have the same questions and find your post to discover all the relevant information. When you post links please always use the chain links icon on the toolbar to make them clickable.

Thanks a lot pert for your response. I´ll follow your advice. The code that Arduino IDE does not compile is the example of the pbecchi´s ESP_ping library, available at:

The complete code is the following:

/*
 Name:		PingTest.ino
 Created:	05/08/2017 10:20:19
 Author:	pbecc
*/
#undef PROVA_


#include <WiFi.h>
#include  "ping.h"

// the setup function runs once when you press reset or power the board
const char ssid[] = "TP-LINK_C20B";  //  your network SSID (name)
const char password[] = "paolo-48";       // your network password

void setup() {

	Serial.begin(115200);
	Serial.print("Connecting t ");
	Serial.println(ssid);
	// WiFi.mode(WIFI_STA);

	WiFi.begin(ssid, password);


	while (WiFi.status() != WL_CONNECTED) {
		delay(500);
		Serial.print(".");
		

	}
	Serial.println("Pinging address: 192.168.1.1");
}

// the loop function runs over and over again until power down or reset
void loop() {
	int ia[4] = { 192,168,1,1 };
	int  i = 0;
	while (Serial.available()) {
		
		char c = Serial.read();
		delay(100);
   	int  val = 0;
		while (c != '.' &&  c != 10 && c!=255) {
			if (c >= '0'&& c<='9') {
				val = val*10+(c-'0');				
			}
			c = Serial.read();
		}
	
			ia[i++] =val ;
	}
	IPAddress adr = IPAddress(ia[0], ia[1], ia[2], ia[3]);
	Serial.printf("Ping : %d . %d . %d . %d ->", ia[0], ia[1], ia[2], ia[3]);
	if (ping_start(adr, 4, 0, 0, 5))
		Serial.println("OK");
	else
		Serial.println("FAILED");
	delay(10000);

}
int readnu(char s) {
	char c = Serial.read();
	Serial.print(c);
	int digit = 1,val=0;
	while (c != s &&  c != 10&&c>0) {
		if(c>'0') val += digit*(c - '0');
		digit *= 10;
		c=Serial.read();
		Serial.print(int(c));
	}
	Serial.println(digit);
	return digit;
}

Every time I get a error message saying: "error compiling for MH ET LIVE ESP32MiniKit board.

And the detailed error is:

Arduino:1.8.7 (Windows 10), Tarjeta:"MH ET LIVE ESP32MiniKit, 80MHz, Default, 921600, None"
D:\User\Documents\Arduino\libraries\ESP32Ping\src\ping.cpp: In function 'err_t ping_send(int, ip4_addr_t*, int)':
D:\User\Documents\Arduino\libraries\ESP32Ping\src\ping.cpp:139:45: error: 'inet_addr_from_ipaddr' was not declared in this scope
inet_addr_from_ipaddr(&to.sin_addr, addr);
D:\User\Documents\Arduino\libraries\ESP32Ping\src\ping.cpp: In function 'void ping_recv(int)':
D:\User\Documents\Arduino\libraries\ESP32Ping\src\ping.cpp:172:58: error: 'inet_addr_to_ipaddr' was not declared in this scope
inet_addr_to_ipaddr(&fromaddr, &from.sin_addr);

exit status 1
Error compilando para la tarjeta MH ET LIVE ESP32MiniKit.

Since the time you posted this, someone reported the same problem here, but with enough information that I could investigate from the start. It turns out that the cause of the problem is that something changed between ESP32 Core for Arduino version 1.0.0 and 1.0.1 that broke the ESP32_Ping library.

The workaround is to roll back to ESP32 Core for Arduino 1.0.0:

  • (In the Arduino IDE) Tools > Board > Boards Manager
  • Wait for downloads to finish
  • Scroll down until you see "ESP32 by espressif systems". Click on it.
  • From the dropdown menu, select "1.0.0".
  • Click "Install".
  • Wait for the installation to finish.
  • Click "Close".

Hi Per, I found earlier today the wieb´s topic ¨'inet_addr_to_ipaddr' was not declared in this scope ([SOLVED] 'inet_addr_to_ipaddr' was not declared in this scope - Programming Questions - Arduino Forum), and the solution you suggested.

So I followed the instructions and the code is now working fine. Thanks a lot.

Hope the ESP32 Core version 1.0.1 will be fixed soon, because the Arduine IDE is promting to update that core every time it is opened.

pert:
Also posted at:

If you're going to do that then please add links to the other places you posted. This will let us avoid wasting time due to duplicate effort and also help others who have the same questions and find your post to discover all the relevant information. When you post links please always use the chain links icon on the toolbar to make them clickable.

I'm sorry, I'll keep it in mind from now on.

I'm glad to hear it's working now.

I agree that this breakage is unfortunate. A change from 1.0.0 to 1.0.1 is not supposed to introduce any changes in the API so you should be able to confidently make this update without expecting it to cause any problems of this sort. I did a search of the ESP32 Core for Arduino's repository and there is no mention of inet_addr_to_ipaddr anywhere in the bug tracker or pull requests so it's likely they are not even aware of the issue.

I don't know anything about this topic. The ESP8266 Core for Arduino has its own functions but the underlying toolchain uses code provided by Espressif and instinct tells me inet_addr_to_ipaddr is actually part of that code. If so, it's not really an issue in the ESP32 Core for Arduino. I'm not sure how versioning should handle breaking changes in the toolchain. The release notes do mention updating the IDF but they are not updating to release versions so that doesn't provide any simple information on whether each update should represent breaking changes in the IDF.

Oslaf:
Hope the ESP32 Core version 1.0.1 will be fixed soon, because the Arduine IDE is promting to update that core every time it is opened.

You can turn off update notifications at File > Preferences > Check for updates at startup. It's unfortunate to need to turn that off because usually the update notifications are quite useful.