I am experiencing a compile error when calling a void function from within another void. In this case the error generated says the called void 'xyz' was "not declared in this scope." Am I correct to think void functions do not require a declaration to call them?
This same code used within a WifiNINA EXAMPLES (ConnectWithWPA) sketch compiles without an error. The same library files are also referenced.
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// check for the WiFi module:
if (WiFi.status() == WL_NO_MODULE) {
Serial.println("Communication with WiFi module failed!");
// don't continue
while (true);
}
String fv = WiFi.firmwareVersion();
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
Serial.println("Please upgrade the firmware");
}
// 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 10 seconds for connection:
delay(5000);
}
// you're connected now, so print out the data
Serial.print("You're connected to the network");
printCurrentNet(); <<<<<<<<<< error
printWifiData(); <<<<<<<<<< error
}
void loop()
{
digitalWrite(LED_BUILTIN, HIGH); // blinky blinky
delay(200);
digitalWrite(LED_BUILTIN, LOW);
delay(300);
if (temp_alarm == true && temp_alarm_state == false)
{
// if(DEBUG){Serial.println(" Alarm is True/Send message");}
temp_alarm_state = true;
sendToPushingBox(DEVID1); //Sending request to PushingBox when the is TRUE
}
if (temp_alarm == false && temp_alarm_state == true) // temp alarm is OFF
{
// if(DEBUG){Serial.println(" Alarm is false/No message sent");}
temp_alarm_state = false;
}
//DEBUG part
// this write the respons from PushingBox Server.
// You should see a "200 OK"
if (client.available()) {
char c = client.read();
if(DEBUG){Serial.print(c);}
}
// if there's no net connection, but there was one last time
// through the loop, then stop the client:
void sendToPushingBox(char devid[])
{ //Function for sending the request to PushingBox
client.stop(); if(DEBUG){Serial.println(" connecting...");}
if(client.connect(serverName, 80)) {
if(DEBUG){Serial.println(" connected");}
if(DEBUG){Serial.println(" sendind request");}
client.print("GET /pushingbox?devid=");
client.print(devid);
client.println(" HTTP/1.1");
client.print("Host: ");
client.println(serverName);
client.println("User-Agent: Arduino");
client.println();
}
else {
if(DEBUG){Serial.println(" connection failed");}
}
}
void printWifiData() {
// print your board's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
Serial.println(ip);
// 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();
}
Error Code
******************** Error Code ********************************
/home/ed/Arduino/Uno_Wifi_Rev2_Push_Test_PushingBox_v3/Uno_Wifi_Rev2_Push_Test_PushingBox_v3.ino: In function 'void setup()':
Uno_Wifi_Rev2_Push_Test_PushingBox_v3:56:9: error: 'printCurrentNet' was not declared in this scope
printCurrentNet();
^~~~~~~~~~~~~~~
Uno_Wifi_Rev2_Push_Test_PushingBox_v3:57:9: error: 'printWifiData' was not declared in this scope
printWifiData();
^~~~~~~~~~~~~
/home/ed/Arduino/Uno_Wifi_Rev2_Push_Test_PushingBox_v3/Uno_Wifi_Rev2_Push_Test_PushingBox_v3.ino: In function 'void loop()':
Uno_Wifi_Rev2_Push_Test_PushingBox_v3:75:10: error: 'sendToPushingBox' was not declared in this scope
sendToPushingBox(DEVID1); //Sending request to PushingBox when the is TRUE
^~~~~~~~~~~~~~~~
Uno_Wifi_Rev2_Push_Test_PushingBox_v3:97:4: error: a function-definition is not allowed here before '{' token
{ //Function for sending the request to PushingBox
^
Uno_Wifi_Rev2_Push_Test_PushingBox_v3:114:25: error: a function-definition is not allowed here before '{' token
void printWifiData() {
^
Uno_Wifi_Rev2_Push_Test_PushingBox_v3:130:29: error: a function-definition is not allowed here before '{' token
void printCurrentNet() {
^
Uno_Wifi_Rev2_Push_Test_PushingBox_v3:153:43: error: a function-definition is not allowed here before '{' token
void printMacAddress(byte mac[]) {
^
Uno_Wifi_Rev2_Push_Test_PushingBox_v3:164:1: error: expected '}' at end of input
}
^
Using library SPI at version 1.0 in folder: /home/ed/.arduino15/packages/arduino/hardware/megaavr/1.8.7/libraries/SPI
Using library WiFiNINA at version 1.8.13 in folder: /home/ed/Arduino/libraries/WiFiNINA
exit status 1
'printCurrentNet' was not declared in this scope