質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Google スプレッドシート

Google スプレッドシートは、フリーで利用できる表計算ソフト。Webアプリのためインターネットに接続することで利用できます。チャートやグラフの作成のほか、シートを他のユーザーと共有したり、同時に作業を進めることも可能です。

Arduino

Arduinoは、AVRマイコン、単純なI/O(入出力)ポートを備えた基板、C言語を元としたArduinoのプログラム言語と、それを実装した統合開発環境から構成されたシステムです。

Google

Googleは、アメリカ合衆国に位置する、インターネット関連のサービスや製品を提供している企業です。検索エンジンからアプリケーションの提供まで、多岐にわたるサービスを提供しています。

Q&A

解決済

1回答

5713閲覧

ArduinoからGoogleスプレッドシートにデータを飛ばしたいけどServer,443で躓く

aRyo

総合スコア23

Google スプレッドシート

Google スプレッドシートは、フリーで利用できる表計算ソフト。Webアプリのためインターネットに接続することで利用できます。チャートやグラフの作成のほか、シートを他のユーザーと共有したり、同時に作業を進めることも可能です。

Arduino

Arduinoは、AVRマイコン、単純なI/O(入出力)ポートを備えた基板、C言語を元としたArduinoのプログラム言語と、それを実装した統合開発環境から構成されたシステムです。

Google

Googleは、アメリカ合衆国に位置する、インターネット関連のサービスや製品を提供している企業です。検索エンジンからアプリケーションの提供まで、多岐にわたるサービスを提供しています。

1グッド

1クリップ

投稿2021/08/27 22:12

編集2021/08/27 23:47

Arduino(ESP)を用いて気温,湿度,気圧のデータをGoogleスプレッドシートに記録するといったプログラムを作成中です。

Googleスプレッドシートにデータを送信した際に接続が上手くいきません。
どこが誤っているかさっぱり分からず困っています。
ご助言していただけると幸いです。

/* BME280I2C Modes.ino This code shows how to use predefined recommended settings from Bosch for the BME280I2C environmental sensor. GNU General Public License Written: Dec 30 2015. Last Updated: Sep 23 2017. Connecting the BME280 Sensor: Sensor -> Board ----------------------------- Vin (Voltage In) -> 3.3V Gnd (Ground) -> Gnd SDA (Serial Data) -> A4 on Uno/Pro-Mini, 20 on Mega2560/Due, 2 Leonardo/Pro-Micro SCK (Serial Clock) -> A5 on Uno/Pro-Mini, 21 on Mega2560/Due, 3 Leonardo/Pro-Micro */ #include <BME280I2C.h> #include <Wire.h> // Needed for legacy versions of Arduino. #include <WiFiClientSecure.h> #include <Adafruit_Sensor.h> #include <Adafruit_BME280.h> #define SERIAL_BAUD 115200 const char* ssid = "60AAEF98BE17-2G"; const char* password = "1sxvgn8cp143e5"; const char* server = "script.google.com"; const char* key = "AKfycbwnX2K6mBQEF5qy4MSbtHuRJeiQX8_94q7MpPga26AQkEZaBhzdRImC187oGYwBSaQ"; // google script key WiFiClientSecure client; float temp(NAN), hum(NAN), pres(NAN); /* Recommended Modes - Based on Bosch BME280I2C environmental sensor data sheet. Weather Monitoring : forced mode, 1 sample/minute pressure ×1, temperature ×1, humidity ×1, filter off Current Consumption = 0.16 μA RMS Noise = 3.3 Pa/30 cm, 0.07 %RH Data Output Rate 1/60 Hz Humidity Sensing : forced mode, 1 sample/second pressure ×0, temperature ×1, humidity ×1, filter off Current Consumption = 2.9 μA RMS Noise = 0.07 %RH Data Output Rate = 1 Hz Indoor Navigation : normal mode, standby time = 0.5ms pressure ×16, temperature ×2, humidity ×1, filter = x16 Current Consumption = 633 μA RMS Noise = 0.2 Pa/1.7 cm Data Output Rate = 25Hz Filter Bandwidth = 0.53 Hz Response Time (75%) = 0.9 s Gaming : normal mode, standby time = 0.5ms pressure ×4, temperature ×1, humidity ×0, filter = x16 Current Consumption = 581 μA RMS Noise = 0.3 Pa/2.5 cm Data Output Rate = 83 Hz Filter Bandwidth = 1.75 Hz Response Time (75%) = 0.3 s */ BME280I2C::Settings settings( BME280::OSR_X1, BME280::OSR_X1, BME280::OSR_X1, BME280::Mode_Forced, BME280::StandbyTime_1000ms, BME280::Filter_Off, BME280::SpiEnable_False, BME280I2C::I2CAddr_0x76 // I2C address. I2C specific. ); BME280I2C bme(settings); ////////////////////////////////////////////////////////////////// void setup() { Serial.begin(SERIAL_BAUD); while(!Serial) {} // Wait Wire.begin(); while(!bme.begin()) { Serial.println("Could not find BME280I2C sensor!"); delay(1000); } switch(bme.chipModel()) { case BME280::ChipModel_BME280: Serial.println("Found BME280 sensor! Success."); break; case BME280::ChipModel_BMP280: Serial.println("Found BMP280 sensor! No Humidity available."); break; default: Serial.println("Found UNKNOWN sensor! Error!"); } // Change some settings before using. settings.tempOSR = BME280::OSR_X4; bme.setSettings(settings); } ////////////////////////////////////////////////////////////////// void loop() { printBME280Data(&Serial); delay(60000); wifi_conect(); delay(30000); //30秒毎に書き込みする g_acsess(); } ////////////////////////////////////////////////////////////////// void printBME280Data ( Stream* client ) { BME280::TempUnit tempUnit(BME280::TempUnit_Celsius); BME280::PresUnit presUnit(BME280::PresUnit_Pa); bme.read(pres, temp, hum, tempUnit, presUnit); client->print("Temp: "); client->print(temp); client->print("°"+ String(tempUnit == BME280::TempUnit_Celsius ? 'C' :'F')); client->print("\t\tHumidity: "); client->print(hum); client->print("% RH"); client->print("\t\tPressure: "); client->print(pres); client->println("Pa"); delay(1000); } void wifi_conect(){ WiFiServer server(80); // Wi-Fiに接続 Serial.print("Attempting to connect to SSID: "); Serial.println(ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { Serial.print("."); // 接続するまで待機する delay(1000); } Serial.print("Connected to "); Serial.println(ssid); Serial.println("IP address: "); Serial.println(WiFi.localIP()); server.begin(); } void g_acsess(){ String URL="https://script.google.com/macros/s/"; URL += key; URL += "/exec?"; URL += "&1_cell="; URL += temp ; URL += "&2_cell="; URL += hum ; URL += "&3_cell="; URL += pres ; Serial.println(URL); // サイトにアクセス Serial.println("\nStarting connection to server..."); if (!client.connect(server, 443)){  //ここで毎回エラーになり接続できません。因みに作成されたURLを自分でコピペするとデータGoogleスプレッドシートに記録されます Serial.println("Connection failed!"); Serial.println(""); return; } Serial.println("Connected to server!\n"); client.println("GET " + URL); client.stop(); Serial.println("finish."); }

