前提
M5StackからGoogleDriveのスプレッドシートに送信するプログラムを
http://toolware.jp/m5stack-spreadsheet/
を見ながら作ったのですが、うまくいきません。
下がArduinoでのコードなのですが
関数postValuesのif (client.connect(host, 443))がうまくいっていない感じなのですが素人なので解決策がわかりません。
どうすればいいですか?
実現したいこと
client.connect(host, 443)を真にしたい
発生している問題・エラーメッセージ
実行するとM5STACKのディスプレイに様々な文字が出てきた後に
MainLoop
Response : ERROR
と出て終わる
Arduinoに書いたコード
if (client.connect(host, 443))
が原因だと思うのですが解決策がわかりません。
該当のソースコード
#include <M5Stack.h> #include <WiFiClientSecure.h> //****** ネットワーク関連 ****** const char* ssid = ""; // your network SSID (name of wifi network) const char* password = ""; // your network password const char* host = "script.google.com"; String exec_url = "https://script.google.com/macros/s/AKfycbyHyq0tOPGTXQCFaSkQHkvNpLnNqCXLgzLBgWBhrI3LydWOG4awZltICRC1bzZc3jln/exec"; //ウェブアプリケーションのURL WiFiClientSecure client; String values; //送信するデータ String postValues(String values_to_post) { //M5.Lcd.println("?????"); //delay(4000); if (client.connect(host, 443)){ //M5.Lcd.println("!!!!!"); //delay(4000); LcdInit(); M5.Lcd.println("Posting data..."); client.println("POST " + exec_url + " HTTP/1.1"); client.println("HOST: " + (String)host); client.println("Connection: close"); client.println("Content-Type: text/plain"); client.print("Content-Length: "); client.println(values_to_post.length()); client.println(); client.println(values_to_post); delay(100); while (client.available()) { char c = client.read(); M5.Lcd.print(c); } client.stop(); delay(4000); return "post end"; } else { return "ERROR"; } } void connectingWiFi(){ boolean WiFiOn; // WiFi接続したらtrue int n_trial, max_trial = 10; //WiFi接続試行回数とその上限 WiFi.mode(WIFI_STA); WiFi.disconnect(); WiFi.begin(ssid, password); LcdInit(); M5.Lcd.print("Connecting to WiFi"); // attempt to connect to Wifi network: n_trial = 0; while (WiFi.status() != WL_CONNECTED && n_trial < max_trial) { M5.Lcd.print("."); // wait 1 second for re-trying n_trial++; delay(4000); } LcdInit(); if (WiFi.status() == WL_CONNECTED) {WiFiOn = true; M5.Lcd.print("Connected to "); M5.Lcd.println(ssid); M5.Lcd.print("IP: "); M5.Lcd.println(WiFi.localIP()); } else {WiFiOn = false; M5.Lcd.print("WiFi connection failed"); } delay(4000); } void LcdInit(){ M5.Lcd.clear(BLACK); M5.Lcd.setTextSize(2); M5.Lcd.setTextColor(WHITE, BLACK); M5.Lcd.setCursor(0, 0); } void setup() { M5.begin(); LcdInit(); M5.Lcd.print("Send data to Google Spreadsheet\n"); delay(4000); connectingWiFi(); } void loop() { LcdInit(); M5.Lcd.print("MainLoop\n"); values = "FilenameA, SheetnameA, 3,"; //ファイル名、シート名、データ列数、 values += "1, 10, 20, 2, 12, 28, 3, 20, 30"; //以後データ本体 String response = postValues(values); M5.Lcd.print("Response : "); M5.Lcd.println(response); delay(1000); WiFi.disconnect(); while(1); }
実行時のシリアルモニタの内容
16:33:09.993 -> ets Jul 29 2019 12:21:46 16:33:09.993 -> 16:33:09.993 -> rst:0x1 (POWERON_RESET),boot:0x17 (SPI_FAST_FLASH_BOOT) 16:33:09.993 -> configsip: 0, SPIWP:0xee 16:33:09.993 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00 16:33:09.993 -> mode:DIO, clock div:1 16:33:09.993 -> load:0x3fff0030,len:1344 16:33:09.993 -> load:0x40078000,len:13864 16:33:09.993 -> load:0x40080400,len:3608 16:33:09.993 -> entry 0x400805f0 16:33:10.364 -> M5Stack initializing... 16:33:11.283 -> OK
M5STACKの画面の内容
Send data to Google Spreadsheet
↓
Connecting to WiFi.
↓
Connected to *************** IP: 192.*******
↓
MainLoop Response : ERROR
最後の部分を何とかしたいです

回答1件
あなたの回答
tips
プレビュー