質問編集履歴

3

ソースコードの追加

2021/08/21 04:43

投稿

aRyo
aRyo

スコア23

test CHANGED
File without changes
test CHANGED
@@ -318,7 +318,7 @@
318
318
 
319
319
 
320
320
 
321
- double temp = temp, press = press, hum = hum;
321
+ double temp = temp, press = press, hum = hum;              //ここのやり方間違ってるのかな
322
322
 
323
323
  signed long int temp_cal;
324
324
 
@@ -440,19 +440,19 @@
440
440
 
441
441
  client->print("Temp: ");
442
442
 
443
- client->print(temp);
443
+ client->print(temp);        //これと
444
444
 
445
445
  client->print("°"+ String(tempUnit == BME280::TempUnit_Celsius ? 'C' :'F'));
446
446
 
447
447
  client->print("\t\tHumidity: ");
448
448
 
449
- client->print(hum);
449
+ client->print(hum);                              //これと
450
450
 
451
451
  client->print("% RH");
452
452
 
453
453
  client->print("\t\tPressure: ");
454
454
 
455
- client->print(pres);
455
+ client->print(pres);                             //これの値を変数に格納したい
456
456
 
457
457
  client->println("Pa");
458
458
 

2

ソースコードの貼り付け場所の修正

2021/08/21 04:43

投稿

aRyo
aRyo

スコア23

test CHANGED
File without changes
test CHANGED
@@ -18,464 +18,456 @@
18
18
 
19
19
  正直、自分で何かを作るのは初めてのことで以下のプログラムも殆どブログなどから引用してつぎはぎで貼り付けたものになり、凄く見にくいかもしれません。
20
20
 
