#include <HTTPClient.h>
#include <WiFi.h>
const char* ssid = "Wokwi-GUEST";
const char* password = "";
const String url = "http://web.mgiga.com.tw/mgiga_ajax.jsp?action=TEST";
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
WiFi.begin(ssid, password);
//非同步wifi連線
Serial.println("connecting to wifi");
while( WiFi.status() != WL_CONNECTED){
delay(500);
Serial.println(".");
//連線中
}
Serial.print("ok! ip=");
//連線成功到網頁端
Serial.println(WiFi.localIP());
//顯示IP
HTTPClient http;
http.begin(url);
//HTTP request請求連線
int httpResponseCode = http.GET();
//重要
Serial.print(httpResponseCode);
if(httpResponseCode >0){
Serial.print("HTTP OK!");
//連線成功的回應
String payload = http.getString();
//把回應的網頁資訊丟給payload再轉成字串
Serial.println();
Serial.println(payload);
//印出網頁回應的字串
}else{
Serial.print("Error code");
//連線失敗的回應
}
}
void loop() {
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
}