Garbage at the end of Serial.print

Apple Mac OS
Arduino IDE 2.2.1,
Arduino Uno WiFi rev 2,
Arduino Motor Shield rev3
WiFiNINA.h version 1.8.14
Arduino C++
TCP-IP

void IP_Services(){

  Serial.println("entering IP_Services.ino");

  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your board's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  //print the server port being used
  Serial.print("server port =  ");
  Serial.println(serverPort);
 
  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");

  // Get subnet mask
  IPAddress subnetMask = WiFi.subnetMask();
  Serial.print("Subnet Mask: ");
  Serial.println(subnetMask);
  
  // Get MAC address
  Serial.print("MAC address: ");
  byte mac[6];

  WiFi.macAddress(mac);

  for (int i = 0; i < 6; i++) {
    Serial.print(mac[i], HEX);
    if (i < 5) Serial.print(':');
    delay(100);
  } //for (int i = 0; i < 6; i++)
  Serial.println();

  Serial.println();
  Serial.println("leaving IP_Services");
  Serial.println(Serial.available());
  while (Serial.available() > 0) {
    Serial.print(Serial.read()); // Read and discard a character
  } //while (Serial.available() > 0)

} //void IP_Services()

entering IP_Services.ino

SSID: xxxxxx
IP Address: 192.168.1.143
server port = 8081
signal strength (RSSI):-38 dBm
Subnet Mask: 255.255.255.0
MAC address: F8:61:7A:84:21:78

leaving IP_Services
0
���7AY!9)5�-#!��

I keep getting this garbage at the end of this procedure. Adding the delay in MAC Address moved the garbage to the end of the procedure. I tried to clear the serial buffer by using the while loop at the end. The garbage is still there. I assume the garbage has something to do with the program stopping. What am I missing?

Comment out this line

And make this just Serial.read();

leaving IP_Services
���7AY!9)5�-#!��

...same thing
leaving IP_Services
���7AY!9)5�-#!��

Is it always the same?
Maybe some PNP mouse detection stuff.

The output is so strange I can't be positive. I can't remember it. It always looks like that though, and the parts I remember are always the same.

Post your updated code. If you did exactly what I said, then nothing should print after "leaving IP_Services."

void IP_Services(){

  Serial.println("entering IP_Services.ino");

  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your board's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  //print the server port being used
  Serial.print("server port =  ");
  Serial.println(serverPort);
 
  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");

  // Get subnet mask
  IPAddress subnetMask = WiFi.subnetMask();
  Serial.print("Subnet Mask: ");
  Serial.println(subnetMask);
  
  // Get MAC address
  Serial.print("MAC address: ");
  byte mac[6];

  WiFi.macAddress(mac);

  for (int i = 0; i < 6; i++) {
    Serial.print(mac[i], HEX);
    if (i < 5) Serial.print(':');
    delay(100);
  } //for (int i = 0; i < 6; i++)
  Serial.println();


  Serial.println();
  Serial.println("leaving IP_Services");
  //Serial.println(Serial.available());
  while (Serial.available() > 0) {
    Serial.read(); // Read and discard a character
  } //while (Serial.available() > 0)

} //void IP_Services()



entering IP_Services.ino

SSID: xxxxx

IP Address: 192.168.1.143

server port = 8081

signal strength (RSSI):-39 dBm

Subnet Mask: 255.255.255.0

MAC address: F8:61:7A:84:21:78

leaving IP_Services

���7AY!9)5�-#!��

Ln 57, Col 1

Arduino Uno WiFi Rev2

on /dev/cu.usbmodem221402

2

It is printed by another part of your code that you did not post.

If you were to look carefully, you'll see that's all the code there is, right down to the last closed curly bracket.

I see one function, not a complete program.

Arduino sketches require a void setup() function and a void loop() function to compile in the Arduino IDE. Your post is missing both... and as important, the libraries and other information that sets up or passes data to the function in question via global variables.

The plot thickens...

No company is registered as the vendor for mac address prefix F8617A842178.