[Solved] Standalone ESP8266 Library Issues

Hi, so I am want to get my local time printed out on the Serial Monitor, so I bought a standalone ESP8266 module: Amazon.com

I am following this tutorial: https://www.instructables.com/id/Simplest-ESP8266-Local-Time-Internet-Clock-With-OL/

The code used is:

/*
 * TimeNTP_ESP8266WiFi.ino
 * Example showing time sync to NTP time source
 *
 * This sketch uses the ESP8266WiFi library
 */

#include <TimeLib.h>
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>

const char ssid[] = "*************";  //  your network SSID (name)
const char pass[] = "********";       // your network password

// NTP Servers:
static const char ntpServerName[] = "us.pool.ntp.org";
//static const char ntpServerName[] = "time.nist.gov";
//static const char ntpServerName[] = "time-a.timefreq.bldrdoc.gov";
//static const char ntpServerName[] = "time-b.timefreq.bldrdoc.gov";
//static const char ntpServerName[] = "time-c.timefreq.bldrdoc.gov";

const int timeZone = 1;     // Central European Time
//const int timeZone = -5;  // Eastern Standard Time (USA)
//const int timeZone = -4;  // Eastern Daylight Time (USA)
//const int timeZone = -8;  // Pacific Standard Time (USA)
//const int timeZone = -7;  // Pacific Daylight Time (USA)


WiFiUDP Udp;
unsigned int localPort = 8888;  // local port to listen for UDP packets

time_t getNtpTime();
void digitalClockDisplay();
void printDigits(int digits);
void sendNTPpacket(IPAddress &address);

void setup()
{
  Serial.begin(9600);
  while (!Serial) ; // Needed for Leonardo only
  delay(250);
  Serial.println("TimeNTP Example");
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, pass);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.print("IP number assigned by DHCP is ");
  Serial.println(WiFi.localIP());
  Serial.println("Starting UDP");
  Udp.begin(localPort);
  Serial.print("Local port: ");
  Serial.println(Udp.localPort());
  Serial.println("waiting for sync");
  setSyncProvider(getNtpTime);
  setSyncInterval(300);
}

time_t prevDisplay = 0; // when the digital clock was displayed

void loop()
{
  if (timeStatus() != timeNotSet) {
    if (now() != prevDisplay) { //update the display only if time has changed
      prevDisplay = now();
      digitalClockDisplay();
    }
  }
}

void digitalClockDisplay()
{
  // digital clock display of the time
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.print(" ");
  Serial.print(day());
  Serial.print(".");
  Serial.print(month());
  Serial.print(".");
  Serial.print(year());
  Serial.println();
}

void printDigits(int digits)
{
  // utility for digital clock display: prints preceding colon and leading 0
  Serial.print(":");
  if (digits < 10)
    Serial.print('0');
  Serial.print(digits);
}

/*-------- NTP code ----------*/

const int NTP_PACKET_SIZE = 48; // NTP time is in the first 48 bytes of message
byte packetBuffer[NTP_PACKET_SIZE]; //buffer to hold incoming & outgoing packets

time_t getNtpTime()
{
  IPAddress ntpServerIP; // NTP server's ip address

  while (Udp.parsePacket() > 0) ; // discard any previously received packets
  Serial.println("Transmit NTP Request");
  // get a random server from the pool
  WiFi.hostByName(ntpServerName, ntpServerIP);
  Serial.print(ntpServerName);
  Serial.print(": ");
  Serial.println(ntpServerIP);
  sendNTPpacket(ntpServerIP);
  uint32_t beginWait = millis();
  while (millis() - beginWait < 1500) {
    int size = Udp.parsePacket();
    if (size >= NTP_PACKET_SIZE) {
      Serial.println("Receive NTP Response");
      Udp.read(packetBuffer, NTP_PACKET_SIZE);  // read packet into the buffer
      unsigned long secsSince1900;
      // convert four bytes starting at location 40 to a long integer
      secsSince1900 =  (unsigned long)packetBuffer[40] << 24;
      secsSince1900 |= (unsigned long)packetBuffer[41] << 16;
      secsSince1900 |= (unsigned long)packetBuffer[42] << 8;
      secsSince1900 |= (unsigned long)packetBuffer[43];
      return secsSince1900 - 2208988800UL + timeZone * SECS_PER_HOUR;
    }
  }
  Serial.println("No NTP Response :-(");
  return 0; // return 0 if unable to get the time
}

