0
Arduino IDEをNodemcu-esp12eモジュールで使用して、HTTP GETリクエストを作成するプログラムを作成しました。arduino IDEとnodemcu-esp-12eでHTTP GET要求の戻りを確認する
しかし、私はこの相談の復帰にどのように対処するのが正しいのか分かりません。
戻り値がfalse/offかtrue/onかを調べるために 'indexOf'関数を使って戻り値を検証しています。
返品を確認する正しい方法はありますか?
このコードを改善する方法の提案はありますか?
#include <ESP8266WiFi.h>
const char* ssid = "mywifiid";
const char* password = "mypassword";
IPAddress host(192,168,0,11);
void setup() {
Serial.begin(115200);
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
//
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
//
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void loop() {
//
Serial.print("connecting to ");
Serial.println(host);
//
WiFiClient client;
const int httpPort = 80;
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;
}
else{
Serial.println("connection success");
}
//
String get = "http://localhost/Test/GetStatusSensor?idsensor=2";
Serial.println(get);
//
client.print("GET " + get + "\r\nHTTP/1.1\r\nHost: localhost\Test\r\nConnection: keep-alive\r\n\r\n");
//
while(client.available()){
String line = client.readStringUntil('\r');
//
int iret= line.indexOf('on');
//
Serial.print(line);
Serial.println(String(iret));
//
if (iret> 0) {
//
Serial.println("On");
}
else {
Serial.println("Off");
}
}
//
Serial.println();
Serial.println("closing connection");
delay(20000); // 20 sec
}
ArduinoのはCではありません! – Olaf
訂正ありがとう! –
http://stackoverflow.com/questions/11812850/does-arduino-use-c-or-c –