質問編集履歴

1

全ソース 掲載しました

2020/07/12 09:44

投稿

runa
runa

スコア38

test CHANGED
File without changes
test CHANGED
@@ -16,29 +16,107 @@
16
16
 
17
17
 
18
18
 
19
- ```
19
+ ```全ソース
20
20
 
21
- 前略
21
+ #include <M5Stack.h>
22
22
 
23
- WiFi.config(staticIP, DNS, gateway, subnet);
23
+ #include <WiFi.h>
24
24
 
25
- ----
26
-
27
- WiFi.begin(ssid, password);
25
+ #include <time.h>
28
-
29
- ----
30
-
31
- configTime(gmtOffset_sec, daylightOffset_sec, "210.173.162.106");
32
-
33
- // ntp.nttsl.mfeed.ne.jp
34
26
 
35
27
 
36
28
 
37
- if (!getLocalTime(&timeinfo)) {
29
+ //<For WiFi>=================================
38
30
 
39
- Serial.println("Err getLocalTime()");
31
+ const char* ssid = "test"; // ここを書き換える
40
32
 
33
+ const char* password = "12345678"; // ここを書き換える
34
+
35
+ //===========================================
36
+
37
+
38
+
39
+ IPAddress staticIP(192, 168, 0, 40);
40
+
41
+ IPAddress subnet(255, 255, 255, 0);
42
+
43
+ IPAddress gateway(192, 168, 0, 254);
44
+
45
+ IPAddress DNS(192, 168, 0, 254); //optional
46
+
47
+
48
+
49
+ // for NTPサーバー ------------------------
50
+
51
+ struct tm timeInfo;
52
+
53
+ //===================================
54
+
55
+
56
+
57
+ void setup() {
58
+
59
+ Serial.begin(115200);
60
+
61
+
62
+
63
+ M5.begin(true, false, true); //M5.begin(bool LCDEnable=true, bool SDEnable=true, bool SerialEnable=true)
64
+
65
+
66
+
67
+ Serial.println("M5 Starting....");
68
+
69
+
70
+
71
+ WiFi.mode(WIFI_STA);
72
+
73
+ WiFi.disconnect(true, true);
74
+
75
+
76
+
77
+ WiFi.config(staticIP, DNS, gateway, subnet); // これを有効にすると NG
78
+
79
+ WiFi.begin(ssid, password);
80
+
81
+
82
+
83
+ while (WiFi.status() != WL_CONNECTED) {
84
+
85
+ delay(500);
86
+
87
+ M5.Lcd.print(".");
88
+
89
+ }
90
+
91
+
92
+
93
+ configTime(9 * 3600, 0, "ntp1.jst.mfeed.ad.jp"); // NG
94
+
95
+ // configTime(9 * 3600, 0, "210.173.160.27"); // OK
96
+
97
+
98
+
99
+ if (getLocalTime(&timeInfo, 10000) == false ) {
100
+
101
+ Serial.print("Err getLocalTime()");
102
+
41
- while(1);
103
+ while (true) {}
104
+
105
+ }
106
+
107
+ Serial.println("OK getLocalTime()");
108
+
109
+
110
+
111
+ while (true) {}
112
+
113
+ }
114
+
115
+
116
+
117
+ void loop() {
118
+
119
+ ;
42
120
 
43
121
  }
44
122