#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
HTTPClient http;
#ifndef STASSID
#define STASSID "xxxx4321"
#define STAPSK "45654745"
#endif
const char* ssid = STASSID;
const char* password = STAPSK;
WiFiClient client;
int status=0;
void setup() {
pinMode(16, OUTPUT);
Serial.begin(9600);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
WifiInit();
}
void loop() {
if(digitalRead(16)==HIGH){
http.begin("http://192.168.2.8:29000/Index.aspx");
int httpCode = http.GET();
Serial.println(httpCode);
if(httpCode == 200) { // 访问成功,取得返回参数
String payload = http.getString();
Serial.println(payload);
} else { // 访问不成功,打印原因
String payload = http.getString();
Serial.print("context:");
Serial.println(payload);
}
delay(2000);
}
}
void WifiInit()
{
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
}