user48730: I'm writing a sketch in order to upload to a Sonoff device ( Remote relay, based ESP8266 ).
All is working great, but I wish my MQTT pubs to contain following format:
[ DATE & TIME ] msg
ESP8266 is connected to the internet.
I;m looking for a way doing it (including periodic time updates ) without running all 1MB memory, meaning: a code that 
1) get time from external source (LAN or WAN )
2) update it every 24h
3) Lite code ?
Thanks

user4143: Start with the ESP8266WiFi "NTPClient" example.  That will teach you how you can get the "Unix Epoch" time from the internet.
That value can be fed directly into TimeLib to keep track of the time for you (indeed, TimeLib includes an NTP example for Arduino Ethernet that should help you get started).  Do that periodically (daily, hourly, whatever), and you have your time.  TimeLib can then give you the date and time as individual components (hours, minutes, etc), which you can then construct together (I'd use snprintf) to include in your MQTT message:
int len = strlen(message) + 25;
char mqttMessage[len];
snprintf(mqttMessage, len, "[%04d/%02d/%02d %02d:%02d:%02d] %s",
    year(), month(), day(), hour(), minute(), second(), message);

mqttMessage => "[2018/08/11 20:36:24] foo"


48730: <p>I'm writing a sketch in order to upload to a Sonoff device ( Remote relay, based ESP8266 ).</p>

<p>All is working great, but I wish my MQTT pubs to contain following format:</p>

<p><code>[ DATE &amp; TIME ] msg</code></p>

<p>ESP8266 is connected to the internet.
I;m looking for a way doing it (including periodic time updates ) without running all 1MB memory, meaning: a code that 
1) get time from external source (LAN or WAN )
2) update it every 24h
3) Lite code ?</p>

<p>Thanks</p>
 4143: <p>Start with the ESP8266WiFi "<a href="https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266WiFi/examples/NTPClient/NTPClient.ino" rel="nofollow noreferrer">NTPClient</a>" example.  That will teach you how you can get the "Unix Epoch" time from the internet.</p>

<p>That value can be fed directly into <a href="https://github.com/PaulStoffregen/Time" rel="nofollow noreferrer">TimeLib</a> to keep track of the time for you (indeed, TimeLib includes an <a href="https://github.com/PaulStoffregen/Time/blob/master/examples/TimeNTP/TimeNTP.ino" rel="nofollow noreferrer">NTP example for Arduino Ethernet</a> that should help you get started).  Do that periodically (daily, hourly, whatever), and you have your time.  TimeLib can then give you the date and time as individual components (hours, minutes, etc), which you can then construct together (I'd use <code>snprintf</code>) to include in your MQTT message:</p>

<pre><code>int len = strlen(message) + 25;
char mqttMessage[len];
snprintf(mqttMessage, len, "[%04d/%02d/%02d %02d:%02d:%02d] %s",
    year(), month(), day(), hour(), minute(), second(), message);

mqttMessage =&gt; "[2018/08/11 20:36:24] foo"
</code></pre>
