Compare commits
No commits in common. "a5300f34e6dcd36f977430bb2c56bf447ac1c228" and "0625a098dad3729457adfb17eba411c36600c8cf" have entirely different histories.
a5300f34e6
...
0625a098da
|
|
@ -1,2 +0,0 @@
|
|||
#define BUTTONPIN 22 // 22/GPIO22
|
||||
#define BOARD "ESP32"
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
#define BUTTONPIN 14 // D5/GPIO14
|
||||
#define BOARD "ESP8266"
|
||||
|
|
@ -8,38 +8,13 @@
|
|||
; Please visit documentation for the other options and examples
|
||||
; https://docs.platformio.org/page/projectconf.html
|
||||
|
||||
[platformio]
|
||||
default_envs = esp32doit-devkit-v1
|
||||
;default_envs = nodemcuv2
|
||||
|
||||
[common]
|
||||
build_flags =
|
||||
-D DEBUG=false
|
||||
|
||||
[env:esp32doit-devkit-v1]
|
||||
platform = espressif32
|
||||
board = esp32doit-devkit-v1
|
||||
framework = arduino
|
||||
monitor_speed = 115200
|
||||
upload_protocol = espota
|
||||
upload_port = 192.168.2.221
|
||||
;upload_port = COM6
|
||||
build_flags =
|
||||
${common.build_flags}
|
||||
upload_port = 192.168.2.232
|
||||
lib_compat_mode = strict
|
||||
lib_deps =
|
||||
tzapu/WiFiManager@^2.0.17
|
||||
|
||||
[env:nodemcuv2]
|
||||
platform = https://github.com/platformio/platform-espressif8266.git
|
||||
board = nodemcuv2
|
||||
framework = arduino
|
||||
upload_protocol = espota
|
||||
upload_port = 192.168.2.238
|
||||
;upload_port = COM6
|
||||
upload_speed = 115200
|
||||
monitor_speed = 115200
|
||||
build_flags =
|
||||
${common.build_flags}
|
||||
lib_deps =
|
||||
tzapu/WiFiManager@^2.0.17
|
||||
|
|
|
|||
45
src/main.cpp
45
src/main.cpp
|
|
@ -1,50 +1,40 @@
|
|||
#include <Arduino.h>
|
||||
#include <WiFiManager.h>
|
||||
#include <WiFi.h>
|
||||
#include <HTTPClient.h>
|
||||
#include <ArduinoOTA.h>
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
#include <esp32.h>
|
||||
#include <WiFi.h>
|
||||
#include <HTTPClient.h>
|
||||
#elif defined(ARDUINO_ARCH_ESP8266)
|
||||
#include <esp8266.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESP8266HTTPClient.h>
|
||||
#endif
|
||||
|
||||
#define BOARDFIRMWARE "2.5"
|
||||
|
||||
#define BUTTONPIN 22
|
||||
#define DEBOUNCEMS 15
|
||||
#define BOARD "ESP32"
|
||||
#define SERVICE "LEDsActionButton"
|
||||
#define STATUSINTERVAL 600000 // 10 minutes
|
||||
#define STATUSINTERVAL 600000
|
||||
|
||||
String hostAddress = "moon.basement.lan";
|
||||
const char hostAddress[] = "moon.basement.lan";
|
||||
unsigned int hostPort = 80;
|
||||
String actionURL = "/l/actionbutton.php?state=";
|
||||
String statusURL = "/l/boardstatus.php";
|
||||
|
||||
String actionURL = "http://moon.basement.lan/l/actionbutton.php?state=";
|
||||
String statusURL = "http://moon.basement.lan/l/boardstatus.php";
|
||||
unsigned short buttonState = HIGH, lastButtonState = HIGH;
|
||||
unsigned long lastStatusTime = 0;
|
||||
|
||||
void sendActionMessage(bool state) {
|
||||
if ( DEBUG ) Serial.println("Action button triggered");
|
||||
String msgURL = actionURL + (state ? "true" : "false");
|
||||
Serial.println("Action button triggered");
|
||||
char webMsg[255] = "";
|
||||
strcat(webMsg, actionURL.c_str());
|
||||
strcat(webMsg, (state) ? "true" : "false");
|
||||
HTTPClient http;
|
||||
if ( BOARD == "ESP32" ) {
|
||||
msgURL = "http://" + hostAddress + ":" + String(hostPort) + msgURL;
|
||||
http.begin(msgURL.c_str());
|
||||
} else {
|
||||
WiFiClient client;
|
||||
http.begin(client, hostAddress.c_str(), hostPort, msgURL.c_str());
|
||||
}
|
||||
http.begin(webMsg);
|
||||
http.GET();
|
||||
http.end();
|
||||
}
|
||||
|
||||
unsigned long sendDeviceStatus() {
|
||||
if ( DEBUG ) Serial.println("Sending device status");
|
||||
Serial.println("Sending device status");
|
||||
WiFiClient client;
|
||||
HTTPClient http;
|
||||
http.begin(client, ("http://" + hostAddress + ":" + String(hostPort) + statusURL).c_str());
|
||||
http.begin(client, statusURL.c_str());
|
||||
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
String httpData = "mac=" + WiFi.macAddress() + "&board=" + BOARD + "&firmware=" + BOARDFIRMWARE + "&service=" + SERVICE;
|
||||
int httpResponseCode = http.POST(httpData);
|
||||
|
|
@ -55,7 +45,7 @@ unsigned long sendDeviceStatus() {
|
|||
void setup() {
|
||||
Serial.begin(115200);
|
||||
pinMode(BUTTONPIN, INPUT_PULLUP);
|
||||
if ( DEBUG ) Serial.println("MAC Address: " + WiFi.macAddress());
|
||||
Serial.println("MAC Address: " + WiFi.macAddress());
|
||||
WiFiManager wifiManager;
|
||||
wifiManager.autoConnect("LEDsActionButton");
|
||||
lastStatusTime = sendDeviceStatus();
|
||||
|
|
@ -69,6 +59,9 @@ void loop() {
|
|||
if ( millis() > (lastStatusTime + STATUSINTERVAL) ) {
|
||||
lastStatusTime = sendDeviceStatus();
|
||||
}
|
||||
if ( millis() > 86400000 ) {
|
||||
ESP.restart();
|
||||
}
|
||||
unsigned short buttonCheck = digitalRead(BUTTONPIN);
|
||||
if ( buttonCheck != lastButtonState ) {
|
||||
debouncing = true;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user