21
+
22
+
23
+ ```ここに言語を入力
24
+
25
+ /*
26
+
27
+ BME280I2C Modes.ino
28
+
29
+
30
+
31
+ This code shows how to use predefined recommended settings from Bosch for
32
+
33
+ the BME280I2C environmental sensor.
34
+
35
+
36
+
37
+ GNU General Public License
38
+
39
+
40
+
41
+ Written: Dec 30 2015.
42
+
43
+ Last Updated: Sep 23 2017.
44
+
45
+
46
+
47
+ Connecting the BME280 Sensor:
48
+
49
+ Sensor -> Board
50
+
51
+ -----------------------------
52
+
53
+ Vin (Voltage In) -> 3.3V
54
+
55
+ Gnd (Ground) -> Gnd
56
+
57
+ SDA (Serial Data) -> A4 on Uno/Pro-Mini, 20 on Mega2560/Due, 2 Leonardo/Pro-Micro
58
+
59
+ SCK (Serial Clock) -> A5 on Uno/Pro-Mini, 21 on Mega2560/Due, 3 Leonardo/Pro-Micro
60
+
61
+
62
+
63
+ */
64
+
65
+
66
+
67
+ #include <BME280I2C.h>
68
+
69
+ #include <Wire.h> // Needed for legacy versions of Arduino.
70
+
71
+ #include <WiFiClientSecure.h>
72
+
73
+ #include <Adafruit_Sensor.h>
74
+
75
+ #include <Adafruit_BME280.h>
76
+
77
+
78
+
79
+ #define SERIAL_BAUD 115200
80
+
81
+
82
+
83
+ const char* ssid = "*******";
84
+
85
+ const char* password = "*******";
86
+
87
+
88
+
89
+ const char* host = "maker.ifttt.com";
90
+
91
+ const char* event = "*******";
92
+
93
+ const char* secretkey = "*******";
94
+
95
+
96
+
97
+ float temp(NAN), hum(NAN), pres(NAN);
98
+
99
+
100
+
101
+ /* Recommended Modes -
102
+
103
+ Based on Bosch BME280I2C environmental sensor data sheet.
104
+
105
+
106
+
107
+ Weather Monitoring :
108
+
109
+ forced mode, 1 sample/minute
110
+
111
+ pressure ×1, temperature ×1, humidity ×1, filter off
112
+
113
+ Current Consumption = 0.16 μA
114
+
115
+ RMS Noise = 3.3 Pa/30 cm, 0.07 %RH
116
+
117
+ Data Output Rate 1/60 Hz
118
+
119
+
120
+
121
+ Humidity Sensing :
122
+
123
+ forced mode, 1 sample/second
124
+
125
+ pressure ×0, temperature ×1, humidity ×1, filter off
126
+
127
+ Current Consumption = 2.9 μA
128
+
129
+ RMS Noise = 0.07 %RH
130
+
131
+ Data Output Rate = 1 Hz
132
+
133
+
134
+
135
+ Indoor Navigation :
136
+
137
+ normal mode, standby time = 0.5ms
138
+
139
+ pressure ×16, temperature ×2, humidity ×1, filter = x16
140
+
141
+ Current Consumption = 633 μA
142
+
143
+ RMS Noise = 0.2 Pa/1.7 cm
144
+
145
+ Data Output Rate = 25Hz
146
+
147
+ Filter Bandwidth = 0.53 Hz
148
+
149
+ Response Time (75%) = 0.9 s
150
+
151
+
152
+
153
+
154
+
155
+ Gaming :
156
+
157
+ normal mode, standby time = 0.5ms
158
+
159
+ pressure ×4, temperature ×1, humidity ×0, filter = x16
160
+
161
+ Current Consumption = 581 μA
162
+
163
+ RMS Noise = 0.3 Pa/2.5 cm
164
+
165
+ Data Output Rate = 83 Hz
166
+
167
+ Filter Bandwidth = 1.75 Hz
168
+
169
+ Response Time (75%) = 0.3 s
170
+
171
+
172
+
173
+ */
174
+
175
+
176
+
177
+ BME280I2C::Settings settings(
178
+
179
+ BME280::OSR_X1,
180
+
181
+ BME280::OSR_X1,
182
+
183
+ BME280::OSR_X1,
184
+
185
+ BME280::Mode_Forced,
186
+
187
+ BME280::StandbyTime_1000ms,
188
+
189
+ BME280::Filter_Off,
190
+
191
+ BME280::SpiEnable_False,
192
+
193
+ BME280I2C::I2CAddr_0x76 // I2C address. I2C specific.
194
+
195
+ );
196
+
197
+
198
+
199
+ BME280I2C bme(settings);
200
+
201
+
202
+
203
+ //////////////////////////////////////////////////////////////////
204
+
205
+ void setup()
206
+
207
+ {
208
+
209
+ Serial.begin(SERIAL_BAUD);
210
+
211
+
212
+
213
+ while(!Serial) {} // Wait
214
+
215
+
216
+
217
+ Wire.begin();
218
+
219
+ while(!bme.begin())
220
+
221
+ {
222
+
223
+ Serial.println("Could not find BME280I2C sensor!");
224
+
225
+ delay(1000);
226
+
227
+ }
228
+
229
+
230
+
231
+ switch(bme.chipModel())
232
+
233
+ {
234
+
235
+ case BME280::ChipModel_BME280:
236
+
237
+ Serial.println("Found BME280 sensor! Success.");
238
+
239
+ break;
240
+
241
+ case BME280::ChipModel_BMP280:
242
+
243
+ Serial.println("Found BMP280 sensor! No Humidity available.");
244
+
245
+ break;
246
+
247
+ default:
248
+
249
+ Serial.println("Found UNKNOWN sensor! Error!");
250
+
251
+ }
252
+
253
+
254
+
255
+ // Change some settings before using.
256
+
257
+ settings.tempOSR = BME280::OSR_X4;
258
+
259
+
260
+
261
+ bme.setSettings(settings);
262
+
263
+ }
264
+
265
+
266
+
267
+ //////////////////////////////////////////////////////////////////
268
+
269
+ void loop()
270
+
271
+ {
272
+
273
+ printBME280Data(&Serial);
274
+
275
+ delay(500);
276
+
277
+
278
+
279
+
280
+
281
+
282
+
283
+
284
+
285
+
286
+
287
+ WiFiServer server(80);
288
+
289
+ // Wi-Fiに接続
290
+
291
+ Serial.print("Attempting to connect to SSID: ");
292
+
293
+ Serial.println(ssid);
294
+
295
+ WiFi.begin(ssid, password);
296
+
297
+ while (WiFi.status() != WL_CONNECTED) {
298
+
299
+ Serial.print(".");
300
+
301
+ // 接続するまで待機する
302
+
303
+ delay(1000);
304
+
305
+ }
306
+
307
+ Serial.print("Connected to ");
308
+
309
+ Serial.println(ssid);
310
+
311
+ Serial.println("IP address: ");
312
+
313
+ Serial.println(WiFi.localIP());
314
+
315
+ server.begin();
316
+
317
+
318
+
319
+
320
+
321
+ double temp = temp, press = press, hum = hum;
322
+
323
+ signed long int temp_cal;
324
+
325
+ unsigned long int press_cal, hum_cal;
326
+
327
+
328
+
329
+ Serial.print("connecting to ");
330
+
331
+ Serial.println(host);
332
+
333
+
334
+
335
+ // Use WiFiClient class to create TCP connections
336
+
337
+ WiFiClient client;
338
+
339
+ const int httpPort = 80;
340
+
341
+ if (!client.connect(host, httpPort)) {
342
+
343
+ Serial.println("connection failed");
344
+
345
+ return;
346
+
347
+ }
348
+
349
+
350
+
351
+ // We now create a URI for the request
352
+
353
+ String url = "https://maker.ifttt.com/trigger/";
354
+
355
+ url += event;
356
+
357
+ url += "/with/key/";
358
+
359
+ url += secretkey;
360
+
361
+ url += "?value1=";
362
+
363
+ url += String(temp);
364
+
365
+ url += "&value2=";
366
+
367
+ url += String(press);
368
+
369
+ url += "&value3=";
370
+
371
+ url += String(hum);
372
+
373
+
374
+
375
+ Serial.print("Requesting URL: ");
376
+
377
+ Serial.println(url);
378
+
379
+
380
+
381
+ // This will send the request to the server
382
+
383
+ client.print(String("GET ") + url + " HTTP/1.1\r\n" +
384
+
385
+ "Host: " + host + "\r\n" +
386
+
387
+ "Connection: close\r\n\r\n");
388
+
389
+
390
+
391
+ // Read all the lines of the reply from server and print them to Serial
392
+
393
+ while (client.available()) {
394
+
395
+ String line = client.readStringUntil('\r');
396
+
397
+ Serial.print(line);
398
+
399
+ }
400
+
401
+
402
+
403
+
404
+
405
+
406
+
407
+
408
+
409
+
410
+
411
+ }
412
+
413
+
414
+
415
+ //////////////////////////////////////////////////////////////////
416
+
417
+ void printBME280Data
418
+
419
+ (
420
+
421
+ Stream* client
422
+
423
+ )
424
+
425
+ {
426
+
427
+
428
+
429
+
430
+
431
+ BME280::TempUnit tempUnit(BME280::TempUnit_Celsius);
432
+
433
+ BME280::PresUnit presUnit(BME280::PresUnit_Pa);
434
+
435
+
436
+
437
+ bme.read(pres, temp, hum, tempUnit, presUnit);
438
+
439
+
440
+
441
+ client->print("Temp: ");
442
+
443
+ client->print(temp);
444
+
445
+ client->print("°"+ String(tempUnit == BME280::TempUnit_Celsius ? 'C' :'F'));
446
+
447
+ client->print("\t\tHumidity: ");
448
+
449
+ client->print(hum);
450
+
451
+ client->print("% RH");
452
+
453
+ client->print("\t\tPressure: ");
454
+
455
+ client->print(pres);
456
+
457
+ client->println("Pa");
458
+
459
+
460
+
461
+ double temp = temp, press = press, hum = hum;
462
+
463
+
464
+
465
+ delay(1000);
466
+
467
+ }
468
+
21
469
  ```
22
470
 
23
- エラーメッセージ
24
-
25
- ```
26
-
27
-
28
-
29
- ### 該当のソースコード
30
-
31
- ```/*
32
-
33
- BME280I2C Modes.ino
34
-
35
-
36
-
37
- This code shows how to use predefined recommended settings from Bosch for
38
-
39
- the BME280I2C environmental sensor.
40
-
41
-
42
-
43
- GNU General Public License
44
-
45
-
46
-
47
- Written: Dec 30 2015.
48
-
49
- Last Updated: Sep 23 2017.
50
-
51
-
52
-
53
- Connecting the BME280 Sensor:
54
-
55
- Sensor -> Board
56
-
57
- -----------------------------
58
-
59
- Vin (Voltage In) -> 3.3V
60
-
61
- Gnd (Ground) -> Gnd
62
-
63
- SDA (Serial Data) -> A4 on Uno/Pro-Mini, 20 on Mega2560/Due, 2 Leonardo/Pro-Micro
64
-
65
- SCK (Serial Clock) -> A5 on Uno/Pro-Mini, 21 on Mega2560/Due, 3 Leonardo/Pro-Micro
66
-
67
-
68
-
69
- */
70
-
71
-
72
-
73
- #include <BME280I2C.h>
74
-
75
- #include <Wire.h> // Needed for legacy versions of Arduino.
76
-
77
- #include <WiFiClientSecure.h>
78
-
79
- #include <Adafruit_Sensor.h>
80
-
81
- #include <Adafruit_BME280.h>
82
-
83
-
84
-
85
- #define SERIAL_BAUD 115200
86
-
87
-
88
-
89
- const char* ssid = "******";
90
-
91
- const char* password = "******";
92
-
93
-
94
-
95
- const char* host = "maker.ifttt.com";
96
-
97
- const char* event = "******";
98
-
99
- const char* secretkey = "******";
100
-
101
-
102
-
103
- float temp(NAN), hum(NAN), pres(NAN);
104
-
105
-
106
-
107
- /* Recommended Modes -
108
-
109
- Based on Bosch BME280I2C environmental sensor data sheet.
110
-
111
-
112
-
113
- Weather Monitoring :
114
-
115
- forced mode, 1 sample/minute
116
-
117
- pressure ×1, temperature ×1, humidity ×1, filter off
118
-
119
- Current Consumption = 0.16 μA
120
-
121
- RMS Noise = 3.3 Pa/30 cm, 0.07 %RH
122
-
123
- Data Output Rate 1/60 Hz
124
-
125
-
126
-
127
- Humidity Sensing :
128
-
129
- forced mode, 1 sample/second
130
-
131
- pressure ×0, temperature ×1, humidity ×1, filter off
132
-
133
- Current Consumption = 2.9 μA
134
-
135
- RMS Noise = 0.07 %RH
136
-
137
- Data Output Rate = 1 Hz
138
-
139
-
140
-
141
- Indoor Navigation :
142
-
143
- normal mode, standby time = 0.5ms
144
-
145
- pressure ×16, temperature ×2, humidity ×1, filter = x16
146
-
147
- Current Consumption = 633 μA
148
-
149
- RMS Noise = 0.2 Pa/1.7 cm
150
-
151
- Data Output Rate = 25Hz
152
-
153
- Filter Bandwidth = 0.53 Hz
154
-
155
- Response Time (75%) = 0.9 s
156
-
157
-
158
-
159
-
160
-
161
- Gaming :
162
-
163
- normal mode, standby time = 0.5ms
164
-
165
- pressure ×4, temperature ×1, humidity ×0, filter = x16
166
-
167
- Current Consumption = 581 μA
168
-
169
- RMS Noise = 0.3 Pa/2.5 cm
170
-
171
- Data Output Rate = 83 Hz
172
-
173
- Filter Bandwidth = 1.75 Hz
174
-
175
- Response Time (75%) = 0.3 s
176
-
177
-
178
-
179
- */
180
-
181
-
182
-
183
- BME280I2C::Settings settings(
184
-
185
- BME280::OSR_X1,
186
-
187
- BME280::OSR_X1,
188
-
189
- BME280::OSR_X1,
190
-
191
- BME280::Mode_Forced,
192
-
193
- BME280::StandbyTime_1000ms,
194
-
195
- BME280::Filter_Off,
196
-
197
- BME280::SpiEnable_False,
198
-
199
- BME280I2C::I2CAddr_0x76 // I2C address. I2C specific.
200
-
201
- );
202
-
203
-
204
-
205
- BME280I2C bme(settings);
206
-
207
-
208
-
209
- //////////////////////////////////////////////////////////////////
210
-
211
- void setup()
212
-
213
- {
214
-
215
- Serial.begin(SERIAL_BAUD);
216
-
217
-
218
-
219
- while(!Serial) {} // Wait
220
-
221
-
222
-
223
- Wire.begin();
224
-
225
- while(!bme.begin())
226
-
227
- {
228
-
229
- Serial.println("Could not find BME280I2C sensor!");
230
-
231
- delay(1000);
232
-
233
- }
234
-
235
-
236
-
237
- switch(bme.chipModel())
238
-
239
- {
240
-
241
- case BME280::ChipModel_BME280:
242
-
243
- Serial.println("Found BME280 sensor! Success.");
244
-
245
- break;
246
-
247
- case BME280::ChipModel_BMP280:
248
-
249
- Serial.println("Found BMP280 sensor! No Humidity available.");
250
-
251
- break;
252
-
253
- default:
254
-
255
- Serial.println("Found UNKNOWN sensor! Error!");
256
-
257
- }
258
-
259
-
260
-
261
- // Change some settings before using.
262
-
263
- settings.tempOSR = BME280::OSR_X4;
264
-
265
-
266
-
267
- bme.setSettings(settings);
268
-
269
- }
270
-
271
-
272
-
273
- //////////////////////////////////////////////////////////////////
274
-
275
- void loop()
276
-
277
- {
278
-
279
- printBME280Data(&Serial);
280
-
281
- delay(500);
282
-
283
-
284
-
285
-
286
-
287
-
288
-
289
-
290
-
291
-
292
-
293
- WiFiServer server(80);
294
-
295
- // Wi-Fiに接続
296
-
297
- Serial.print("Attempting to connect to SSID: ");
298
-
299
- Serial.println(ssid);
300
-
301
- WiFi.begin(ssid, password);
302
-
303
- while (WiFi.status() != WL_CONNECTED) {
304
-
305
- Serial.print(".");
306
-
307
- // 接続するまで待機する
308
-
309
- delay(1000);
310
-
311
- }
312
-
313
- Serial.print("Connected to ");
314
-
315
- Serial.println(ssid);
316
-
317
- Serial.println("IP address: ");
318
-
319
- Serial.println(WiFi.localIP());
320
-
321
- server.begin();
322
-
323
-
324
-
325
-
326
-
327
- double temp = temp, press = press, hum = hum;
328
-
329
- signed long int temp_cal;
330
-
331
- unsigned long int press_cal, hum_cal;
332
-
333
-
334
-
335
- Serial.print("connecting to ");
336
-
337
- Serial.println(host);
338
-
339
-
340
-
341
- // Use WiFiClient class to create TCP connections
342
-
343
- WiFiClient client;
344
-
345
- const int httpPort = 80;
346
-
347
- if (!client.connect(host, httpPort)) {
348
-
349
- Serial.println("connection failed");
350
-
351
- return;
352
-
353
- }
354
-
355
-
356
-
357
- // We now create a URI for the request
358
-
359
- String url = "https://maker.ifttt.com/trigger/";
360
-
361
- url += event;
362
-
363
- url += "/with/key/";
364
-
365
- url += secretkey;
366
-
367
- url += "?value1=";
368
-
369
- url += String(temp);
370
-
371
- url += "&value2=";
372
-
373
- url += String(press);
374
-
375
- url += "&value3=";
376
-
377
- url += String(hum);
378
-
379
-
380
-
381
- Serial.print("Requesting URL: ");
382
-
383
- Serial.println(url);
384
-
385
-
386
-
387
- // This will send the request to the server
388
-
389
- client.print(String("GET ") + url + " HTTP/1.1\r\n" +
390
-
391
- "Host: " + host + "\r\n" +
392
-
393
- "Connection: close\r\n\r\n");
394
-
395
-
396
-
397
- // Read all the lines of the reply from server and print them to Serial
398
-
399
- while (client.available()) {
400
-
401
- String line = client.readStringUntil('\r');
402
-
403
- Serial.print(line);
404
-
405
- }
406
-
407
-
408
-
409
-
410
-
411
-
412
-
413
-
414
-
415
-
416
-
417
- }
418
-
419
-
420
-
421
- //////////////////////////////////////////////////////////////////
422
-
423
- void printBME280Data
424
-
425
- (
426
-
427
- Stream* client
428
-
429
- )
430
-
431
- {
432
-
433
-
434
-
435
-
436
-
437
- BME280::TempUnit tempUnit(BME280::TempUnit_Celsius);
438
-
439
- BME280::PresUnit presUnit(BME280::PresUnit_Pa);
440
-
441
-
442
-
443
- bme.read(pres, temp, hum, tempUnit, presUnit);
444
-
445
-
446
-
447
- client->print("Temp: ");
448
-
449
- client->print(temp);
450
-
451
- client->print("°"+ String(tempUnit == BME280::TempUnit_Celsius ? 'C' :'F'));
452
-
453
- client->print("\t\tHumidity: ");
454
-
455
- client->print(hum);
456
-
457
- client->print("% RH");
458
-
459
- client->print("\t\tPressure: ");
460
-
461
- client->print(pres);
462
-
463
- client->println("Pa");
464
-
465
-
466
-
467
- double temp = temp, press = press, hum = hum;
468
-
469
-
470
-
471
- delay(1000);
472
-
473
- }
474
-
475
-
476
-
477
-
478
-
479
471
 
