{"id":333,"date":"2021-02-23T09:48:41","date_gmt":"2021-02-23T00:48:41","guid":{"rendered":"https:\/\/sakae-shokai.com\/?p=333"},"modified":"2021-02-23T09:48:41","modified_gmt":"2021-02-23T00:48:41","slug":"esp32-%e6%99%82%e8%a8%88%e3%81%be%e3%82%8f%e3%82%8a","status":"publish","type":"post","link":"https:\/\/sakae-shokai.com\/wordpress\/?p=333","title":{"rendered":"ESP32 \u6642\u8a08\u307e\u308f\u308a"},"content":{"rendered":"\n<p>ESP32\u3092Wi-Fi\u306b\u3066\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u306b\u3064\u306a\u304e\u307e\u3057\u305f\u306e\u3067\u3001\u6b21\u306f\u6642\u8a08\u307e\u308f\u308a\u3092\u6574\u5099\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>ESP32\u306b\u306f\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u30af\u30ed\u30c3\u30af\uff08\uff32\uff34\uff23\uff09\u304c\u5b9f\u88c5\u3055\u308c\u3066\u3044\u307e\u3059\u306e\u3067\u3001\u307e\u305a\u306f\u3069\u306e\u3088\u3046\u306a\u53cd\u5fdc\u304c\u51fa\u308b\u304b\u898b\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>>>> from machine import RTC\r\n>>> rtc=RTC()\r\n>>> rtc.datetime()\r\n(2000, 1, 1, 5, 0, 2, 41, 237515)<\/code><\/pre>\n\n\n\n<p>2000\u5e741\u67081\u65e5\u3067\u3059\u306d\u3002\u3053\u308c\u3067\u306f\u6642\u8a08\u3068\u3057\u3066\u4f7f\u3048\u307e\u305b\u3093\u306e\u3067\u3001NTP\u30b5\u30fc\u30d0\u30fc\u306b\u63a5\u7d9a\u3057\u3066\u73fe\u5728\u6642\u523b\uff08UTC)\u306b\u5408\u308f\u305b\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>>>> import ntptime\r\n>>> ntptime.settime()\r\n>>> rtc.datetime()\r\n(2021, 2, 22, 0, 22, 6, 52, 654317)<\/code><\/pre>\n\n\n\n<p>2021\u5e742\u670822\u65e522\u66426\u520652\u79d2\u3067\u3059\u304b\u30014\u500b\u76ee\u306e\uff10\u306f\u591a\u5206\u66dc\u65e5\u3092\u8868\u3057\u3066\u304a\u308a\u6708\u66dc\u65e5\u3001654317\u306f\u30fb\u30fb\u30fb<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>>>> import utime\r\n>>> utime.localtime()\r\n(2021, 2, 22, 22, 16, 34, 0, 53)<\/code><\/pre>\n\n\n\n<p>utime\u3067\u30ed\u30fc\u30ab\u30eb\u30bf\u30a4\u30e0\u8868\u793a\u3067\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<p>2021\u5e742\u670822\u65e522\u664216\u520634\u79d2\u6708\u66dc\u65e5\u3001\u5e74\u5185\u306e\u901a\u7b97\u65e5\u657053\u65e5\u76ee\uff08\uff13\uff11\uff0b\uff12\uff12\uff1d\uff15\uff13\uff09\u3053\u308c\u306f\uff35\uff34\uff23\u3067\u3059\u306e\u3067\u3001\uff2a\uff33\uff34\u306b\u5408\u308f\u305b\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>>>> utime.mktime(utime.localtime())\r\n667355194\r\n>>> utime.mktime(utime.localtime())+(9*3600)\r\n667387595\r\n>>> utime.localtime(utime.mktime(utime.localtime())+(9*3600))\r\n(2021, 2, 23, 9, 26, 38, 1, 54)\n<\/code><\/pre>\n\n\n\n<p>9\u6642\u9593\u9032\u3081\u307e\u3059utime.mktime()\u95a2\u6570\u3067\u30ed\u30fc\u30ab\u30eb\u30bf\u30a4\u30e0\u3092\u79d2\u6570\u306e\u6574\u6570\u306b\u623b\u3057\u307e\u3059\u3002\u3053\u306e\u6574\u6570\u306bJST\u306f9\u6642\u9593\u9032\u3093\u3067\u3044\u307e\u3059\u306e\u30679\u6642\u9593\u00d73600\u79d2\u3092\u8db3\u3057\u3066\u3042\u3052\u307e\u3059\u3002\u3053\u306e\u6574\u6570\u3092utime.localtime()\u95a2\u6570\u3067\u6642\u9593\u306b\u623b\u3057\u307e\u3059\u3002\u3059\u308b\u30682021\u5e742\u670823\u65e59\u664226\u520638\u79d2\u706b\u66dc\u65e554\u65e5\u7d4c\u904e\u3068\u65e5\u672c\u6642\u9593\u306b\u5909\u66f4\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p>\u5168\u4f53\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3067\u3059<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><\/div>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \" title=\"timetest.py\" >from time import sleep_ms\nimport ntptime\nimport utime\n\nUTC_OFFSET=9\n\n\ndef do_connect():\n    import network\n    wlan = network.WLAN(network.STA_IF)\n    wlan.active(True)\n    if not wlan.isconnected():\n        print('connecting to network...')\n        wlan.connect('essid', 'password')\n        while not wlan.isconnected():\n            pass\n    print('network config:', wlan.ifconfig())\n\n     \ndef get_jst():\n    sleep_ms(1000)\n    ntptime.settime()\n    tm=utime.localtime(utime.mktime(utime.localtime())+UTC_OFFSET*3600)\n    jst = str(tm[0])+'\/'+str(tm[1])+'\/'+str(tm[2])+' '+str(tm[3])+':'+str(tm[4])+':'+str(tm[5])\n    return(jst)\n     \n  \ndo_connect()\nprint(get_jst())<\/pre><\/div>\n\n\n\n<p>\u5b9f\u884c\u7d4c\u904e\u3067\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>C:\\Users\\>ampy -p com4 run c:\\micropython\\timetest1.py\r\nnetwork config: ('192.168.11.25', '255.255.255.0', '192.168.11.1', '192.168.11.1')\r\n2021\/2\/23 9:39:41<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>ESP32\u3092Wi-Fi\u306b\u3066\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u306b\u3064\u306a\u304e\u307e\u3057\u305f\u306e\u3067\u3001\u6b21\u306f\u6642\u8a08\u307e\u308f\u308a\u3092\u6574\u5099\u3057\u307e\u3059\u3002 ESP32\u306b\u306f\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u30af\u30ed\u30c3\u30af\uff08\uff32\uff34\uff23\uff09\u304c\u5b9f\u88c5\u3055\u308c\u3066\u3044\u307e\u3059\u306e\u3067\u3001\u307e\u305a\u306f\u3069\u306e\u3088\u3046\u306a\u53cd\u5fdc\u304c\u51fa\u308b\u304b\u898b\u307e\u3059\u3002 2000\u5e741\u67081\u65e5\u3067\u3059\u306d\u3002 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/sakae-shokai.com\/wordpress\/?p=333\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;ESP32 \u6642\u8a08\u307e\u308f\u308a&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":234,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17,16],"tags":[18,19,38,37],"class_list":["post-333","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-esp32","category-micropython","tag-esp32","tag-micropython","tag-ntptime","tag-rtc"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/sakae-shokai.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/333","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sakae-shokai.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sakae-shokai.com\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sakae-shokai.com\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sakae-shokai.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=333"}],"version-history":[{"count":5,"href":"https:\/\/sakae-shokai.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/333\/revisions"}],"predecessor-version":[{"id":338,"href":"https:\/\/sakae-shokai.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/333\/revisions\/338"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sakae-shokai.com\/wordpress\/index.php?rest_route=\/wp\/v2\/media\/234"}],"wp:attachment":[{"href":"https:\/\/sakae-shokai.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=333"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sakae-shokai.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=333"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sakae-shokai.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=333"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}