実現したいこと
通信設定が上手くいかないので、教えてください。
前提
M5stackCore2で重量計を作っています。
Googleドライブのスプレッドシートに重量などを書き込む機能を実装中に以下のエラーメッセージが発生しました。
発生している問題・エラーメッセージ
14:40:34.786 -> 0
14:40:36.113 -> http://script.google.com/macros/s/AKfycby8tykwQjqA2lCY13GUzM6VEABVz2Pizstt_EYdpFQ0GNEBT_Cd2YlZjno1FSMh32Nd/exec?temperature=0.00&humidity=0.00
14:40:36.146 -> [ 45940][V][HTTPClient.cpp:252] beginInternal(): url: http://script.google.com/macros/s/AKfycby8tykwQjqA2lCY13GUzM6VEABVz2Pizstt_EYdpFQ0GNEBT_Cd2YlZjno1FSMh32Nd/exec?temperature=0.00&humidity=0.00
14:40:36.146 -> [ 45946][D][HTTPClient.cpp:303] beginInternal(): protocol: http, host: script.google.com port: 80 url: /macros/s/AKfycby8tykwQjqA2lCY13GUzM6VEABVz2Pizstt_EYdpFQ0GNEBT_Cd2YlZjno1FSMh32Nd/exec?temperature=0.00&humidity=0.00
14:40:36.180 -> [ 45966][D][HTTPClient.cpp:598] sendRequest(): request type: 'GET' redirCount: 0
14:40:36.180 ->
14:40:36.180 -> [ 45973][E][WiFiGeneric.cpp:1476] hostByName(): DNS Failed for script.google.com
14:40:36.180 -> [ 45980][D][HTTPClient.cpp:1149] connect(): failed connect to script.google.com:80
14:40:36.180 -> [ 45987][W][HTTPClient.cpp:1469] returnError(): error(-1): connection refused
14:40:36.180 -> HTTP Status Code: -1
14:40:36.217 -> [ 46004][D][HTTPClient.cpp:408] disconnect(): tcp is closed
14:40:36.217 ->
14:40:36.217 ->
該当のソースコード
#include <M5Core2.h>
#include "HX711.h"
#include <time.h>
#include <WiFiClientSecure.h>
#include <HTTPClient.h>
#include <WebServer.h>
#include <EEPROM.h>
~重量プログラム省略~
const char* ssid = "xxxxxxx";
const char* password = "xxxxxxxxx";
// Accessed Google Script Settings
const char* APP_SERVER = "script.google.com";
IPAddress ip(192, 168, 1, 38); // for fixed IP Address
IPAddress gateway(192,168, 1, 1); //
IPAddress subnet(255, 255, 255, 0); //
IPAddress dns(192, 168, 1, 1); //
//WiFiClient client; //WiFi接続に関するインスタンス的な
WiFiClientSecure client;
const String url1 = "http://script.google.com/macros/s/AKfycby8tykwQjqA2lCY13GUzM6VEABVz2Pizstt_EYdpFQ0GNEBT_Cd2YlZjno1FSMh32Nd/exec";
float ZeroCount ;
float AVE1 ;
float AVE2 ;
int WEIGHT ;//変化重量値
int WEIGHT1;//初期値重量
int WEIGHT2;//
int WEIGHT3;//
int WEIGHT4;//
int WEIGHT5;//
int count ;
float Zero1; //5個の平均値
float Zero2 ; //10個の平均値
float Zero3 ; //20個の平均値
float Zero4 ; //30個の平均値
float Zero5 ; //50個の平均値
int fresh=0;
///////////////////////////////////////////////////
// int: 32bit (4byte)EEPROM用
const int N = 4; // 5つの変数(a0,a1,2,a3)
float data[N];
void eeprom_write() {
data[0] = WEIGHT5;
//data[1] = round( data[0] /ZeroCount);
data[1] = count;
data[2] = ZeroCount;
data[3] = scale.get_units(10);
int n = 0;
for (int i = 0; i < N; i++) {
EEPROM.put(n, data[i]);
//n += 4; // 4バイト毎
n += 16; // 16バイト毎
}
EEPROM.commit(); // EEPROMに書き込み確定
}
void eeprom_read() {
int n = 0;
for (int i = 0; i < N; i++) {
EEPROM.get(n, data[i]); // EEPROMより読み込み
//n += 4; // 4バイト毎
n += 16; // 8バイト毎
}
Serial.println(data[0]);
Serial.println(data[1]);
Serial.println(data[2]);
Serial.println(data[3]);
Serial.println(data[4]);
count = (data[1]);
ZeroCount = (data[2]);
AVE1 = (data[2])*0.80;
AVE2 = (data[2])*1.20;
WEIGHT1 = (data[0]);
WEIGHT5 = (data[3]);
}
//////////////////////////////////////////////////////
//////////////////////////////////////////////////////
void setup() {
Serial.begin(115200); // シリアルポートを初期化(9600 bpsで通信)
M5.begin(); //Init M5Core2. 初期化M5Core2
M5.lcd.setTextSize(3); //Set the text size to 3. Text文字の大きさ設定3
M5.Spk.begin(); // Initialize the speaker.
if (!WiFi.config(ip,gateway,subnet)){
Serial.println("Failed to configure!");
}
//WiFi.mode(WIFI_STA);
//WiFi.disconnect();
//if (WiFi.begin(ssid, password) != WL_DISCONNECTED) {
// ESP.restart();
//}
////////////////////////////////////////////////////////////
scale.begin(
LOADCELL_DOUT_PIN,
LOADCELL_SCK_PIN); // Initialize library with data output pin, clock input pin and gain factor.
scale.set_scale(0); //既知の重さをADCの値で割った数字を入れる。(「2280」の値がそれ)#floatなのでfが付いている); //set the SCALE value this value is used to convert the raw data to measure units.
scale.set_offset(LOADCELL_OFFSET); //Set the tare weight.
scale.set_scale(-109.8); // this value is obtained by calibrating the scale with known weights; see the README for details.
scale.tare(); // reset the scale to 0.
EEPROM.begin(64); // 16byte = 4変数 x 4バイト(int=32bit)
eeprom_read();
delay(200);
/////////////////////////////////////////////////////////////
/////LCD初期設定/////
lcd.init(); // LCD初期化
lcd.setRotation(1); // 画面向き設定(0~3で設定、4~7は反転)
canvas.setColorDepth(8); // カラーモード設定(書かなければ初期値16bit。24bit(パネル性能によっては18bit)は対応していれば選択可)
// CORE2 GRAY、のスプライトは16bit以上で表示されないため8bitに設定
canvas.setTextWrap(false); // 改行をしない(画面をはみ出す時自動改行する場合はtrue)
canvas.setTextSize(3); // 文字サイズ(倍率)
canvas.createSprite(lcd.width(), lcd.height()); // canvasサイズ(メモリ描画領域)設定(画面サイズに設定)
}
////////////////////////////
///////////////////////////////////////////////////////////////////////
void loop() {
M5.update(); //ボタンの状態を更新する関数・・・この関数を呼ばないとボタンの状態は更新されない。
M5.Axp.SetLDOEnable(3, false); // AXP_IO3 を false で振動モータ停止
M5.Spk.begin(); // Initialize the speaker.
///// LCD表示処理(canvas.で指定してメモリ内の仮想画面に描画していく)/////
canvas.fillScreen(BLACK); // 背景塗り潰し
canvas.setTextColor(WHITE); // 文字色と背景を指定(文字色, 背景(省略可))
//////////////////////////////////////////////////////////////////////
delay(50);
if (M5.BtnA.wasPressed()) { //If button A is pressed. Aボタンが押されたら
M5.Axp.SetLDOEnable(3, true); // AXP_IO3 を false で振動モータ作動
scale.set_offset(LOADCELL_OFFSET + scale.read());
scale.set_scale(-109.8);
scale.tare();
fresh = 0 ;
data[0] = 0;
data[1] = 0;
data[2] = 0;
data[3] = 0;
data[4] = 0;
AVE1=0;
AVE2=0;
count=0;
M5.Axp.SetLDOEnable(3, true); // AXP_IO3 を false で振動モータ作動
delay(10);
}
////////////////////////////////////////////////////////////
//float weight = scale.get_units(10) +(data[0]) ;
int weight = scale.get_units(10) + data[0] ; //在庫用
//int weight = scale.get_units(5) +(data[0]) ; //現場用
delay(300);
////////////////////////////////////////////////////////////
//// M5.Lcd. を canvas. に書き換え////
canvas.setCursor(45, 60);
canvas.printf("Weight:%2d ", weight); //%2d初期値(整数)
canvas.setCursor(280, 60);
canvas.printf("g");
delay(10);
////////////////////////////////////////
////////////////////////////////////////
if ( weight == 0 ){
count=0;
delay(10);
}
Serial.println(WEIGHT1);
delay(250);
///////////////////////////////////////////
//// M5.Lcd. を canvas. に書き換え////
canvas.setCursor(45, 130);
canvas.printf(" Count:%1d ", count);
delay(10);
////////////////////////////////////////
}
if (M5.BtnC.wasPressed()){ //If button C is pressed. Cボタンが押されている間、IPアドレスの表示
M5.Axp.SetLDOEnable(3, true); // AXP_IO3 を false で振動モータ作動
M5.Lcd.clear(BLACK);
M5.Lcd.setCursor(1, 1, 1);
M5.Lcd.print("\r\nWiFi connected\r\nIP address: ");
M5.Lcd.println(WiFi.localIP());
M5.Lcd.println(ZeroCount);
WEIGHT5 = weight;
eeprom_write();
delay(50);
M5.Axp.SetLDOEnable(3, false); // AXP_IO3 を false で振動モータ停止
M5.shutdown();
}
fresh++;
delay(10);
//if(fresh == 15){ //画面化けリフレッシュ
// M5.Lcd.clear(BLACK);
canvas.setCursor(1, 1, 1);
canvas.print(" Weight Unit ");
canvas.setCursor(20, 210, 1);
canvas.print("0_W");
canvas.setCursor(125, 210, 1);
canvas.print("0_C");
canvas.setCursor(245, 210, 1);
canvas.print("Memo");
canvas.drawFastHLine(30, 100, 260, YELLOW);
canvas.drawFastHLine(30, 170, 260, BLUE);
delay(10);
//fresh=0;
//}
/////////////////////////////////////////////////////////////////////////
float temperature = weight;
float humidity = count;
String urlFinal = url1 + "?temperature=" + String(temperature) + "&humidity=" + String(humidity);
Serial.println(urlFinal);
delay(10);
HTTPClient http;
client.setInsecure();
http.begin(urlFinal.c_str());
http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
int httpCode = http.GET();
Serial.print("HTTP Status Code: ");
Serial.println(httpCode);
//---------------------------------------------------------------------
//getting response from google sheet
String payload; if (httpCode > 0) { payload = http.getString(); Serial.println("Payload: "+payload); } //--------------------------------------------------------------------- http.end(); delay(10); Serial.println("\nWiFi is disconnected"); WiFi.disconnect(true);
canvas.pushSprite(0, 0); // メモリ内に描画したcanvasを座標を指定して表示する
delay(10);
delay(10); // 遅延時間(ms)
}
ここにより詳細な情報を記載してください。

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