Current time in a specific timezone

#1

If you are asking a question, please follow this template:

  1. My goal is: to fetch current time and run a job on a specific time.
  2. My actions are: I have included SNTP library in mos.yml and invoked Timer.now() function to fetch current time
  3. The result I see is: I see the time shown is the time elapsed since ESP8266 has started
  4. My expectation & question is: I am expecting to get the current time in my timezone so that I can use crontabs to schedule the job. How can I get current time in India timezone?
#2

In order to synchronize the time using sntp, your device must have internet connection.

To get the local time you have to add sys.tz_spec in your mos.yml
Ref. https://github.com/mongoose-os-libs/core/blob/74a909e5078c911dc6f0d665ddbdac2540b5ce6b/mos.yml#L41-L48

A simpler way to do this is provided by @mamuesp’s timezones library.

#3

@nliviu, thanks a lot. I had set wifi credentials using mos command line tool. I was not aware that if you flash the app again, then configuration needs to be set once again. I was able to solve this problem by setting wifi credentials and SNTP timezone information in mos.yml. Thanks a lot for your help.

1 Like
#4

After flashing the firmware the first time, you can OTA update it and conf9.json (ie. the device configuration changed with mos --port <your_port> config-set, mos wifi) will be preserved between updates.