Sending the time to arduino via HC-06

I am trying to send my arduino the current time and then display it. I have no experience with android and I'm wondering what would be the best way to do this. I played around with app inventor to see if I could do it and got no such luck, but perhaps I'm not seeing something? I was just wondering how I should go about doing this.

What I've done in this regard is send commands (ascii strings) from BlueTerm (on Android), like "TIME=12:34:59".

The Arduino sketch interprets the command once it receives it, that is, gets the hour, minute, seconds, then sets the time in RTC.

Hmmm, not sure if that would work since I don't have an RTC connected, unless there's something I don't know about.

You can send time from android to arduino with serial commands via bluetooth no doubts, but if you want the clock to be permanently updated on arduino display, then you'd better get an RTC module, unless you want to update time from bluetooth each second.

Sending the time from Android is only for synchronization purpose. You should be able to measure time on Arduino without RTC, take a look at time library.
What do you find challenging?

florinc:
Sending the time from Android is only for synchronization purpose. You should be able to measure time on Arduino without RTC, take a look at time library.
What do you find challenging?

florinc:
Sending the time from Android is only for synchronization purpose. You should be able to measure time on Arduino without RTC, take a look at time library.
What do you find challenging?

Yea but with the time library time error will be higher than with RTC, because of the crystal.

florinc:
What I've done in this regard is send commands (ascii strings) from BlueTerm (on Android), like "TIME=12:34:59".

The Arduino sketch interprets the command once it receives it, that is, gets the hour, minute, seconds, then sets the time in RTC.

Could you please give me some example code as to how the Arduino interprets the ascii strings?

These fragments are copied from the source code I share on my blog. Check it out.

// globals; their values are set in getTimeFromRTC();
int hour;
int minute;
int second = 0;
int year, month, day;


// receive commands from serial port in this buffer;
char cmdBuffer[30] = {0};
byte nCrtBufIndex = 0;

...

void loop()
{
  checkCommands();
  
  timeReadingCounter++;
  if (timeReadingCounter > MAX_TIME_READING_COUNTER)
  {
    getTimeFromRTC();
    display_time();

    timeReadingCounter = 0;
  }
}

...

void checkCommands()
{
	while (Serial.available() > 0)
	{
		// read the incoming byte;
		char inChar = Serial.read();
		cmdBuffer[nCrtBufIndex++] = inChar;
		if (nCrtBufIndex >= sizeof(cmdBuffer)-1)
                    shiftBufferLeft();
	}

	if (0 == strncmp(cmdBuffer, "TIME=", 5) && nCrtBufIndex > 12)
	{
          // time setting command;
          #ifdef _DEBUG_
            Serial.print(">>Received command: ");
            Serial.println(cmdBuffer);
          #endif

          // next characters are the time, formatted HH:MM:SS;
          hour   = (cmdBuffer[5]-'0') * 10 + (cmdBuffer[6]-'0');
          minute = (cmdBuffer[8]-'0') * 10 + (cmdBuffer[9]-'0');
          second = (cmdBuffer[11]-'0')* 10 + (cmdBuffer[12]-'0');

          setTime(hour, minute, second);
          resetBuffer();
	}
	else if (0 == strncmp(cmdBuffer, "DATE=", 5) && nCrtBufIndex > 12)
	{
          // date setting command;
          #ifdef _DEBUG_
            Serial.print(">>Received command: ");
            Serial.println(cmdBuffer);
          #endif

          // next characters are the date, formatted YY/MM/DD;
          year  = (cmdBuffer[5]-'0') * 10 + (cmdBuffer[6]-'0');
          month = (cmdBuffer[8]-'0') * 10 + (cmdBuffer[9]-'0');
          day   = (cmdBuffer[11]-'0')* 10 + (cmdBuffer[12]-'0');

          setDate(year, month, day);
          resetBuffer();
	}
}


void resetBuffer()
{
  for (byte i=0; i<sizeof(cmdBuffer); i++)
    cmdBuffer[i] = 0;

  nCrtBufIndex = 0;
}

void shiftBufferLeft()
{
  for (byte i=0; i<sizeof(cmdBuffer)-1; i++)
    cmdBuffer[i] = cmdBuffer[i+1];

  nCrtBufIndex--;
}

ghostwubble:
Could you please give me some example code as to how the Arduino interprets the ascii strings?

Have a look at serial input basics. It includes a parse example.

If you can choose the data format I would recommend using a system similar to the third example with start- and end-markers.

...R