Skip to content

Instantly share code, notes, and snippets.

@yutokun
Created July 28, 2019 06:54
Show Gist options
  • Save yutokun/e8a366e7eed08c8c531cc3d5f5ab8b88 to your computer and use it in GitHub Desktop.
Save yutokun/e8a366e7eed08c8c531cc3d5f5ab8b88 to your computer and use it in GitHub Desktop.
<?php
echo file_get_contents("command.txt");
?>
#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