480
472
 
481
473
  ### 試したこと

1

ソースコードの貼り付け場所を修正しました。

2021/08/21 04:33

投稿

aRyo
aRyo

スコア23

test CHANGED
File without changes
test CHANGED
@@ -28,15 +28,7 @@
28
28
 
29
29
  ### 該当のソースコード
30
30
 
31
-
32
-
33
- Arduino
34
-
35
- ソースコード
36
-
37
- ```
38
-
39
- /*
31
+ ```/*
40
32
 
41
33
  BME280I2C Modes.ino
42
34
 
@@ -96,15 +88,15 @@
96
88
 
97
89
  const char* ssid = "******";
98
90
 
99
- const char* password = ""******";
91
+ const char* password = "******";
100
92
 
101
93
 
102
94
 
103
95
  const char* host = "maker.ifttt.com";
104
96
 
105
- const char* event = ""******";
97
+ const char* event = "******";
106
-
98
+
107
- const char* secretkey = ""******";
99
+ const char* secretkey = "******";
108
100
 
109
101
 
110
102
 
@@ -332,7 +324,7 @@
332
324
 
333
325
 
334
326
 
335
- double temp = temp, press = press, hum = hum;      //ここら辺のやり方が誤っている可能性がある//
327
+ double temp = temp, press = press, hum = hum;
336
328
 
337
329
  signed long int temp_cal;
338
330
 
@@ -482,6 +474,10 @@
482
474
 
483
475
 
484
476
 
477
+
478
+
479
+
480
+
485
481
  ### 試したこと
486
482
 
487
483