質問編集履歴

2

情報の修正

2021/08/27 12:16

投稿

aRyo
aRyo

score23

test CHANGED
File without changes
test CHANGED
@@ -336,9 +336,9 @@
336
336
 
337
337
 
338
338
 
339
-
339
+  wifi_conect();
340
-
340
+
341
- delay(30000); //10秒毎に書き込みする
341
+ delay(30000); //30秒毎に書き込みする
342
342
 
343
343
  g_acsess();
344
344
 

1

情報の追加

2021/08/27 12:16

投稿

aRyo
aRyo

score23

test CHANGED
File without changes
test CHANGED
@@ -61,3 +61,451 @@
61
61
  データを送らずデプロイすると日付だけ入力されるはずですが、どこが誤っていますでしょうか。
62
62
 
63
63
  ご教授ください。よろしくお願いいたします。
64
+
65
+
66
+
67
+
68
+
69
+ *****追記*****
70
+
71
+
72
+
73
+ Arduinoに実際に書き込みしたコードが以下になります。
74
+
75
+ これを実行するとGoogleスプレッドシートに記録が始まると思ったのですが何も反応がありません。
76
+
77
+ 事前にGoogleスプレッドシートでシートを作成しておく必要があるのでしょうか。
78
+
79
+ よろしくお願いいたします。
80
+
81
+ ```ここに言語を入力
82
+
83
+ /*
84
+
85
+ BME280I2C Modes.ino
86
+
87
+
88
+
89
+ This code shows how to use predefined recommended settings from Bosch for
90
+
91
+ the BME280I2C environmental sensor.
92
+
93
+
94
+
95
+ GNU General Public License
96
+
97
+
98
+
99
+ Written: Dec 30 2015.
100
+
101
+ Last Updated: Sep 23 2017.
102
+
103
+
104
+
105
+ Connecting the BME280 Sensor:
106
+
107
+ Sensor -> Board
108
+
109
+ -----------------------------
110
+
111
+ Vin (Voltage In) -> 3.3V
112
+
113
+ Gnd (Ground) -> Gnd
114
+
115
+ SDA (Serial Data) -> A4 on Uno/Pro-Mini, 20 on Mega2560/Due, 2 Leonardo/Pro-Micro
116
+
117
+ SCK (Serial Clock) -> A5 on Uno/Pro-Mini, 21 on Mega2560/Due, 3 Leonardo/Pro-Micro
118
+
119
+
120
+
121
+ */
122
+
123
+
124
+
125
+ #include <BME280I2C.h>
126
+
127
+ #include <Wire.h> // Needed for legacy versions of Arduino.
128
+
129
+ #include <WiFiClientSecure.h>
130
+
131
+ #include <Adafruit_Sensor.h>
132
+
133
+ #include <Adafruit_BME280.h>
134
+
135
+
136
+
137
+ #define SERIAL_BAUD 115200
138
+
139
+
140
+
141
+ const char* ssid = "********";
142
+
143
+ const char* password = "********";
144
+
145
+
146
+
147
+
148
+
149
+ const char* server = "script.google.com";
150
+
151
+ const char* key = "********"; // google script key
152
+
153
+ WiFiClientSecure client;
154
+
155
+
156
+
157
+ float temp(NAN), hum(NAN), pres(NAN);
158
+
159
+
160
+
161
+ /* Recommended Modes -
162
+
163
+ Based on Bosch BME280I2C environmental sensor data sheet.
164
+
165
+
166
+
167
+ Weather Monitoring :
168
+
169
+ forced mode, 1 sample/minute
170
+
171
+ pressure ×1, temperature ×1, humidity ×1, filter off
172
+
173
+ Current Consumption = 0.16 μA
174
+
175
+ RMS Noise = 3.3 Pa/30 cm, 0.07 %RH
176
+
177
+ Data Output Rate 1/60 Hz
178
+
179
+
180
+
181
+ Humidity Sensing :
182
+
183
+ forced mode, 1 sample/second
184
+
185
+ pressure ×0, temperature ×1, humidity ×1, filter off
186
+
187
+ Current Consumption = 2.9 μA
188
+
189
+ RMS Noise = 0.07 %RH
190
+
191
+ Data Output Rate = 1 Hz
192
+
193
+
194
+
195
+ Indoor Navigation :
196
+
197
+ normal mode, standby time = 0.5ms
198
+
199
+ pressure ×16, temperature ×2, humidity ×1, filter = x16
200
+
201
+ Current Consumption = 633 μA
202
+
203
+ RMS Noise = 0.2 Pa/1.7 cm
204
+
205
+ Data Output Rate = 25Hz
206
+
207
+ Filter Bandwidth = 0.53 Hz
208
+
209
+ Response Time (75%) = 0.9 s
210
+
211
+
212
+
213
+
214
+
215
+ Gaming :
216
+
217
+ normal mode, standby time = 0.5ms
218
+
219
+ pressure ×4, temperature ×1, humidity ×0, filter = x16
220
+
221
+ Current Consumption = 581 μA
222
+
223
+ RMS Noise = 0.3 Pa/2.5 cm
224
+
225
+ Data Output Rate = 83 Hz
226
+
227
+ Filter Bandwidth = 1.75 Hz
228
+
229
+ Response Time (75%) = 0.3 s
230
+
231
+
232
+
233
+ */
234
+
235
+
236
+
237
+ BME280I2C::Settings settings(
238
+
239
+ BME280::OSR_X1,
240
+
241
+ BME280::OSR_X1,
242
+
243
+ BME280::OSR_X1,
244
+
245
+ BME280::Mode_Forced,
246
+
247
+ BME280::StandbyTime_1000ms,
248
+
249
+ BME280::Filter_Off,
250
+
251
+ BME280::SpiEnable_False,
252
+
253
+ BME280I2C::I2CAddr_0x76 // I2C address. I2C specific.
254
+
255
+ );
256
+
257
+
258
+
259
+ BME280I2C bme(settings);
260
+
261
+
262
+
263
+ //////////////////////////////////////////////////////////////////
264
+
265
+ void setup()
266
+
267
+ {
268
+
269
+ Serial.begin(SERIAL_BAUD);
270
+
271
+
272
+
273
+ while(!Serial) {} // Wait
274
+
275
+
276
+
277
+ Wire.begin();
278
+
279
+ while(!bme.begin())
280
+
281
+ {
282
+
283
+ Serial.println("Could not find BME280I2C sensor!");
284
+
285
+ delay(1000);
286
+
287
+ }
288
+
289
+
290
+
291
+ switch(bme.chipModel())
292
+
293
+ {
294
+
295
+ case BME280::ChipModel_BME280:
296
+
297
+ Serial.println("Found BME280 sensor! Success.");
298
+
299
+ break;
300
+
301
+ case BME280::ChipModel_BMP280:
302
+
303
+ Serial.println("Found BMP280 sensor! No Humidity available.");
304
+
305
+ break;
306
+
307
+ default:
308
+
309
+ Serial.println("Found UNKNOWN sensor! Error!");
310
+
311
+ }
312
+
313
+
314
+
315
+ // Change some settings before using.
316
+
317
+ settings.tempOSR = BME280::OSR_X4;
318
+
319
+
320
+
321
+ bme.setSettings(settings);
322
+
323
+ }
324
+
325
+
326
+
327
+ //////////////////////////////////////////////////////////////////
328
+
329
+ void loop()
330
+
331
+ {
332
+
333
+ printBME280Data(&Serial);
334
+
335
+ delay(60000);
336
+
337
+
338
+
339
+
340
+
341
+ delay(30000); //10秒毎に書き込みする
342
+
343
+ g_acsess();
344
+
345
+
346
+
347
+
348
+
349
+
350
+
351
+
352
+
353
+ }
354
+
355
+
356
+
357
+ //////////////////////////////////////////////////////////////////
358
+
359
+ void printBME280Data
360
+
361
+ (
362
+
363
+ Stream* client
364
+
365
+ )
366
+
367
+ {
368
+
369
+
370
+
371
+
372
+
373
+ BME280::TempUnit tempUnit(BME280::TempUnit_Celsius);
374
+
375
+ BME280::PresUnit presUnit(BME280::PresUnit_Pa);
376
+
377
+
378
+
379
+ bme.read(pres, temp, hum, tempUnit, presUnit);
380
+
381
+
382
+
383
+ client->print("Temp: ");
384
+
385
+ client->print(temp);
386
+
387
+ client->print("°"+ String(tempUnit == BME280::TempUnit_Celsius ? 'C' :'F'));
388
+
389
+ client->print("\t\tHumidity: ");
390
+
391
+ client->print(hum);
392
+
393
+ client->print("% RH");
394
+
395
+ client->print("\t\tPressure: ");
396
+
397
+ client->print(pres);
398
+
399
+ client->println("Pa");
400
+
401
+
402
+
403
+
404
+
405
+
406
+
407
+ delay(1000);
408
+
409
+ }
410
+
411
+
412
+
413
+
414
+
415
+
416
+
417
+
418
+
419
+ void wifi_conect(){
420
+
421
+
422
+
423
+ WiFiServer server(80);
424
+
425
+ // Wi-Fiに接続
426
+
427
+ Serial.print("Attempting to connect to SSID: ");
428
+
429
+ Serial.println(ssid);
430
+
431
+ WiFi.begin(ssid, password);
432
+
433
+ while (WiFi.status() != WL_CONNECTED) {
434
+
435
+ Serial.print(".");
436
+
437
+ // 接続するまで待機する
438
+
439
+ delay(1000);
440
+
441
+ }
442
+
443
+ Serial.print("Connected to ");
444
+
445
+ Serial.println(ssid);
446
+
447
+ Serial.println("IP address: ");
448
+
449
+ Serial.println(WiFi.localIP());
450
+
451
+ server.begin();
452
+
453
+ }
454
+
455
+
456
+
457
+
458
+
459
+
460
+
461
+ void g_acsess(){
462
+
463
+
464
+
465
+
466
+
467
+ String URL="https://script.google.com/macros/s/";
468
+
469
+ URL += key;
470
+
471
+ URL += "/exec?";
472
+
473
+ URL += "&1_cell=";
474
+
475
+ URL += temp ;
476
+
477
+ URL += "&2_cell=";
478
+
479
+ URL += hum ;
480
+
481
+ URL += "&3_cell=";
482
+
483
+ URL += pres ;
484
+
485
+
486
+
487
+ Serial.println(URL);
488
+
489
+ // サイトにアクセス
490
+
491
+ Serial.println("\nStarting connection to server...");
492
+
493
+ if (!client.connect(server, 443))
494
+
495
+ Serial.println("Connection failed!");
496
+
497
+ else {
498
+
499
+ Serial.println("Connected to server!\n");
500
+
501
+ client.println("GET " + URL);
502
+
503
+ client.stop();
504
+
505
+ Serial.println("finish.");
506
+
507
+ }
508
+
509
+ }
510
+
511
+ ```