Format Time in HH:MM from milliseconds from Android App

Hello I'd like to how to proceed to make a clock itself on Arduino Micro. The clock start time will be given by Android App in millscnd.

I have one micro pro with Oled Display and bluetooth, I need make the clock run itself, and when I not have data in bluetooth serial I'll display in OLED.

Thanks

       //Android APp
       Calendar c = Calendar.getInstance();
        
        String mils= ": "+c.get(Calendar.MILLISECOND);
        if (btSocket!=null)
        {
            try
            {

                btSocket.getOutputStream().write(mils.toString().getBytes());
            }
            catch (IOException e)
            {
                msg("Error");
            }

        }
 if(BTserial.available() >0)
 {
     data = BTserial.readString();
    if(data.charAt(':')
         initClock(data);
}

Show us what you have so far :slight_smile:

From terminal I´m getting that, I'll remake my java code

8:46:36.554 -> Incoming_value
18:46:36.554 -> 
18:46:36.554 -> +DISC:SUCCESS
18:46:36.601 -> OK
18:46:36.601 -> 
18:46:46.405 -> Incoming_value
18:46:46.452 -> 
18:46:46.452 -> Conectado: 866
18:48:09.994 -> Incoming_value
18:48:09.994 -> 
18:48:09.994 -> +DISC:SUCCESS
18:48:10.041 -> OK
18:48:10.041 -> 
18:48:20.464 -> Incoming_value
18:48:20.511 -> 
18:48:20.511 -> Conectado
18:48:24.324 -> Incoming_value
18:48:24.324 -> 
18:48:24.371 -> : 833

After modifier I have : 1569794158119, but I´m how I can build this thread in Arduino.

Thanks

After modifier I have : 1569794158119, but I´m how I can build this thread in Arduino.

This looks like a standard unix time stamp with milliseconds. Is it a local time, or GMT? Once your receive the transmission on the Arduino it is going to be simple to convert the character string time stamp to an unsigned long number and convert that to HH:MM:SS. The Time Library may prove useful.

First, I would suggest that you read Robin2's excellent tutorial on Serial Input Basics.

It looks like you have a unique start marker ':'
Is the transmitted millisecond string terminated with a new line or carriage return?

The Arduino micro has a hardware Serial1 separate from the usb serial. You can use this for the bluetooth connections.

Do to limited memory, you should avoid use of String objects( with capital S) and use c-style strings (small s) which are null terminated character arrays. See The Evils of Arduino Strings | Majenko's Hardware Hacking Blog

lakesidepark22:
After modifier I have : 1569794158119, but I´m how I can build this thread in Arduino.

That looks like a UNIX time stamp indeed.
Ignore the last three characters (or send timestamp in seconds); convert the resulting string into a 32-bit unsigned int, and then use that to set your local time using the Time library and retrieve hours/minutes/seconds using the built-in formulas:

timeSet(timestamp);
hh = hours();
mm = minutes();
ss = seconds();

You may have to add your timezone offset to the timestamp, depending on whether you get local time or UTC from your Android.