{"id":13801981,"url":"https://github.com/wieck/micropython-ntpclient","last_synced_at":"2025-10-08T17:30:32.349Z","repository":{"id":140337714,"uuid":"230043601","full_name":"wieck/micropython-ntpclient","owner":"wieck","description":"NTP client for micropython using uasyncio","archived":false,"fork":false,"pushed_at":"2021-07-11T21:19:53.000Z","size":32,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-22T12:33:23.623Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wieck.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-12-25T04:54:15.000Z","updated_at":"2024-08-04T00:06:48.928Z","dependencies_parsed_at":"2023-04-11T09:02:30.018Z","dependency_job_id":null,"html_url":"https://github.com/wieck/micropython-ntpclient","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wieck%2Fmicropython-ntpclient","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wieck%2Fmicropython-ntpclient/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wieck%2Fmicropython-ntpclient/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wieck%2Fmicropython-ntpclient/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wieck","download_url":"https://codeload.github.com/wieck/micropython-ntpclient/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235734333,"owners_count":19037059,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-04T00:01:32.198Z","updated_at":"2025-10-08T17:30:27.067Z","avatar_url":"https://github.com/wieck.png","language":"Python","readme":"micropython-ntpclient\n=====================\n\nA uasyncio based NTP client for ESP32 boards running micropython.\n\n**At this moment this code only works on boards with a custom build\nmicropython firmware.**\n\nPlease go to https://forum.micropython.org/viewtopic.php?f=15\u0026t=7567\nfor discussion and questions. \n\n**The following commit was never accepted by the upstream project.\nIn order to make the utime.adjtime() function available please apply the\nincluded patch _esp32_adjtime.diff_ and build a custom micropython image.**\n\n~~Required commit to be cherry-picked for ESP32: \nhttps://github.com/wieck/micropython/commit/cd80a9aba99a68af7e295067fa7d35383ccef640~~\n\n\nInstallation and testing\n------------------------\n\nThe ntpclient module requires the above commit(s) to be cherry-picked\ninto a custom build of micropython. For the ESP32 it adds the utime.adjtime()\nfunction that uses the adjtime(3) function of the ESP32 SDK.\n\nOnce your board is flashed with that custom build, upload the\nntpclient directory and ntpclient_test[12].py scripts. You also need to upload\na ```boot.py``` that enables WiFi and connects to your WLAN.\n\nThen use a REPL prompt and\n```\nimport ntpclient_test1\nntpclient_test1.run(pps = 17, host = 'my.local.ntp.host.addr', debug=True)\n```\n\nReplace \"my.local.ntp.host.addr\" with your local NTP server. If you don't have\none, you can omit the whole \"host=\" kwarg and it will default to\n\"pool.ntp.org\". But be warned, those have unpredictably asynchronous\ndelays in packet travel.\n\nThe above will run a uasyncio task that prints the current time every\nsecond as well as producing a 100ms pulse on the specified \"pps\" pin.\nThe ntpclient will be running in the background, constantly adjusting\nthe boards RTC.\n\nPlease note that attempting to slew a RTC while using deep sleep is\nnot going to work. The ntpclient needs to adjust or calibrate the RTC\nevery 2 seconds in order to be considered \"in sync\".\n\nIf you have an SSD1306 OLED display you can also use ntpclient_test2.\n```\nimport ntpclient_test2\nntpclient_test2.run(pps = 17, host = 'my.local.ntp.host.addr', scl = 22, sda = 21, debug=True)\n```\n\nCongratulations, you now have an NTP based clock that displays UTC.\n\nSyntax\n------\n\n```\nntpclient.ntpclient(**kwargs)\n\nkwargs:\n  \n  host=HOSTNAME     Hostname of the NTP server to use (default pool.ntp.org).\n\n  poll=SECONDS      Maximum poll interval (default 1024). ntpclient will\n                    dynamically increase/decrease the polling interval based\n                    on current instability between 64 and this maximum\n                    number of seconds.\n  \n  max_startup_delta=SECONDS\n                    Number of seconds of clock difference at which\n                    ntpclient will perform a hard set of the clock on\n                    startup instead of slewing the clock (default 1).\n\n  debug=BOOL        Flag to make ntpclient emit debug messages on stdout\n                    for diagnostics.\n```\n\nExample\n-------\n```\ninclude ntpclient\nntpclient.ntpclient(host = 'ntpserver.localdomain')\n```\n\nSaving Drift information\n------------------------\n\nOn the ESP32 port an optional keyword argument to the ntpclient instance is\nthe path for a \"drift_file\". In this file ntpclient will periodically\nsave drift information to speed up synchronization on subsequent\nreboots.\n\n\nImplementation Notes\n--------------------\n\n* On the ESP32 the RTC is running on the main XTAL while under full power.\n  The algorithm tries to calculate the current \"drift\" of that oscillator.\n  From this drift, measured in microseconds per adjustment interval, it\n  calculates a number of microseconds by which to \"slew\" the RTC every\n  two seconds using the new adjtime() function. This is basically a\n  simplified version of what ntpd does on a Unix system.\n","funding_links":[],"categories":["Libraries"],"sub_categories":["Communications"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwieck%2Fmicropython-ntpclient","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwieck%2Fmicropython-ntpclient","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwieck%2Fmicropython-ntpclient/lists"}