If you want to use sntp library to set the local time, you also need to set sys.tz_spec in mos.yml.
To synchronize the DS3231, you need to process the event MGOS_EVENT_TIME_CHANGED and set DS3231’s time in the event callback.
Regarding the square wave generation, have a look here