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;
}
}