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
|
; Please visit documentation for the other options and examples
|
||||||
; https://docs.platformio.org/page/projectconf.html
|
; https://docs.platformio.org/page/projectconf.html
|
||||||
|
|
||||||
|
[common_env_data]
|
||||||
|
build_flags = '-D BUILD_VERSION="0.8.2*"'
|
||||||
|
|
||||||
|
[platformio]
|
||||||
|
default_envs = esp12e
|
||||||
|
|
||||||
[env:esp12e]
|
[env:esp12e]
|
||||||
platform = espressif8266
|
platform = espressif8266
|
||||||
board = esp12e
|
board = esp12e
|
||||||
|
@ -18,3 +24,18 @@ lib_deps =
|
||||||
ropg/ezTime@^0.8.3
|
ropg/ezTime@^0.8.3
|
||||||
paulstoffregen/OneWire@^2.3.7
|
paulstoffregen/OneWire@^2.3.7
|
||||||
milesburton/DallasTemperature@^3.11.0
|
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 <ESP8266WebServer.h>
|
||||||
#include <ezTime.h>
|
#include <ezTime.h>
|
||||||
|
|
||||||
#define DEBUG 1 // 1 for development, 0 for production
|
#if BUILD_DEBUG == 1
|
||||||
|
|
||||||
#if DEBUG == 1
|
|
||||||
#define debug(debugMSG...) Serial.print(debugMSG)
|
#define debug(debugMSG...) Serial.print(debugMSG)
|
||||||
#define debugln(debugMSG...) Serial.println(debugMSG)
|
#define debugln(debugMSG...) Serial.println(debugMSG)
|
||||||
#else
|
#else
|
||||||
|
|
47
src/main.cpp
47
src/main.cpp
|
@ -1,9 +1,9 @@
|
||||||
const char SSID[] = "";
|
const char SSID[] = "";
|
||||||
const char PASSWORD[] = "";
|
const char PASSWORD[] = "";
|
||||||
|
|
||||||
const char version[] = " 0.8.3";
|
|
||||||
#include "globalvars.h"
|
#include "globalvars.h"
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
#include <ArduinoOTA.h>
|
||||||
#include <DallasTemperature.h>
|
#include <DallasTemperature.h>
|
||||||
#include <EEPROM.h>
|
#include <EEPROM.h>
|
||||||
#include <ESP8266WebServer.h>
|
#include <ESP8266WebServer.h>
|
||||||
|
@ -299,40 +299,58 @@ void setup() {
|
||||||
Serial.begin(74880);
|
Serial.begin(74880);
|
||||||
EEPROM.begin(264); // 4 bits for EEPROM, address 0-263, value 0-255
|
EEPROM.begin(264); // 4 bits for EEPROM, address 0-263, value 0-255
|
||||||
sensors.begin();
|
sensors.begin();
|
||||||
debug(F("\nver."));
|
debug(F("\nver. "));
|
||||||
debugln(version);
|
debug(BUILD_VERSION);
|
||||||
|
debugln(BUILD_DEBUG ? "-debug" : "");
|
||||||
debugln(F("check for updates at "
|
debugln(F("check for updates at "
|
||||||
"https://somepi.ddns.net/gitea/gilex-dev/ESP8266-IOT-timer/\n"));
|
"https://somepi.ddns.net/gitea/gilex-dev/ESP8266-IOT-timer/\n"));
|
||||||
load_EEPROM();
|
load_EEPROM();
|
||||||
// WLAN-config
|
|
||||||
// ---------------------------------------------------------------------------------------------------------------------
|
// WiFI-config
|
||||||
WiFi.mode(WIFI_STA);
|
// WiFi.mode(WIFI_STA); // comment to force use of staticIP
|
||||||
WiFi.config(staticIP, gateway, subnet, dns);
|
|
||||||
WiFi.hostname("ESP8266 IOT development");
|
WiFi.hostname("ESP8266 IOT development");
|
||||||
|
WiFi.config(staticIP, gateway, subnet, dns);
|
||||||
WiFi.begin(SSID, PASSWORD);
|
WiFi.begin(SSID, PASSWORD);
|
||||||
|
|
||||||
debugln(F("Connecting ..."));
|
uint32_t notConnectedCounter = 0;
|
||||||
|
debug(F("Connecting "));
|
||||||
while (WiFi.status() != WL_CONNECTED) {
|
while (WiFi.status() != WL_CONNECTED) {
|
||||||
delay(250);
|
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 "));
|
debug(F("\nConnected to "));
|
||||||
debugln(WiFi.SSID());
|
debugln(WiFi.SSID());
|
||||||
debug(F("IP address: "));
|
debug(F("IP address: "));
|
||||||
debugln(WiFi.localIP());
|
debugln(WiFi.localIP());
|
||||||
//----------------------------------------------------------------------------------------------------------------------------------
|
ArduinoOTA.begin();
|
||||||
myTime.setLocation("de");
|
|
||||||
waitForSync();
|
|
||||||
|
|
||||||
|
// 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: "));
|
debug(F("Local time: "));
|
||||||
debugln(myTime.dateTime("H:i:s"));
|
debugln(myTime.dateTime("H:i:s"));
|
||||||
setInterval();
|
setInterval();
|
||||||
|
|
||||||
|
// Server-config
|
||||||
server.on("/", HTTP_GET, handleHome);
|
server.on("/", HTTP_GET, handleHome);
|
||||||
server.on("/settings", HTTP_GET, handleSettings);
|
server.on("/settings", HTTP_GET, handleSettings);
|
||||||
server.on("/settings", HTTP_POST, handleTime);
|
server.on("/settings", HTTP_POST, handleTime);
|
||||||
server.on("/toggle", HTTP_GET, handleToggle);
|
server.on("/toggle", HTTP_GET, handleToggle);
|
||||||
server.on("/version", HTTP_GET,
|
server.on("/version", HTTP_GET, [] {
|
||||||
[] { server.send(200, "text/html", version); });
|
server.send(200, "text/html",
|
||||||
|
BUILD_VERSION + BUILD_DEBUG ? "-debug" : "");
|
||||||
|
});
|
||||||
|
|
||||||
getCurrentTemperatur();
|
getCurrentTemperatur();
|
||||||
server.begin();
|
server.begin();
|
||||||
debugln(F("Webserver started"));
|
debugln(F("Webserver started"));
|
||||||
|
@ -344,4 +362,5 @@ void loop() {
|
||||||
timer();
|
timer();
|
||||||
yield();
|
yield();
|
||||||
delay(50);
|
delay(50);
|
||||||
|
ArduinoOTA.handle();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue