Hi,
I have been trying for a while to make this ping work without success.
From the code above which I have simplified to the max, I still ahve issues:
Appologies, I have not been doing this for a long time.
"ping_init not declared in this scope"
It seems it can't find this although ping.c is included....
This is the error message.
Code: Select all
Arduino: 1.8.9 (Windows Store 1.8.21.0) (Windows 10), Board: "LOLIN D32, Minimal SPIFFS (Large APPS with OTA), 80MHz, 512000, None"
C:\Users\etawy\OneDrive\Development\Arduino\TestSketches\ping_test\ping_test.ino: In function 'void loop()':
ping_test:95:13: error: 'ping_init' was not declared in this scope
ping_init();
^
Multiple libraries were found for "WiFi.h"
Used: C:\Users\etawy\OneDrive\Documents Perso\ArduinoData\packages\esp32\hardware\esp32\1.0.2\libraries\WiFi
Not used: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.21.0_x86__mdqgnx93n4wtt\libraries\WiFi
exit status 1
'ping_init' was not declared in this scope
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
And this is my code:
Code: Select all
/*
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_spi_flash.h"
#include "freertos/event_groups.h"
#include "esp_log.h"
#include "esp_event_loop.h"
#include "nvs_flash.h"
*/
#include "esp_system.h"
#include "lwip/dns.h"
#include "esp_wifi.h"
#include "lwip/inet.h"
#include "esp_ping.h"
#include "lwip/ip4_addr.h"
#include "lwip/ip_addr.h"
// to make this work for v1.01 just change in file Ping.cpp in your library path:
// inet_addr_from_ipaddr to inet_addr_from_ip4addr
// inet_addr_to_ipaddr to inet_addr_to_ip4addr
#include "ping.h"
#include "esp_ping.h"
#include <WiFi.h>
//ip_addr_t ip_Addr;
ip4_addr_t gw;
uint32_t ping_count = 25; //how many pings per report
uint32_t ping_timeout = 1000; //mS till we consider it timed out
uint32_t ping_delay = 500; //mS between pings
uint32_t waiting_results = 0;
/*
#define PING_TARGET_IP_ADDRESS_COUNT 5
#define PING_TARGET_RCV_TIMEO 10000
#define PING_TARGET_DELAY_TIME 500
#define PING_TARGET_IP_ADDRESS "www.google.com"
#define PING_TARGET_RES_FN pingResults
*/
// the setup function runs once when you press reset or power the board
const char ssid[] = "SFR-XXXX"; // your network SSID (name)
const char password[] = "XXXXXXXX"; // your network password
void setup() {
Serial.begin(115200);
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
}
esp_err_t pingResults(ping_target_id_t msgType, esp_ping_found * pf) {
printf("AvgTime:%.1fmS Sent:%d Rec:%d Err:%d min(mS):%d max(mS):%d ", (float)pf->total_time / pf->recv_count, pf->send_count, pf->recv_count, pf->err_count, pf->min_time, pf->max_time );
printf("Resp(mS):%d Timeouts:%d Total Time:%d\n", pf->resp_time, pf->timeout_count, pf->total_time);
waiting_results = 0;
return ESP_OK;
}
int getStrength(int points) {
wifi_ap_record_t wifidata;
long rssi = 0;
long averageRSSI = 0;
for (int i = 0; i < points; i++) {
if (esp_wifi_sta_get_ap_info(&wifidata) == 0) {
rssi += wifidata.rssi;
vTaskDelay(25 / portTICK_PERIOD_MS);
}
}
averageRSSI = rssi / points;
return averageRSSI;
}
void loop() {
gw.addr = ipaddr_addr("8.8.8.8");
esp_ping_set_target(PING_TARGET_IP_ADDRESS_COUNT, &ping_count, sizeof(uint32_t));
esp_ping_set_target(PING_TARGET_RCV_TIMEO, &ping_timeout, sizeof(uint32_t));
esp_ping_set_target(PING_TARGET_DELAY_TIME, &ping_delay, sizeof(uint32_t));
esp_ping_set_target(PING_TARGET_IP_ADDRESS, &gw.addr, sizeof(uint32_t));
//esp_ping_set_target(PING_TARGET_RES_FN, &pingResults, sizeof(pingResults));
printf("\nPinging Gateway IP %s WiFi rssi %d\n", inet_ntoa(gw), getStrength(10));
printf("%s, %d, ", inet_ntoa(gw), getStrength(10));
ping_init();
waiting_results = 1;
}