// send an NTP request to the time server at the given address
void sendNTPpacket(IPAddress &address)
{
  // 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();
}

and have hooked everything up but when I try to upload the code I get this error:

Arduino: 1.8.8 (Windows Store 1.8.19.0) (Windows 10), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

TimeNTP_ESP8266WiFi:9:25: error: ESP8266WiFi.h: No such file or directory

compilation terminated.

exit status 1
ESP8266WiFi.h: No such file or directory

I have downloaded the libraries I was supposed to on the tutorial so I can't imagine why this is. However, I thought I would just get the ESP8266WiFi.h library however I can't find it anywhere online! I have spent the last two or three hours downloaded different libraries and looking at lots of tutorials but can't seem to figure this out.

Any help would be awesome,
Thanks!

*To clarify I am not using the ESP8266 board, but the small module that looks like an nrf24L01 module.

Vulcan666:

Arduino: 1.8.8 (Windows Store 1.8.19.0) (Windows 10), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

You need to select the correct board for your ESP8266 from the Tools > Board menu. If you don't see the ESP8266 boards on that menu, you probably haven't installed the ESP8266 core for Arduino yet. Instructions are here:

Vulcan666:
I thought I would just get the ESP8266WiFi.h library however I can't find it anywhere online!

The ESP8266WiFi library is bundled with the ESP8266 core for Arduino. It doesn't make sense to install it separately from the core because it will only work when used in conjunction with the core. Libraries bundled with a hardware package like the ESP8266 core for Arduino are only available when one of the boards of that package are selected from the Tools > Board menu. Thus, when you have Tools > Board > Arduino Mega selected, you'll get the "No such file or directory" error even when the ESP8266WiFi library is installed.

Thanks for the help, am I correct in understanding that you are saying I can't use the module in conjunction with my mega 2560? Because I saw several tutorials with people who were doing that.

To further clarify...I am using an Arduino Mega 2560 with the ESP8266 module (see the link in first post) connected.

(It's not an actual ESP8266 board...it's a little module you can connect to an Arduino board, just like the NRF24L01.)

I use the same - a mega2560 with an esp8266; you have to treat both as separate IDE programs (with selected board via Tools menu) and use serial commands to send/receive any information. If you're not familiar with solid serial comms between boards, Serial Input Basics is a good place to start.

I don't see anything in that Instructable that mentions connecting it to an Arduino board. The code is written to run directly on an ESP8266. Some people use an Arduino board as a USB to TTL serial adapter to upload to the ESP8266, and that is something you could use your Mega for with this project, but you have no chance of ever getting that code to run on your Mega.

It's funny because the author of the tutorial gives this link for "ESP8266WiFi.h & WifiUDP.h":

However, that library has never contained files of those names. At one time, it did contain a file named ESP8266wifi.h, but filename case matters in the Arduino IDE, even using Windows. ESP8266WiFi.h and ESP8266wifi.h are two very different things. It seems the author of the code doesn't really know what they're talking about, something all too common on Instructables. I would be wary of the accuracy and quality of their code and documentation.

@Jmeller thank, okay, I had originally planned on using my mega in conjunction with the esp8266 and communicating via serial just like you suggested. I had actually started to do that, but my esp8266's connection on my cord...some mini usb got loose so I couldn't power it. I then noticed online this small module: Amazon.com

I thought I would be able to hook it up to my mega and it would give me wifi capabilities without having to run an entirely new board...since its not, what is it for then?)

@pert thanks, yes, I had also noticed that the libraries hadn't matched up which was why I tried finding one on my own, and okay, my mistake, like I told jmeller I thought I could hook up the module in the link above to my mega

