1

Topic: Mega 2560 code with Esp8266-01 code

I have code that I upload to the esp01 which gets the time from NTP and sends it to the mega via serial.
The code works fine on the esp01 and the mega, until I integrate the remotexy code to the mega that was created from my interface sketch. Then I cannot connect with the remotexy app.
The mega code with the remotexy code works fine and connects with app fine as long as I have a blank sketch loaded to the esp01.
But as soon as I upload my code to the esp01, then I can't connect with the remotexy app.
This is my first project with remotexy. I have done quite a few projects with arduino but not highly skilled with that either.
I should note my configuration- CLOUD-MEGA 2560-ESP8266-ARDUINO.
Any thoughts would be appreciated.

Here's my esp01 code:

#include <ESP8266WiFi.h>
#include <time.h>

//#include <SoftwareSerial.h>
//SoftwareSerial SUART( 4, 5); //SRX  = DPin-D2; STX = DPin-D1
String str;

const char* ssid = "";
const char* password = "";

int timezone = -5 * 3600;
int dst = 1;

int cDay = 0;
int cMonth = 0;
int cYear = 0;
int cHour = 0;
int cMin = 0;
int cSecond = 0;

int upD = 86400000;    //after boot, how often to update from NTP //86400000 = 2 days
int callNtp = 5;    //get NTP "callNtp" number of times on boot every five seconds
unsigned long currentMillis = 0;  //NTP Update Timer

void setup() {

  Serial.begin(115200);
  Serial.println();
  Serial.print("Wifi connecting to ");
  Serial.println( ssid );

  WiFi.begin(ssid,password);

  //SUART.begin(115200);   //NodeMCU prefers higher Bd to work
  
  Serial.println();
  
  Serial.print("Connecting");

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

  Serial.println();

  Serial.println("Wifi Connected Success!");
  Serial.print("NodeMCU IP Address : ");
  Serial.println(WiFi.localIP() );

  configTime(timezone, dst, "pool.ntp.org","time.nist.gov");
  Serial.println("\nWaiting for Internet time");

  while(!time(nullptr)){
     Serial.print("*");
     delay(1000);
  }
  Serial.println("\nTime response....OK"); 

  currentMillis = millis();   
}

void loop() {

  if (currentMillis <= millis() && callNtp >= 1 && callNtp <= 5) {
    time_t now = time(nullptr);
    struct tm* p_tm = localtime(&now);
    Serial.print(p_tm->tm_mday);
    Serial.print("/");
    Serial.print(p_tm->tm_mon + 1);
    Serial.print("/");
    Serial.print(p_tm->tm_year + 1900);
  
    Serial.print(" ");
  
    Serial.print(p_tm->tm_hour);
    Serial.print(":");
    Serial.print(p_tm->tm_min);
    Serial.print(":");
    Serial.println(p_tm->tm_sec);
    Serial.println(callNtp);

    cHour = (p_tm->tm_hour);
    cMin = (p_tm->tm_min);
    cSecond = (p_tm->tm_sec);
    cDay = (p_tm->tm_mday);
    cMonth = (p_tm->tm_mon + 1);
    cYear = (p_tm->tm_year + 1900);
  
    //SUART.print("<Time,");
    //SUART.print(" ");
    //SUART.print(cHour);
    //SUART.print(",");
    //SUART.print(" ");
    //SUART.print(cMin);
    //SUART.print(",");
    //SUART.print(" ");
    //SUART.print(cSecond);
    //SUART.print(",");
    //SUART.print(" ");
    //SUART.print(cMonth);
    //SUART.print(",");
    //SUART.print(" ");
    //SUART.print(cDay);
    //SUART.print(",");
    //SUART.print(" ");
    //SUART.print(cYear);
    //SUART.print(">");

    Serial.print("<Time,");
    Serial.print(" ");
    Serial.print(cHour);
    Serial.print(",");
    Serial.print(" ");
    Serial.print(cMin);
    Serial.print(",");
    Serial.print(" ");
    Serial.print(cSecond);
    Serial.print(",");
    Serial.print(" ");
    Serial.print(cMonth);
    Serial.print(",");
    Serial.print(" ");
    Serial.print(cDay);
    Serial.print(",");
    Serial.print(" ");
    Serial.print(cYear);
    Serial.print(">");

    currentMillis = currentMillis + 5000;
    callNtp--;
  }

  if (callNtp < 1) {
    currentMillis = millis();
    callNtp = 6;
    Serial.println(callNtp);
  }

  if (callNtp >= 6 && currentMillis + upD <= millis()) {
    currentMillis = millis();
    callNtp = 5;
    
  }
}

2

Re: Mega 2560 code with Esp8266-01 code

Your problem is probably that remotexy is running on the mega so it's taking over the Serial port to communicate with the esp8266.

The most logical thing to do is to put the remotexy code directly on the esp8266.

What is the mega used for?

3

Re: Mega 2560 code with Esp8266-01 code

My project is a sprinkler system controller. I was planning on using the mega mostly for the pins. It would be running up to 16 relays and possibly some more features integrated later on. I have currently 3 pages on the app with various switches, edit fields and text strings. I was trying to get the esp8266 to update time to the mega and a RTC every so often to keep up to date time. I orginally had the esp code running on a nodemcu softserial then to serial1 on the mega. And the remotexy was running on serial mega to serial on the nodemcu. I couldn't connect with app in this setup either. But then there is no nodemcu to select for the module either. Same in this setup- the codes run fine on both the mega and esp8266 without the remotexy code added, but when adding remotexy code, you cannot communicate with the remotexy app. So it sounds like no matter what, I cannot run code on both of these as I'm trying to do?

4

Re: Mega 2560 code with Esp8266-01 code

RemoteXY running on the MEGA is expecting to talk to the ESP8266-01 using the original AT code that comes flashed on an ESP8266-01.  Once you flashed anything else to the ESP8266-01 it will not work with RemoteXY.  You can reflash it with the latest AT code or I guess you could use a second ESP8266-01 with original code on it, connect to a different serial port.

5

Re: Mega 2560 code with Esp8266-01 code

johnpage wrote:

RemoteXY running on the MEGA is expecting to talk to the ESP8266-01 using the original AT code that comes flashed on an ESP8266-01.  Once you flashed anything else to the ESP8266-01 it will not work with RemoteXY.  You can reflash it with the latest AT code or I guess you could use a second ESP8266-01 with original code on it, connect to a different serial port.

Ok. Thanks for the info. I did end up changing my plan. I re-flashed the ESP8266-01 with the AT code with no other code loaded. So now instead of using the ESP8266-01 to get the time from NTP and sending it to the Mega, I ended up connecting a DS3231 to the mix. I then added a couple text string settings to the app where I use them to update the time on the DS3231 which all seems to be working out fine.

6

Re: Mega 2560 code with Esp8266-01 code

Sorry but that's just stupid... Your little esp has much more memory and is about 5x faster than you mega, so why not use the esp as the brain, and use the mega only as a Serially-controlled IO expander, maybe doing some simple tasks related to the IO peripherals, but let the esp do the hard work, remotexy, ntp requests, and anything that doesn't require IO.