Sending a char array at a certain time of the day

Hi ,

I am using ESP8266 Wifi module as an access point, collecting information from an Ameba RTL8195 wireless. I want to send 25 at a certain time of the day every day at 04:00, i dont have an RTC. Can you please suggest the way for that. Really appreciate.

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

//These are the avariables you can change for your project. For example, change the SSID (network ID), change the ports on both machines.
//The most useful one is the LOOP_DELAY which changes how quicly it refreshes. set to 100ms be default.
char ssid[] = "ESPAP";      //  your network SSID (name)
char password[] = "mPass@54321";  //Set the AP's password
unsigned int localPort = 2390;        // local port to listen on
#define LOOP_DELAY    10             //how fast we check for new data
#define ARRAYSIZE     255             //size of message array (255bytes)
#define BAUD_RATE     115200          //serial comunication speed
//global variables
IPAddress remoteIp;
int remoteUDPPort;
char packetBuffer[ARRAYSIZE]; //buffer to hold incoming packet
int arraySize = ARRAYSIZE;
char inData[ARRAYSIZE]; // Allocate some space for the string
char inChar; // Where to store the character read
byte aindex = 0; // Index into array; where to store the character
boolean dataToSend = false;
WiFiUDP Udp;
void setup()
{
  Serial.begin(BAUD_RATE);
  /* You can remove the password parameter if you want the AP to be open. */
  WiFi.softAP(ssid, password);    //Start AP
  // IPAddress myIP = WiFi.softAPIP(); if ever in doubt on this devices IP address you can get it here. Should be 192.168.4.1
  Udp.begin(localPort);
  WiFi.setSleepMode(WIFI_NONE_SLEEP);
}
void loop() {
 while(Serial.available() > 0) //check for something to read from serial port
  {
      if(aindex < (arraySize-1)) // One less than the size of the array
      {
          inChar = Serial.read();   // Read a character
          inData[aindex] = inChar;  // Store it
          aindex++;                 // Increment where to write next
          inData[aindex] = '\0';    // Null terminate the string
      }
      dataToSend = true;
       }
  //check for incoming data via UDP
  int packetSize = Udp.parsePacket();
  if (packetSize)
  {
    remoteIp = Udp.remoteIP();
    remoteUDPPort = Udp.remotePort();
    int len = Udp.read(packetBuffer, 255);  //read in the packet
    if (len > 0)
    {
      packetBuffer[len] = 0;
    }
     Serial.println(packetBuffer);
  }
  // send UDP Data - this sends data to the last device it receives data from. For a one to one link this is fine. If there are multiple clients then this may need to be adjusted to store and send to all clients.
  if(dataToSend)
  {
    if(Udp.beginPacket(remoteIp, remoteUDPPort))
    {
      Udp.write(inData);
      Udp.endPacket();
      //Serial.println(inData); //Uncomment this line for a local echo of the data sent
      }
    else
    {
      Serial.println("No connection");
    }
    dataToSend = false; //set the flag to false, ie only send when you need to.
    for (aindex=0; aindex < arraySize; aindex++)  //wipe the array
    {
       inData[aindex] = '\0'; // Null terminate the string
    }
    aindex = 0; //reset the index
   
  }
   //Serial.println(now()); 
}

You don't need RTC to keep track of the time, there are several libraries that will do that for you. What the RTC brings to the party is the ability to keep track of the time when the power is off (assuming it has a charged battery). Without that, you have to have some way of setting the time. You have WiFi. query the net. Once the time is set, configure a countdown timer from when you set to 0400.

DKWatson:
You don’t need RTC to keep track of the time, there are several libraries that will do that for you. What the RTC brings to the party is the ability to keep track of the time when the power is off (assuming it has a charged battery). Without that, you have to have some way of setting the time. You have WiFi. query the net. Once the time is set, configure a countdown timer from when you set to 0400.

Thanks DKWatson for the response. Is it not possible to get time from the PC to which the ESP is connected ? Can you please share a snippet as I could not understand the method of getting the time and do some action based on it? Much appreciated

If you have an application running on the PC that is in communication with the Arduino, that app would have to have a facility built in to provide time and date data upon request. That would be application dependent. If you write your own PC software then that shouldn't be a problem.

As for any snippet, I don't do snippets, I try to help people with their (already written) code. Give it a go and post your results, you'll get a lot more responses. As for understanding time, read up a bit on Unix time. This is the format essentially used by every bit of electronics on the planet. It's a 32bit integer that tracks the elapsed time in seconds from 0000 January 1, 1970.