Just to make sure that you understand what I am trying to say, this is what I am using when I talk about the ESP8266 module:

obviously its a little module not the actual board (btw I am using the 01 which is the module on the left in the pic)

Vulcan666:
I thought I would be able to hook it up to my mega and it would give me wifi capabilities without having to run an entirely new board...since its not, what is it for then?)

I use the ESP-01. I treat it like the nrf module - access to communicate wireless and transmit information to a robust display i.e., TFT. As for the input voltage for the ESP, you will need to either purchase 3.3 voltage regulator (which are plenty on Amazon - or your favorite online parts store) or build a voltage divider.

Vulcan666:
I thought I would be able to hook it up to my mega and it would give me wifi capabilities without having to run an entirely new board...since its not, what is it for then?)

You can use it that way if you want. You just can't use it that way with the code in the Instructable. When you get the ESP-01 module like the one you have, it has the AT firmware installed. You can sent AT commands to the ESP8266 over a serial connection from a regular Arduino board like your Mega to control its WiFi functionality. This allows you to use the ESP-01 as a WiFi adapter for your Mega. GitHub - ekstrand/ESP8266wifi: ESP8266 Arduino library with built in reconnect functionality is actually written for that purpose. However, if you're doing that, I recommend using this library instead of ESP8266wifi:
GitHub - bportaluri/WiFiEsp: Arduino WiFi library for ESP8266 modules
Unlike ESP8266wifi, it provides an API that is compatibility with all the standard Arduino network libraries. This means you can easily adapt code that was written for the Ethernet, WiFi, etc. libraries for use with the WiFiESP library.

There are a couple of alternate firmwares you can install to the ESP8266 that are similar in function to the AT firmware, but have a different interface. I haven't used any of these so I can't provide any more info. Maybe someone else will have input on that. The great advantage of the AT firmware is that it's already on the ESP-01, so you don't need to deal with the complexity of figuring out how to flash the thing with new firmware.

As Jmeller explained, you can also write your own Arduino sketch to upload to the ESP8266 and another for the Mega. That is a bit complex, but it will give you the most flexibility.

The other way to use the ESP8266 is to use it standalone and program it directly from the Arduino IDE. This is the usage in the Instructable. The ESP-01 is a little less well suited for that usage because it's missing some of the components you would find on something like a WeMos D1 Mine or NodeMCU board that make it easier to use, and also doesn't have many of the GPIO pins broken out to the header for easy use. However, many people have used the ESP-01 in this manner.

Okay, so things are starting to make a lot more sense now...this is very new to me and I see some of the rookie mistakes I made. The instructible is for programming the esp8266 module itself! Didn't know you could even do that! That must be what the tx and rx pins are for?

Okay, so that is what I would want to do, send commands over serial from my mega to the esp-01 module so it would act like a Wi-Fi adapter for my mega! Unfortunately I have no idea how to do that...is there a tutorial I could follow somewhere if I look online? (What is this called?)

@Jmeller what will happen if I don't? Right now I have it in my 3.3V pin in the mega so that should be fine right?

Vulcan666:
@Jmeller what will happen if I don't? Right now I have it in my 3.3V pin in the mega so that should be fine right?

From what I have read -no. You'll end up damaging your Mega; the ESP-01 will pull in excess of 200mA.

As for the code, I will strip down a basic version to get you pointed in the correct direction - but, you must read the Serial Basics link above to fully understand.

The ESP-01 has a HUGE amount of flash - another reason I like it; It's able to hold many custom IR commands to transmit to my Mega (via ALEXA) to control my entertainment system- just to show you the possibilities of an ESP-01 paired with any arduino board.

I don't think it will actually damage the Mega. Any good voltage regulator will shut down when the current draw is too high. What happens is that the ESP8266 only draws high current intermittently (when operating the WiFi radio). So the thing seems to be working fine at first glance, but then you eventually find that the WiFi communication is not reliable. This sort of intermittent failure can lead to a lot of frustration and wasted time. It's really crucial to make sure you have a proper power supply for the ESP8266.

