Am looking for a little guidance with getting the following code to compile.
Code was found online and it throws this error while verifying with IDE v2:
/private/var/folders/4b/qckrgbg9363dj_tb8wbv29zr0000gn/T/arduino/sketches/A827478510E08D3B5CCE11A06C8E0BA9/sketch/GIGA_Wifi.ino.cpp.o: In function loop':* */Users/xxxxxxxxxxxx/Documents/Arduino/GIGA_Wifi/GIGA_Wifi.ino:66: undefined reference to arduino::WiFiClass::ping(arduino::String const&, unsigned char)' collect2: error: ld returned 1 exit status exit status 1 Compilation error: exit status 1
The issue seems to be with this function pingResult = WiFi.ping(hostName, 128);
It fails to compile with or without specifying "uint8_t ttl" value.
EDITED: The code does compile fine if that one line is commented out and has NO issues connecting to the specified SSID.
What am I missing?
/*
This example connects to a encrypted WiFi network (WPA/WPA2).
Then it prints the MAC address of the WiFi 101 Shield,
the IP address obtained, and other network details.
Then it continuously pings given host specified by IP Address or name.
Circuit:
WiFi 101 Shield attached / MKR1000
created 13 July 2010
by dlf (Metodo2 srl)
modified 09 June 2016
by Petar Georgiev
*/
#include <SPI.h>
#include <WiFi.h>
#include "arduino_secrets.h"
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
char ssid[] = SECRET_SSID; // your network SSID (name)
char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
int status = WL_IDLE_STATUS; // the WiFi radio's status
// Specify IP address or hostname
// String hostName = "www.google.com";
String hostName = "8, 8, 8, 8";
int pingResult;
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// check for the presence of the shield:
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi 101 Shield not present");
// don't continue:
while (true);
}
// attempt to connect to WiFi network:
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network:
status = WiFi.begin(ssid, pass);
// wait 5 seconds for connection:
delay(5000);
}
// you're connected now, so print out the data:
Serial.println("You're connected to the network");
printCurrentNet();
printWiFiData();
}
void loop() {
Serial.print("Pinging ");
Serial.print(hostName);
Serial.print(": ");
pingResult = WiFi.ping(hostName, 128);
if (pingResult >= 0) {
Serial.print("SUCCESS! RTT = ");
Serial.print(pingResult);
Serial.println(" ms");
} else {
Serial.print("FAILED! Error code: ");
Serial.println(pingResult);
}
delay(5000);
}
void printWiFiData() {
// print your WiFi 101 Shield's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP address : ");
Serial.println(ip);
Serial.print("Subnet mask: ");
Serial.println((IPAddress)WiFi.subnetMask());
Serial.print("Gateway IP : ");
Serial.println((IPAddress)WiFi.gatewayIP());
// print your MAC address:
byte mac[6];
WiFi.macAddress(mac);
Serial.print("MAC address: ");
printMacAddress(mac);
}
void printCurrentNet() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print the MAC address of the router you're attached to:
byte bssid[6];
WiFi.BSSID(bssid);
Serial.print("BSSID: ");
printMacAddress(bssid);
// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI): ");
Serial.println(rssi);
// print the encryption type:
byte encryption = WiFi.encryptionType();
Serial.print("Encryption Type: ");
Serial.println(encryption, HEX);
Serial.println();
}
void printMacAddress(byte mac[]) {
for (int i = 5; i >= 0; i--) {
if (mac[i] < 16) {
Serial.print("0");
}
Serial.print(mac[i], HEX);
if (i > 0) {
Serial.print(":");
}
}
Serial.println();
}
Hi @endreola. Unfortunately it looks like the developers of the "GIGA R1 WiFi" board's "WiFi" library never implemented a ping function. So you can't use that function with this board.
If you would like assistance with that, please provide a detailed description of the "issues" and we'll try to help you with them.
Ugg, that's a shame. Who would of thought that a board having built-in paths of communication wouldn't include a basic networking protocol like ping.
I guess to your point, IDE thinks that library function is valid (b/c it pops-up a syntax window when moused over, see screenshot) but that doesn't necessarily mean the HW supports it.
Is there an current cross-reference guide that lists the different Arduino boards and what libraries / functions are supported (and or not supported)? Asking the developers to make that change will take significant time and who knows if the wifi chipset even supports the ICMP protocol, etc., etc.. So in the interim, I'll go purchase a different board but it has to support wifi & ping.
It think it is valid because the library developers declared the function:
However, despite the presence of the declarations, the functions don't seem to be defined in the library, thus the error message when you try to use them.
I'm not very knowledgeable about the GIGA R1 WiFi's Wi-Fi radio hardware, or about networking in general, but I think it is as likely that the library developers simply didn't get around to implementing the functions rather than that there is a technical limitation that prevents such a thing.
If we are speaking of networking libraries specifically, a community member did just that recently:
This was part of @Juraj's work to improve the standardization of the API of the various networking libraries (official and 3rd party) in the Arduino ecosystem.
It has a table of libraries that provide a ping function here:
Am still not sure where the "ping()" limitation stands with the GIGA r1 wifi board but I would like to see that the "Mbed libraries" get updated so I can use this board as originally planned.
ICMP ping is the industry standard protocol for monitoring device availability, if as device is up/down, (barring firewalls, ACLs, etc. in the path).
ICMP is a low cost protocol, meaning it does not impose the additional overhead that protocols like TCP/UDP have, such as TCP 3-way handshake. And UDP is a connection-less protocol meaning there's no acknowledgement that the end-point actually received the packet. So from an IP protocol stack perspective the ICMP protocol is what I require for availability testing using Ardunio. From an ICMP stack perspective I just need two types; echo (type 8) and echo reply (type 0).
Is there another protocol that you have in mind that i should use instead?