Hi -
I have some software that is functioning well, but for a rather irritating problem. I am getting internet time from NTP servers using some pretty standard code - see below:
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <WiFiClient.h>
#include <WiFiUdp.h>
#include <time.h>
#include <string>
#include <sstream>
...
const char* ntpServerName = "time.nist.gov";
const int NTP_PACKET_SIZE = 48; // NTP time stamp is in the first 48 bytes of the message
unsigned long curTime = 0;
unsigned int localPort = 2390; // local port to listen for UDP packets
byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets
IPAddress timeServerIP; // time.nist.gov NTP server address
WiFiUDP udp;
...
//==================================
// GetTimeFromServer Routine
//==================================
String getTimeFromServer() {
WiFi.hostByName(ntpServerName, timeServerIP);
sendNTPpacket(timeServerIP); // send an NTP packet to a time server
delay(1000); // wait to see if a reply is available
int cb = udp.parsePacket();
if (!cb) {
Serial.println("no packet yet");
return "";
}
else {
//Serial.print("packet received, length=");
//Serial.println(cb);
// We've received a packet, read the data from it
udp.read(packetBuffer, NTP_PACKET_SIZE); // read the packet into the buffer
//the timestamp starts at byte 40 of the received packet and is four bytes,
// or two words, long. First, extract the two words:
unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);
unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]);
unsigned long secsSince1900 = highWord << 16 | lowWord;
const unsigned long seventyYears = 2208988800UL;
unsigned long epoch = secsSince1900 - seventyYears;
time_t secs = epoch;
tm *t = localtime(&secs);
char genout[20];
sprintf(genout, "%04d%02d%02d%02d%02d%02d", t->tm_year+1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec);
return genout;
}
}
//==================================
// SendNTPacket Routine
//==================================
unsigned long sendNTPpacket(IPAddress& address) {
// send an NTP request to the time server at the given address
//Serial.println("sending NTP packet...");
// set all bytes in the buffer to 0
memset(packetBuffer, 0, NTP_PACKET_SIZE);
// Initialize values needed to form NTP request
// (see URL above for details on the packets)
packetBuffer[0] = 0b11100011; // LI, Version, Mode
packetBuffer[1] = 0; // Stratum, or type of clock
packetBuffer[2] = 6; // Polling Interval
packetBuffer[3] = 0xEC; // Peer Clock Precision
// 8 bytes of zero for Root Delay & Root Dispersion
packetBuffer[12] = 49;
packetBuffer[13] = 0x4E;
packetBuffer[14] = 49;
packetBuffer[15] = 52;
// all NTP fields have been given values, now
// you can send a packet requesting a timestamp:
udp.beginPacket(address, 123); //NTP requests are to port 123
udp.write(packetBuffer, NTP_PACKET_SIZE);
udp.endPacket();
}
As I said, this works fine, but prints the following to the serial port:
[hostByName] request IP for: time.nist.gov
[hostByName] Host: time.nist.gov IP: 132.163.97.1
Those strings certainly don't appear in my code, so must be coming from the library routines - which I am not yet clever enough to investigate!
Can anyone please suggest a way of suppressing these messages as I am using the serial port for communications with another device and these messages are screwing things up.
Thanks.
PhilTilson:
Those strings certainly don't appear in my code,
How would we know? The code you posted is incomplete -- no setup() or loop() functions.
The program is over 600 lines long. I have read Item 6 in Nick Gammon's sticky: "With coding problems, if possible post a "minimal" sketch that demonstrates the problem - not hundreds of lines of code", and thus decided to include only those parts that I thought relevant.
You will see that I have included the Library calls, the declaration of the relevant variables and the two routines that call for and process the time from the NTP server.
If you really want to wade through the remainder of the program, none of which bears any relationship to the question, I will post it! But I was just trying to be the good guy on this forum. 
"Minimal" in this sense means an MCVE. That's the smallest possible code that compiles AND demonstrates the problem. The code you posted does neither.
As requested!
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <WiFiClient.h>
#include <WiFiUdp.h>
#include <time.h>
#include <string>
#include <sstream>
const char* ssid = "--ssid--";
const char* password = "--pass--";
const byte clk = 14; //Pin 14 is the clock or enable input
const byte dat = 12; //Pin 12 is the data input
byte clkval;
byte datval;
volatile byte updSts = LOW;
//Stuff for getting time
String newTime="";
const char* ntpServerName = "time.nist.gov";
const int NTP_PACKET_SIZE = 48; // NTP time stamp is in the first 48 bytes of the message
unsigned long curTime = 0;
unsigned int localPort = 2390; // local port to listen for UDP packets
byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets
IPAddress timeServerIP; // time.nist.gov NTP server address
WiFiUDP udp;
ESP8266WebServer server(80);
void IntSvc() {
updSts = HIGH;
}
void handleRoot() {
}
void handleTemps() {
}
void handleNotFound() {
}
void RxData() {
}
char getCRC(char genin[]) {
}
void setup(void) {
Serial.begin(115200);
pinMode(clk, INPUT);
pinMode(dat, INPUT);
attachInterrupt(digitalPinToInterrupt(clk),IntSvc, RISING);
WiFi.begin(ssid, password);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
server.on("/", handleRoot);
server.on("/temps", handleTemps);
server.onNotFound(handleNotFound);
server.begin();
Serial.println("HTTP server started");
//Stuff for getting time
Serial.println ("Starting UDP...");
udp.begin(2390);
Serial.print("Status after udp.begin: ");
Serial.println(WiFi.status());
}
void loop(void) {
if (updSts==HIGH) { //we have an update to service
RxData();
attachInterrupt(digitalPinToInterrupt(clk),IntSvc, RISING);
yield();
}
//Stuff for getting time
if (millis()-curTime > 60000) { //we need to get the time every minute
curTime = millis();
//Serial.print("Time from Server: ");
newTime = getTimeFromServer() + "000000003"; //to signify it's a time string
if (newTime.length() == 23) {
char buf[] = {'000000000000000000000000'};
newTime.toCharArray(buf,24);
buf[23]=getCRC(buf);
Serial.print("#");
for(int i=0; i<24; i++) {
Serial.print(buf[i]);
}
Serial.println("#");
}
}
server.handleClient();
}
//==================================
// GetTimeFromServer Routine
//==================================
String getTimeFromServer() {
WiFi.hostByName(ntpServerName, timeServerIP);
sendNTPpacket(timeServerIP); // send an NTP packet to a time server
delay(1000); // wait to see if a reply is available
int cb = udp.parsePacket();
if (!cb) {
Serial.println("no packet yet");
return "";
}
else {
//Serial.print("packet received, length=");
//Serial.println(cb);
// We've received a packet, read the data from it
udp.read(packetBuffer, NTP_PACKET_SIZE); // read the packet into the buffer
//the timestamp starts at byte 40 of the received packet and is four bytes,
// or two words, long. First, extract the two words:
unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);
unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]);
unsigned long secsSince1900 = highWord << 16 | lowWord;
const unsigned long seventyYears = 2208988800UL;
unsigned long epoch = secsSince1900 - seventyYears;
time_t secs = epoch;
tm *t = localtime(&secs);
char genout[20];
sprintf(genout, "%04d%02d%02d%02d%02d%02d", t->tm_year+1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec);
return genout;
}
}
//==================================
// SendNTPacket Routine
//==================================
unsigned long sendNTPpacket(IPAddress& address) {
// send an NTP request to the time server at the given address
//Serial.println("sending NTP packet...");
// set all bytes in the buffer to 0
memset(packetBuffer, 0, NTP_PACKET_SIZE);
// Initialize values needed to form NTP request
// (see URL above for details on the packets)
packetBuffer[0] = 0b11100011; // LI, Version, Mode
packetBuffer[1] = 0; // Stratum, or type of clock
packetBuffer[2] = 6; // Polling Interval
packetBuffer[3] = 0xEC; // Peer Clock Precision
// 8 bytes of zero for Root Delay & Root Dispersion
packetBuffer[12] = 49;
packetBuffer[13] = 0x4E;
packetBuffer[14] = 49;
packetBuffer[15] = 52;
// all NTP fields have been given values, now
// you can send a packet requesting a timestamp:
udp.beginPacket(address, 123); //NTP requests are to port 123
udp.write(packetBuffer, NTP_PACKET_SIZE);
udp.endPacket();
}
This is all your code prints out for me using a Wemos D1 mini.
Connected to ******
IP address: *******
HTTP server started
Starting UDP...
Status after udp.begin: 3
#20190314163415000000003
#20190314163515000000003
#20190314163615000000003
#20190314163715000000003
cattledog:
This is all your code prints out for me using a Wemos D1 mini.
OP, did you actually verify that code you posted demonstrates the problem?
From what I can tell digging though the library is that those should prints will only happen if BOTH of these macros are defined:
DEBUG_ESP_WIFI
DEBUG_ESP_PORT
That's very interesting.
Yes, I can confirm that the code compiled correctly on my machine and produced the (undesired) output as shown in the original query.
I had not considered that this could have been generated by the ESP itself via the Arduino IDE. On checking I find that, under the Tools menu, it says: "Debug port: Serial Debug Level: WIFI".
So presumably that could solve my problem! I will report back... 
Yea, go with "Disabled" / "None".
Yup! That did the trick.
As you will appreciate, I am fairly new to the Arduino environment (long-term VB6 programmer!) so there will be a few surprises to discover yet.
Many thanks.