Ok, thanks for the adivce...I'll get one

@Jmeller did you get a basic thing I could look out to figure out how to do it?

Thanks to both of you!

To be honest, my code instantly grabs the time. When I strip it down to the basics, it contacts the server - however, it fails to retrieve the time- level 1 n00b Since it getting late, the more experienced (pert</>) may provide a better example; if the question is still open by next weekend (my free time), I'll hash it out. In the mean time, don't forget to read Serial Basics.

I've never done a project with a custom firmware on the ESP8266 communicating with a different Arduino board. I have done some things with the ESP8266 running the AT firmware, communicating with a different Arduino board using the WiFiESP library. If you want to see examples of how to do that, just install the WiFiESP library and then look at the examples under File > Examples > WiFiESP. WebServerLed is a good example.

Thanks again guys, yes I am reading Serial Basics, and will see if I can figure it out myself. WebServerLed was a good start...I am eventually wanting to send data from my mega to the esp-01 to google sheets.

Well, I found the hindrance from earlier; a novice mistake- I failed to insert into wifiSetup() :
udp.begin(localPort);

Note to self: no coding during/after the normal time to lay flat with eyes closed.

Anyhow, the example code is broken into two parts - the first IDE code is for the ESP-01 and the second is to be uploaded to the Mega2560. You'll see the similarities (nearly verbatim) from the referenced Serial Basics.

The following was tested and found operational.

ESP-01 IDE code

Referenced NTP code:
/*

 Udp NTP Client

 Get the time from a Network Time Protocol (NTP) time server
 Demonstrates use of UDP sendPacket and ReceivePacket
 For more on NTP time servers and the messages needed to communicate with them,
 see http://en.wikipedia.org/wiki/Network_Time_Protocol

 created 4 Sep 2010
 by Michael Margolis
 modified 9 Apr 2012
 by Tom Igoe
 updated for the ESP8266 12 Apr 2015 
 by Ivan Grokhotkov

 This code is in the public domain.

 */
#include <TimeLib.h>          //https://github.com/PaulStoffregen/Time //Time Library - Time-master
#include <ESP8266WiFi.h>      //https://github.com/esp8266/Arduino/releases/tag/2.3.0-rc2
#include <WiFiUdp.h>          //https://github.com/esp8266/Arduino/releases/tag/2.3.0-rc2
WiFiUDP udp;

// Not Needed - just added info
#include <ESP8266WebServer.h> //https://github.com/esp8266/Arduino/releases/tag/2.3.0-rc2
#include <ESP8266mDNS.h>      //https://github.com/esp8266/Arduino/releases/tag/2.3.0-rc2
ESP8266WebServer ESP8266server(80);
//

#define SERIAL_BAUDRATE                 115200

char WIFI_SSID[30] = {"YOURssid"}; 
char WIFI_PASS[30] = {"YOURpassword"};

const unsigned int localPort = 2390;      // local port to listen for UDP packets
const char* ntpServerName = "time.nist.gov";
const unsigned int NTP_PACKET_SIZE = 48;
byte packetBuffer[NTP_PACKET_SIZE];

char addChar[2];
char  DATE[20]; // = 01/01/1970 00:00:00

const int bytesMAX   = 4000;
unsigned long c_slot;//CHARstring[c_slot]
char CHARstring[bytesMAX];

unsigned long PROcheck = 0;

void setup() {
  Serial.begin(SERIAL_BAUDRATE);
  Serial.println();
  Serial.printf("Booting..."); // this will be ignored by the Mega since a start sentinel is not in the print
  delay(1000); // wait for serial initialization
  
  // clear character array
  memset(CHARstring, '\0', sizeof(CHARstring) - 1); 

  //copy "ESP-01 booting" into char array CHARstring
  strcpy(CHARstring, "ESP-01 booting");          

  //  'E' will pre-determine how the Mega will process the serial data   //send CHARstring
  SendToMega('E');                              

  wifiSetup();

  //get ready to send IP Address to Mega
  IPAddress ip = WiFi.localIP();
  char buf1[16];
  //Store machine IP address into char array buf1
  sprintf(buf1, "%d.%d.%d.%d:%d", ip[0], ip[1], ip[2], ip[3]);

   //Store "IP Address = " into char array CHARstring
  strcpy(CHARstring, "IP Address = ");  

  //concatenate CHARstring to store "IP Address = nnn.mmm.ooo.ppp
  strcat(CHARstring, buf1);  

  //  'E' will pre-determine how the Mega will process the serial data   //send CHARstring
  SendToMega('E');         
}

