Skip to content

Commit

Permalink
Web-AC-control: Add platformio support files & Travis checks (#886)
Browse files Browse the repository at this point in the history
* Add Web-AC-control.ino to Travis checks.
* Web-AC-control: Add platformio support files
* Add .platformio.ini file for example code
* Add support for ESP32.
* OTA update only available on ESP8266
  • Loading branch information
crankyoldgit committed Sep 11, 2019
1 parent d6750b9 commit 19766b1
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 6 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ jobs:
- arduino --verify --board $BD $PWD/examples/TurnOnFujitsuAC/TurnOnFujitsuAC.ino 2> /dev/null
- arduino --verify --board $BD $PWD/examples/TurnOnKelvinatorAC/TurnOnKelvinatorAC.ino 2> /dev/null
- arduino --verify --board $BD $PWD/examples/TurnOnMitsubishiAC/TurnOnMitsubishiAC.ino 2> /dev/null
- arduino --verify --board $BD $PWD/examples/Web-AC-control/Web-AC-control.ino 2> /dev/null
- script:
# Check that everything compiles. (Part 2)
- arduino --verify --board $BD $PWD/examples/IRsendProntoDemo/IRsendProntoDemo.ino 2> /dev/null
Expand Down
26 changes: 20 additions & 6 deletions examples/Web-AC-control/Web-AC-control.ino
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,20 @@
*/
#include <FS.h>
#if defined(ESP8266)
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ESP8266HTTPUpdateServer.h>
#include <ESP8266WebServer.h>
#endif // ESP8266
#if defined(ESP32)
#include <ESPmDNS.h>
#include <WebServer.h>
#include <WiFi.h>
#include <SPIFFS.h>
#include <Update.h>
#endif // ESP32
#include <WiFiUdp.h>
#include <WiFiManager.h>
#include <ArduinoJson.h>
#include <IRremoteESP8266.h>
Expand Down Expand Up @@ -40,7 +49,6 @@ IRCoolixAC ac(kIrLed);
/// ##### End user configuration ######



struct state {
uint8_t temperature = 22, fan = 0, operation = 0;
bool powerStatus;
Expand All @@ -55,9 +63,13 @@ state acState;
// settings
char deviceName[] = "AC Remote Control";

#if defined(ESP8266)
ESP8266WebServer server(80);
ESP8266HTTPUpdateServer httpUpdateServer;

#endif // ESP8266
#if defined(ESP32)
WebServer server(80);
#endif // ESP32

bool handleFileRead(String path) {
// send the right file to the client (if it exists)
Expand All @@ -73,7 +85,7 @@ bool handleFileRead(String path) {
path += ".gz"; // Use the compressed verion
File file = SPIFFS.open(path, "r");
// Open the file
size_t sent = server.streamFile(file, contentType);
server.streamFile(file, contentType);
// Send it to the client
file.close();
// Close the file again
Expand Down Expand Up @@ -160,12 +172,14 @@ void setup() {

if (!wifiManager.autoConnect(deviceName)) {
delay(3000);
ESP.reset();
ESP.restart();
delay(5000);
}


#if defined(ESP8266)
httpUpdateServer.setup(&server);
#endif // ESP8266



Expand Down Expand Up @@ -270,7 +284,7 @@ void setup() {
server.on("/reset", []() {
server.send(200, "text/html", "reset");
delay(100);
ESP.reset();
ESP.restart();
});

server.serveStatic("/", SPIFFS, "/", "max-age=86400");
Expand Down
37 changes: 37 additions & 0 deletions examples/Web-AC-control/platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[platformio]
src_dir = .

[env]
lib_extra_dirs = ../../
lib_ldf_mode = deep+
lib_ignore = examples
build_flags =

[common]
lib_deps_builtin =
lib_deps_external =
ArduinoJson@>=6.0

[common_esp8266]
lib_deps_external =
${common.lib_deps_builtin}
${common.lib_deps_external}
WifiManager@>=0.14

[common_esp32]
lib_deps_external =
${common.lib_deps_builtin}
${common.lib_deps_external}
https://github.com/tzapu/WiFiManager.git#development

[env:nodemcuv2]
platform = espressif8266
framework = arduino
board = nodemcuv2
lib_deps = ${common_esp8266.lib_deps_external}

[env:esp32dev]
platform = espressif32
framework = arduino
board = esp32dev
lib_deps = ${common_esp32.lib_deps_external}

0 comments on commit 19766b1

Please sign in to comment.