シリアルモニターに表示されている文
****部分は、意図的に消しています

08:43:15.051 -> Temp: 28.30°C Humidity: 56.79% RH Pressure: 101093.39Pa 08:44:16.056 -> Attempting to connect to SSID: 60AAEF98BE17-2G 08:44:16.056 -> Connected to 60AAEF98BE17-2G 08:44:16.056 -> IP address: 08:44:16.056 -> ******  //IPアドレスが記載 08:44:46.063 -> https://script.google.com/macros/s/********/exec?&1_cell=28.30&2_cell=56.79&3_cell=101093.39  08:44:46.063 -> 08:44:46.063 -> Starting connection to server... 08:44:46.063 -> Connection failed! 08:44:46.063 ->
Naa👍を押しています

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

y_waiwai

2021/08/27 23:35

うまくいかないとは、どーゆーふーになるんでしょうか
aRyo

2021/08/27 23:37

コメントありがとうございます。 シリアルモニターに”Connection failed!”と表示されます。 つまり接続が上手くできていないかと思われます。 よろしくお願いいたします。
y_waiwai

2021/08/27 23:41

んじゃそのシリアルモニタに表示されるものを全部提示しましょう。 質問文を編集してそこに追記してください
aRyo

2021/08/27 23:49

シリアルモニタの情報を追加投稿しました。 このURLをコピペし手動で張り付けるとGoogleスプレッドシートに記録されます なので、サーバーにコネクトする際になんらかのエラーが起きていると思われます
guest

回答1

0

ベストアンサー

Arduino core for the ESP32 v1.0.5からは、WiFiClientSecureを使ってHTTPS接続する際、証明書による認証がデフォルトで必須となっています。このためscript.google.comのルート証明書を取得して設定する必要があります。

Arduino

1const char *root_ca= "ルート証明書"; 2client.setCACert(root_ca); 3client.connect(server, 443);

上記の、"ルート証明書"は、正しい証明書の値を設定してください。

認証が必要ない場合は、setInsecure()を使って、認証なしで接続することもできます。

Arduino

1client.setInsecure(); 2client.connect(server, 443);

付属するスケッチ例の、WiFiClientSecureやWiFiClientInsecureを参照してください。

あと、本題ではありませんが、以下は恐らく不要です。

Arduino

1#include <Adafruit_Sensor.h> 2#include <Adafruit_BME280.h>

また、自分自身をウェブサーバにしているようですが、受信する処理がないため、こちらも不要だと思います。今後拡張するとかであれば、すみません。

Arduino

1WiFiServer server(80); 2server.begin();

グローバル変数 const char* server = "script.google.com"; と同じ変数名というのも、混乱のもとですね。

投稿2021/08/28 00:30

mkgt00

総合スコア165

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

aRyo

2021/08/28 00:50

client.setInsecure();を追加したら、出来ました!! ありがとうございます。 また、補足情報に関しても色々なブログ等から引用したため余分な情報が整理出来ていない状態でした これからどんどん学びたいと思います。 凄い分かりやすかったので、また疑問点あれば回答お待ちしております!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問