void loop() {

  //non-blocking timer
  if (millis() - PROcheck > 5000 ) {
    PROcheck = millis();
    if (WiFi.status() == WL_CONNECTED && year() == 1970) {
      SetTime();
      //Serial.printf("[MAIN] Free heap: %d bytes\n", ESP.getFreeHeap());
    }


  }
}


void wifiSetup() {
  WiFi.mode(WIFI_AP);

  //Force DCHP

  IPAddress ip(0, 0, 0, 0);
  IPAddress gateway(0, 0, 0, 0);
  IPAddress subnet(0, 0, 0, 0);


  //Force Static IP
  //IPAddress ip(10, 6, 5, 79);
  //IPAddress gateway(10, 6, 5, 75);
  //IPAddress subnet(255, 255, 255, 0);



  WiFi.begin(WIFI_SSID, WIFI_PASS);
  WiFi.config(ip, gateway, subnet);
  Serial.println();
  Serial.println(WiFi.localIP());

  //Start udp to retrieve time from ntp server
  Serial.println("Starting UDP");
  udp.begin(localPort);
  Serial.print("Local port: ");
  Serial.println(udp.localPort());

  //creates a webpage pointer
  //WiFi.hostname("Vulcan666");


  while (WiFi.status() != WL_CONNECTED) {
    Serial.print('.');
    delay(500);
  }

  Serial.println();

/*
  //Create a wifi server with a name
  MDNS.begin("Vulcan666", WiFi.localIP());
  if (MDNS.begin("Vulcan666")) {              // Start the mDNS responder for esp8266.local
    Serial.printf("mDNS responder started!!");
    MDNS.addService("http", "tcp", 80);
  } else {
    Serial.printf("Error setting up MDNS responder!");
    Serial.println();
  }
*/
}
void SetTime() {
  Serial.printf("Contacting NTP server ...");
  //get a random server from the pool
  IPAddress timeServerIP;
  WiFi.hostByName(ntpServerName, timeServerIP);

  Serial.printf("timeServerIP = ");
  Serial.println(timeServerIP);
  Serial.println();
  sendNTPpacket(timeServerIP); delay(500);// send an NTP packet to a time server
  //return;
  int cb = udp.parsePacket();
  if (!cb) {
    Serial.printf("No answer from NTP ...");
    Serial.println();
  } else {
    Serial.printf("Got Time!");
    Serial.println();

    udp.read(packetBuffer, NTP_PACKET_SIZE);    // read the packet into the buffer
    Serial.println("Contacting NTP ...");
    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;     // Unix time starts on Jan 1 1970. In seconds, that's 2208988800:
    unsigned long epoch = secsSince1900 - seventyYears; // subtract seventy years (UNIX time)

    setTime(epoch);
    setTime(hour(), minute(), second(), day(), month(), year());

    unsigned long MYtime = now();


    memset(CHARstring, '\0', sizeof(CHARstring) - 1); // clear character array
    
    // convert MYtime integer to string; assign character array with converted string value of MYtime
    strcpy(CHARstring, String(MYtime).c_str()); 

     //  'U' will pre-determine how the Mega will process the serial data   //send CHARstring
    SendToMega('U');                              
    memset(packetBuffer, '\0', sizeof(packetBuffer)); //clear buffer
  }
}

