Created
July 28, 2019 06:54
-
-
Save yutokun/e8a366e7eed08c8c531cc3d5f5ab8b88 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
echo file_get_contents("command.txt"); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ESP8266WiFi.h> | |
#include <ESP8266HTTPClient.h> | |
// Network | |
const char *ssid = "Your SSID Here"; | |
const char *pswd = "Your Password Here"; | |
const char *commandIOPath = "http://withoutssl.yutokun.com/ac-switcher/command-io-test.php"; | |
void setup() | |
{ | |
pinMode(LED_BUILTIN, OUTPUT); | |
Serial.begin(115200, SERIAL_8N1); | |
while (!Serial) | |
delay(50); | |
ConnectToWiFi(); | |
digitalWrite(LED_BUILTIN, HIGH); | |
} | |
void ConnectToWiFi() | |
{ | |
WiFi.mode(WIFI_STA); | |
WiFi.begin(ssid, pswd); | |
Serial.println(); | |
Serial.println("Connecting to Wi-Fi..."); | |
while (WiFi.status() != WL_CONNECTED) | |
{ | |
Serial.print("."); | |
delay(1000); | |
} | |
Serial.println("Connected."); | |
Serial.print("IP Address: "); | |
Serial.println(WiFi.localIP()); | |
} | |
void loop() | |
{ | |
String command = GET(commandIOPath); | |
Serial.println(); | |
Serial.println("Received: " + command); | |
for (size_t i = 0; i < 3; i++) | |
delay(1000); | |
} | |
String GET(const char *host) | |
{ | |
HTTPClient http; | |
http.begin(host); | |
int httpCode = http.GET(); | |
String result = ""; | |
if (httpCode < 0) | |
{ | |
result = http.errorToString(httpCode); | |
} | |
else if (http.getSize() < 0) | |
{ | |
result = "size is invalid"; | |
} | |
else | |
{ | |
result = http.getString(); | |
} | |
http.end(); | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment