add OTA update & debug env
This commit is contained in:
parent
782fe8cf04
commit
69611e8bfd
@ -8,6 +8,12 @@
|
||||
; Please visit documentation for the other options and examples
|
||||
; https://docs.platformio.org/page/projectconf.html
|
||||
|
||||
[common_env_data]
|
||||
build_flags = '-D BUILD_VERSION="0.8.2*"'
|
||||
|
||||
[platformio]
|
||||
default_envs = esp12e
|
||||
|
||||
[env:esp12e]
|
||||
platform = espressif8266
|
||||
board = esp12e
|
||||
@ -18,3 +24,18 @@ lib_deps =
|
||||
ropg/ezTime@^0.8.3
|
||||
paulstoffregen/OneWire@^2.3.7
|
||||
milesburton/DallasTemperature@^3.11.0
|
||||
build_flags = ${common_env_data.build_flags}
|
||||
-D BUILD_DEBUG=0
|
||||
|
||||
[env:esp12e_debug]
|
||||
extends = env:esp12e
|
||||
build_type = debug
|
||||
build_flags = ${common_env_data.build_flags}
|
||||
-D BUILD_DEBUG=1
|
||||
|
||||
[env:esp12e_ota]
|
||||
extends = env:esp12e
|
||||
upload_protocol = espota
|
||||
upload_port = 192.168.2.4
|
||||
build_flags = ${common_env_data.build_flags}
|
||||
-D BUILD_DEBUG=0
|
||||
|
@ -6,9 +6,7 @@
|
||||
#include <ESP8266WebServer.h>
|
||||
#include <ezTime.h>
|
||||
|
||||
#define DEBUG 1 // 1 for development, 0 for production
|
||||
|
||||
#if DEBUG == 1
|
||||
#if BUILD_DEBUG == 1
|
||||
#define debug(debugMSG...) Serial.print(debugMSG)
|
||||
#define debugln(debugMSG...) Serial.println(debugMSG)
|
||||
#else
|
||||
|
47
src/main.cpp
47
src/main.cpp
@ -1,9 +1,9 @@
|
||||
const char SSID[] = "";
|
||||
const char PASSWORD[] = "";
|
||||
|
||||
const char version[] = " 0.8.3";
|
||||
#include "globalvars.h"
|
||||
#include <Arduino.h>
|
||||
#include <ArduinoOTA.h>
|
||||
#include <DallasTemperature.h>
|
||||
#include <EEPROM.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
@ -299,40 +299,58 @@ void setup() {
|
||||
Serial.begin(74880);
|
||||
EEPROM.begin(264); // 4 bits for EEPROM, address 0-263, value 0-255
|
||||
sensors.begin();
|
||||
debug(F("\nver."));
|
||||
debugln(version);
|
||||
debug(F("\nver. "));
|
||||
debug(BUILD_VERSION);
|
||||
debugln(BUILD_DEBUG ? "-debug" : "");
|
||||
debugln(F("check for updates at "
|
||||
"https://somepi.ddns.net/gitea/gilex-dev/ESP8266-IOT-timer/\n"));
|
||||
load_EEPROM();
|
||||
// WLAN-config
|
||||
// ---------------------------------------------------------------------------------------------------------------------
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.config(staticIP, gateway, subnet, dns);
|
||||
|
||||
// WiFI-config
|
||||
// WiFi.mode(WIFI_STA); // comment to force use of staticIP
|
||||
WiFi.hostname("ESP8266 IOT development");
|
||||
WiFi.config(staticIP, gateway, subnet, dns);
|
||||
WiFi.begin(SSID, PASSWORD);
|
||||
|
||||
debugln(F("Connecting ..."));
|
||||
uint32_t notConnectedCounter = 0;
|
||||
debug(F("Connecting "));
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
delay(250);
|
||||
debug('.');
|
||||
debug(F("."));
|
||||
notConnectedCounter++;
|
||||
if (notConnectedCounter >
|
||||
(1000 / 250) * 15) { // Reset board if not connected after 15s
|
||||
debugln("\nResetting due to Wifi not connecting");
|
||||
ESP.restart();
|
||||
}
|
||||
}
|
||||
debug(F("\nConnected to "));
|
||||
debugln(WiFi.SSID());
|
||||
debug(F("IP address: "));
|
||||
debugln(WiFi.localIP());
|
||||
//----------------------------------------------------------------------------------------------------------------------------------
|
||||
myTime.setLocation("de");
|
||||
waitForSync();
|
||||
ArduinoOTA.begin();
|
||||
|
||||
// Time-config
|
||||
myTime.setLocation("de");
|
||||
// setServer("192.168.2.1"); // uncomment to set custom NTP server
|
||||
if (!waitForSync(5000)) {
|
||||
debugln("\nResetting due to NTP not syncing");
|
||||
ESP.restart();
|
||||
}
|
||||
debug(F("Local time: "));
|
||||
debugln(myTime.dateTime("H:i:s"));
|
||||
setInterval();
|
||||
|
||||
// Server-config
|
||||
server.on("/", HTTP_GET, handleHome);
|
||||
server.on("/settings", HTTP_GET, handleSettings);
|
||||
server.on("/settings", HTTP_POST, handleTime);
|
||||
server.on("/toggle", HTTP_GET, handleToggle);
|
||||
server.on("/version", HTTP_GET,
|
||||
[] { server.send(200, "text/html", version); });
|
||||
server.on("/version", HTTP_GET, [] {
|
||||
server.send(200, "text/html",
|
||||
BUILD_VERSION + BUILD_DEBUG ? "-debug" : "");
|
||||
});
|
||||
|
||||
getCurrentTemperatur();
|
||||
server.begin();
|
||||
debugln(F("Webserver started"));
|
||||
@ -344,4 +362,5 @@ void loop() {
|
||||
timer();
|
||||
yield();
|
||||
delay(50);
|
||||
ArduinoOTA.handle();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user