質問編集履歴
2
情報の修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -167,8 +167,8 @@
|
|
167
167
|
printBME280Data(&Serial);
|
168
168
|
delay(60000);
|
169
169
|
|
170
|
-
|
170
|
+
wifi_conect();
|
171
|
-
delay(30000); //
|
171
|
+
delay(30000); //30秒毎に書き込みする
|
172
172
|
g_acsess();
|
173
173
|
|
174
174
|
|
1
情報の追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -29,4 +29,228 @@
|
|
29
29
|
```
|
30
30
|
|
31
31
|
データを送らずデプロイすると日付だけ入力されるはずですが、どこが誤っていますでしょうか。
|
32
|
-
ご教授ください。よろしくお願いいたします。
|
32
|
+
ご教授ください。よろしくお願いいたします。
|
33
|
+
|
34
|
+
|
35
|
+
*****追記*****
|
36
|
+
|
37
|
+
Arduinoに実際に書き込みしたコードが以下になります。
|
38
|
+
これを実行するとGoogleスプレッドシートに記録が始まると思ったのですが何も反応がありません。
|
39
|
+
事前にGoogleスプレッドシートでシートを作成しておく必要があるのでしょうか。
|
40
|
+
よろしくお願いいたします。
|
41
|
+
```ここに言語を入力
|
42
|
+
/*
|
43
|
+
BME280I2C Modes.ino
|
44
|
+
|
45
|
+
This code shows how to use predefined recommended settings from Bosch for
|
46
|
+
the BME280I2C environmental sensor.
|
47
|
+
|
48
|
+
GNU General Public License
|
49
|
+
|
50
|
+
Written: Dec 30 2015.
|
51
|
+
Last Updated: Sep 23 2017.
|
52
|
+
|
53
|
+
Connecting the BME280 Sensor:
|
54
|
+
Sensor -> Board
|
55
|
+
-----------------------------
|
56
|
+
Vin (Voltage In) -> 3.3V
|
57
|
+
Gnd (Ground) -> Gnd
|
58
|
+
SDA (Serial Data) -> A4 on Uno/Pro-Mini, 20 on Mega2560/Due, 2 Leonardo/Pro-Micro
|
59
|
+
SCK (Serial Clock) -> A5 on Uno/Pro-Mini, 21 on Mega2560/Due, 3 Leonardo/Pro-Micro
|
60
|
+
|
61
|
+
*/
|
62
|
+
|
63
|
+
#include <BME280I2C.h>
|
64
|
+
#include <Wire.h> // Needed for legacy versions of Arduino.
|
65
|
+
#include <WiFiClientSecure.h>
|
66
|
+
#include <Adafruit_Sensor.h>
|
67
|
+
#include <Adafruit_BME280.h>
|
68
|
+
|
69
|
+
#define SERIAL_BAUD 115200
|
70
|
+
|
71
|
+
const char* ssid = "********";
|
72
|
+
const char* password = "********";
|
73
|
+
|
74
|
+
|
75
|
+
const char* server = "script.google.com";
|
76
|
+
const char* key = "********"; // google script key
|
77
|
+
WiFiClientSecure client;
|
78
|
+
|
79
|
+
float temp(NAN), hum(NAN), pres(NAN);
|
80
|
+
|
81
|
+
/* Recommended Modes -
|
82
|
+
Based on Bosch BME280I2C environmental sensor data sheet.
|
83
|
+
|
84
|
+
Weather Monitoring :
|
85
|
+
forced mode, 1 sample/minute
|
86
|
+
pressure ×1, temperature ×1, humidity ×1, filter off
|
87
|
+
Current Consumption = 0.16 μA
|
88
|
+
RMS Noise = 3.3 Pa/30 cm, 0.07 %RH
|
89
|
+
Data Output Rate 1/60 Hz
|
90
|
+
|
91
|
+
Humidity Sensing :
|
92
|
+
forced mode, 1 sample/second
|
93
|
+
pressure ×0, temperature ×1, humidity ×1, filter off
|
94
|
+
Current Consumption = 2.9 μA
|
95
|
+
RMS Noise = 0.07 %RH
|
96
|
+
Data Output Rate = 1 Hz
|
97
|
+
|
98
|
+
Indoor Navigation :
|
99
|
+
normal mode, standby time = 0.5ms
|
100
|
+
pressure ×16, temperature ×2, humidity ×1, filter = x16
|
101
|
+
Current Consumption = 633 μA
|
102
|
+
RMS Noise = 0.2 Pa/1.7 cm
|
103
|
+
Data Output Rate = 25Hz
|
104
|
+
Filter Bandwidth = 0.53 Hz
|
105
|
+
Response Time (75%) = 0.9 s
|
106
|
+
|
107
|
+
|
108
|
+
Gaming :
|
109
|
+
normal mode, standby time = 0.5ms
|
110
|
+
pressure ×4, temperature ×1, humidity ×0, filter = x16
|
111
|
+
Current Consumption = 581 μA
|
112
|
+
RMS Noise = 0.3 Pa/2.5 cm
|
113
|
+
Data Output Rate = 83 Hz
|
114
|
+
Filter Bandwidth = 1.75 Hz
|
115
|
+
Response Time (75%) = 0.3 s
|
116
|
+
|
117
|
+
*/
|
118
|
+
|
119
|
+
BME280I2C::Settings settings(
|
120
|
+
BME280::OSR_X1,
|
121
|
+
BME280::OSR_X1,
|
122
|
+
BME280::OSR_X1,
|
123
|
+
BME280::Mode_Forced,
|
124
|
+
BME280::StandbyTime_1000ms,
|
125
|
+
BME280::Filter_Off,
|
126
|
+
BME280::SpiEnable_False,
|
127
|
+
BME280I2C::I2CAddr_0x76 // I2C address. I2C specific.
|
128
|
+
);
|
129
|
+
|
130
|
+
BME280I2C bme(settings);
|
131
|
+
|
132
|
+
//////////////////////////////////////////////////////////////////
|
133
|
+
void setup()
|
134
|
+
{
|
135
|
+
Serial.begin(SERIAL_BAUD);
|
136
|
+
|
137
|
+
while(!Serial) {} // Wait
|
138
|
+
|
139
|
+
Wire.begin();
|
140
|
+
while(!bme.begin())
|
141
|
+
{
|
142
|
+
Serial.println("Could not find BME280I2C sensor!");
|
143
|
+
delay(1000);
|
144
|
+
}
|
145
|
+
|
146
|
+
switch(bme.chipModel())
|
147
|
+
{
|
148
|
+
case BME280::ChipModel_BME280:
|
149
|
+
Serial.println("Found BME280 sensor! Success.");
|
150
|
+
break;
|
151
|
+
case BME280::ChipModel_BMP280:
|
152
|
+
Serial.println("Found BMP280 sensor! No Humidity available.");
|
153
|
+
break;
|
154
|
+
default:
|
155
|
+
Serial.println("Found UNKNOWN sensor! Error!");
|
156
|
+
}
|
157
|
+
|
158
|
+
// Change some settings before using.
|
159
|
+
settings.tempOSR = BME280::OSR_X4;
|
160
|
+
|
161
|
+
bme.setSettings(settings);
|
162
|
+
}
|
163
|
+
|
164
|
+
//////////////////////////////////////////////////////////////////
|
165
|
+
void loop()
|
166
|
+
{
|
167
|
+
printBME280Data(&Serial);
|
168
|
+
delay(60000);
|
169
|
+
|
170
|
+
|
171
|
+
delay(30000); //10秒毎に書き込みする
|
172
|
+
g_acsess();
|
173
|
+
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
}
|
178
|
+
|
179
|
+
//////////////////////////////////////////////////////////////////
|
180
|
+
void printBME280Data
|
181
|
+
(
|
182
|
+
Stream* client
|
183
|
+
)
|
184
|
+
{
|
185
|
+
|
186
|
+
|
187
|
+
BME280::TempUnit tempUnit(BME280::TempUnit_Celsius);
|
188
|
+
BME280::PresUnit presUnit(BME280::PresUnit_Pa);
|
189
|
+
|
190
|
+
bme.read(pres, temp, hum, tempUnit, presUnit);
|
191
|
+
|
192
|
+
client->print("Temp: ");
|
193
|
+
client->print(temp);
|
194
|
+
client->print("°"+ String(tempUnit == BME280::TempUnit_Celsius ? 'C' :'F'));
|
195
|
+
client->print("\t\tHumidity: ");
|
196
|
+
client->print(hum);
|
197
|
+
client->print("% RH");
|
198
|
+
client->print("\t\tPressure: ");
|
199
|
+
client->print(pres);
|
200
|
+
client->println("Pa");
|
201
|
+
|
202
|
+
|
203
|
+
|
204
|
+
delay(1000);
|
205
|
+
}
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
|
210
|
+
void wifi_conect(){
|
211
|
+
|
212
|
+
WiFiServer server(80);
|
213
|
+
// Wi-Fiに接続
|
214
|
+
Serial.print("Attempting to connect to SSID: ");
|
215
|
+
Serial.println(ssid);
|
216
|
+
WiFi.begin(ssid, password);
|
217
|
+
while (WiFi.status() != WL_CONNECTED) {
|
218
|
+
Serial.print(".");
|
219
|
+
// 接続するまで待機する
|
220
|
+
delay(1000);
|
221
|
+
}
|
222
|
+
Serial.print("Connected to ");
|
223
|
+
Serial.println(ssid);
|
224
|
+
Serial.println("IP address: ");
|
225
|
+
Serial.println(WiFi.localIP());
|
226
|
+
server.begin();
|
227
|
+
}
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
void g_acsess(){
|
232
|
+
|
233
|
+
|
234
|
+
String URL="https://script.google.com/macros/s/";
|
235
|
+
URL += key;
|
236
|
+
URL += "/exec?";
|
237
|
+
URL += "&1_cell=";
|
238
|
+
URL += temp ;
|
239
|
+
URL += "&2_cell=";
|
240
|
+
URL += hum ;
|
241
|
+
URL += "&3_cell=";
|
242
|
+
URL += pres ;
|
243
|
+
|
244
|
+
Serial.println(URL);
|
245
|
+
// サイトにアクセス
|
246
|
+
Serial.println("\nStarting connection to server...");
|
247
|
+
if (!client.connect(server, 443))
|
248
|
+
Serial.println("Connection failed!");
|
249
|
+
else {
|
250
|
+
Serial.println("Connected to server!\n");
|
251
|
+
client.println("GET " + URL);
|
252
|
+
client.stop();
|
253
|
+
Serial.println("finish.");
|
254
|
+
}
|
255
|
+
}
|
256
|
+
```
|