unsigned long sendNTPpacket(IPAddress& address) { // for get time
  // send an NTP request to the time server at the given address
  memset(packetBuffer, 0, NTP_PACKET_SIZE);    // set all bytes in the buffer to 0
  // 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();
}
void SendToMega(char DataType) { //, String text) {
  Serial.println(CHARstring);  // no effect to Mega since there is not a start/stop sentinel.
/*
  Example output: *U1552326914$
  * = start sentinel
  U = preassigned determination of use in the Mega
   UNIX Time
  $ = stop sentinel
*/
  Serial.write('*'); delay(2); //start sentinel
  Serial.write(DataType); delay(2);  //pre-determine how the Mega will process the serial data

  for (int i = 0; i < sizeof(CHARstring) - 1; i++) {
    delay(2);
    
    if (i > 0 && CHARstring[i] == '\0' && CHARstring[i - 1] == '\0') {
      break;   //when reading character, if character is null, exit loop
    }
    
    Serial.write(CHARstring[i]);
  }

  Serial.write('

);  //stop sentinel

memset(CHARstring, '\0', sizeof(CHARstring) - 1); // clear character array
}

Mega2560 IDE code (or any arduino with serial1 pins reassigned)

/*
Robin2 Serial Basics reference: https://forum.arduino.cc/index.php?topic=288234.0
*/

#include <TimeLib.h> //https://github.com/PaulStoffregen/Time

const int bytesMAX   = 3000;
unsigned long c_slot;//CHARstring[c_slot]
char CHARstring[bytesMAX];
bool newData;

unsigned int gNewDateTime [8]; //mo/day/yr/hr/min/sec

#define SERIAL_BAUDRATE                 115200 // for USB comms to PC
#define SERIAL1_BAUDRATE                 115200 // for comms to ESP8266
void setup() {
  Serial.begin(SERIAL_BAUDRATE);
  Serial1.begin(SERIAL_BAUDRATE);

  //print to IDE serial monitor
  Serial.println();
  Serial.println("Mega Booting...");

}

void loop() {

  if (Serial1.available() > 0) {  // Serial comms on Mega Serial1 = TX1 & RX1 (pins 18 & 19) // receive from ESP8266
    Check_Serial();
  }

}

void Check_Serial() {

  static boolean recvInProgress = false;
  //char DataType = 'H';
  char rc;
  char affirm;

  const char bitSTART = '*';
  const char bitSTOP  = '

Output from Mega2560 serial monitor:

Mega Booting...
ESP-01 booting
IP Address = 10.6.5.77:908996657
Unix Time received from ESP-01: 1552431345

I also threw in a few string gems (commented) to fast-track anyone reading this; I really could have used them when I was introduced to the arduino.

Best of luck with your project.;
 char DataType;

c_slot = 0;
 memset(CHARstring, '\0', sizeof(CHARstring));

while (Serial1.available() && newData == false) {
   delay(2);
   rc = Serial1.read();

if (recvInProgress == true) {
     if (rc != bitSTOP) {
       CHARstring[c_slot] = rc;
       c_slot++;
       if (c_slot == bytesMAX - 1) {
         c_slot = 0;
       }

} else {
       CHARstring[c_slot] = '\0'; // terminate the string
       recvInProgress = false;
       c_slot = 0;
       newData = true;
       showNewData(DataType);
       DataType = 'L';
     }
   }
   else if (rc == bitSTART) {
     rc = Serial1.read();
     DataType = rc;
     c_slot = 0;
     recvInProgress = true;
   }

}
}

void showNewData(char MyDataType) {

newData = false;
 switch (MyDataType) {
   case 'E':
   //'E' used to receive various status messages from ESP-01
   Serial.println(CHARstring);
   break;
   
   case 'U':
     //'U' used to process UNIX time only
     Serial.print("Unix Time received from ESP-01: ");
     Serial.println(CHARstring);
     break;

}
 memset(CHARstring, '\0', sizeof(CHARstring) - 1);
}


Output from Mega2560 serial monitor:

§DISCOURSE_HOISTED_CODE_1§


I also threw in a few string gems (commented) to fast-track anyone reading this; I really could have used them when I was introduced to the arduino.

Best of luck with your project.

Thanks all lot Jmeller! I'll give it a try and see if I can get it up and running.