Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add KNX_IP_DISABLE_WEBSERVER and KNX_IP_DISABLE_EEPROM #74

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions esp-knx-ip-webserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "esp-knx-ip.h"

#ifndef KNX_IP_DISABLE_WEBSERVER
void ESPKNXIP::__handle_root()
{
String m = F("<html><head><meta charset='utf-8'><meta name='viewport' content='width=device-width, initial-scale=1, shrink-to-fit=no'>");
Expand Down Expand Up @@ -522,3 +523,4 @@ void ESPKNXIP::__handle_eeprom()
server->send(302);
}
#endif
#endif
21 changes: 21 additions & 0 deletions esp-knx-ip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@
* License: MIT
*/

#ifdef KNX_IP_DISABLE_EEPROM
#define DISABLE_EEPROM_BUTTONS 1
#endif
#include "esp-knx-ip.h"

#ifndef KNX_IP_DISABLE_WEBSERVER
ESPKNXIP::ESPKNXIP() : server(nullptr), registered_callback_assignments(0), registered_callbacks(0), registered_configs(0), registered_feedbacks(0)
#else
ESPKNXIP::ESPKNXIP() : registered_callback_assignments(0), registered_callbacks(0), registered_configs(0), registered_feedbacks(0)
#endif
{
DEBUG_PRINTLN();
DEBUG_PRINTLN("ESPKNXIP starting up");
Expand All @@ -23,24 +30,31 @@ ESPKNXIP::ESPKNXIP() : server(nullptr), registered_callback_assignments(0), regi
void ESPKNXIP::load()
{
memcpy(custom_config_default_data, custom_config_data, MAX_CONFIG_SPACE);
#ifndef KNX_IP_DISABLE_EEPROM
EEPROM.begin(EEPROM_SIZE);
restore_from_eeprom();
#endif
}

#ifndef KNX_IP_DISABLE_WEBSERVER
void ESPKNXIP::start(ESP8266WebServer *srv)
{
server = srv;
__start();
}
#endif

void ESPKNXIP::start()
{
#ifndef KNX_IP_DISABLE_WEBSERVER
server = new ESP8266WebServer(80);
#endif
__start();
}

void ESPKNXIP::__start()
{
#ifndef KNX_IP_DISABLE_WEBSERVER
if (server != nullptr)
{
server->on(ROOT_PREFIX, [this](){
Expand Down Expand Up @@ -82,9 +96,11 @@ void ESPKNXIP::__start()
server->begin();
}

#endif
udp.beginMulticast(WiFi.localIP(), MULTICAST_IP, MULTICAST_PORT);
}

#ifndef KNX_IP_DISABLE_EEPROM
void ESPKNXIP::save_to_eeprom()
{
uint32_t address = 0;
Expand Down Expand Up @@ -174,6 +190,7 @@ void ESPKNXIP::restore_from_eeprom()
DEBUG_PRINT("Restored from EEPROM: 0x");
DEBUG_PRINTLN(address, HEX);
}
#endif

uint16_t ESPKNXIP::__ntohs(uint16_t n)
{
Expand Down Expand Up @@ -333,15 +350,19 @@ feedback_id_t ESPKNXIP::feedback_register_action(String name, feedback_action_fp
void ESPKNXIP::loop()
{
__loop_knx();
#ifndef KNX_IP_DISABLE_WEBSERVER
if (server != nullptr)
{
__loop_webserver();
}
#endif
}

void ESPKNXIP::__loop_webserver()
{
#ifndef KNX_IP_DISABLE_WEBSERVER
server->handleClient();
#endif
}

void ESPKNXIP::__loop_knx()
Expand Down
8 changes: 7 additions & 1 deletion esp-knx-ip.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#define SEND_CHECKSUM 0

// Uncomment to enable printing out debug messages.
#define ESP_KNX_DEBUG
// #define ESP_KNX_DEBUG
/**
* END CONFIG
*/
Expand All @@ -46,7 +46,9 @@
#include <EEPROM.h>
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#ifndef KNX_IP_DISABLE_WEBSERVER
#include <ESP8266WebServer.h>
#endif

#include "DPT.h"

Expand Down Expand Up @@ -358,7 +360,9 @@ class ESPKNXIP {
ESPKNXIP();
void load();
void start();
#ifndef KNX_IP_DISABLE_WEBSERVER
void start(ESP8266WebServer *srv);
#endif
void loop();

void save_to_eeprom();
Expand Down Expand Up @@ -515,7 +519,9 @@ class ESPKNXIP {
callback_assignment_id_t __callback_register_assignment(address_t address, callback_id_t id);
void __callback_delete_assignment(callback_assignment_id_t id);

#ifndef KNX_IP_DISABLE_WEBSERVER
ESP8266WebServer *server;
#endif
address_t physaddr;
WiFiUDP udp;

Expand Down