Skip to content

Commit

Permalink
Option to remove API_SUPPORT at build time
Browse files Browse the repository at this point in the history
  • Loading branch information
xoseperez committed Aug 16, 2018
1 parent b497cc8 commit 4f61d3a
Show file tree
Hide file tree
Showing 24 changed files with 15,063 additions and 15,017 deletions.
5 changes: 3 additions & 2 deletions code/espurna/api.ino
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Copyright (C) 2016-2018 by Xose Pérez <xose dot perez at gmail dot com>
*/

#if WEB_SUPPORT
#if API_SUPPORT

#include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h>
Expand All @@ -27,6 +27,7 @@ bool _apiWebSocketOnReceive(const char * key, JsonVariant& value) {
}

void _apiWebSocketOnSend(JsonObject& root) {
root["apiVisible"] = 1;
root["apiEnabled"] = getSetting("apiEnabled", API_ENABLED).toInt() == 1;
root["apiKey"] = getSetting("apiKey");
root["apiRealTime"] = getSetting("apiRealTime", API_REAL_TIME_VALUES).toInt() == 1;
Expand Down Expand Up @@ -216,4 +217,4 @@ void apiSetup() {
webRequestRegister(_apiRequestCallback);
}

#endif // WEB_SUPPORT
#endif // API_SUPPORT
9 changes: 7 additions & 2 deletions code/espurna/config/arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@
//--------------------------------------------------------------------------------

//#define ALEXA_SUPPORT 0
//#define API_SUPPORT 0
//#define BROKER_SUPPORT 0
//#define BUTTON_SUPPORT 0
//#define DEBUG_SERIAL_SUPPORT 0
//#define DEBUG_TELNET_SUPPORT 0
//#define DEBUG_UDP_SUPPORT 1
Expand All @@ -107,15 +109,18 @@
//#define I2C_SUPPORT 1
//#define INFLUXDB_SUPPORT 1
//#define IR_SUPPORT 1
//#define LED_SUPPORT 0
//#define LLMNR_SUPPORT 1 // Only with Arduino Core 2.4.0
//#define MDNS_SERVER_SUPPORT 0
//#define MDNS_CLIENT_SUPPORT 1
//#define MDNS_SERVER_SUPPORT 0
//#define MQTT_SUPPORT 0
//#define NETBIOS_SUPPORT 1 // Only with Arduino Core 2.4.0
//#define NOFUSS_SUPPORT 1
//#define NTP_SUPPORT 0
//#define RFM69_SUPPORT 1
//#define RF_SUPPORT 1
//#define SCHEDULER_SUPPORT 0
//#define SENSOR_SUPPORT 1
//#define SPIFFS_SUPPORT 1
//#define SSDP_SUPPORT 1
//#define TELNET_SUPPORT 0
Expand All @@ -141,6 +146,7 @@
//#define EMON_ADS1X15_SUPPORT 1
//#define EMON_ANALOG_SUPPORT 1
//#define EVENTS_SUPPORT 1
//#define GEIGER_SUPPORT 1
//#define GUVAS12SD_SUPPORT 1
//#define HLW8012_SUPPORT 1
//#define MHZ19_SUPPORT 1
Expand All @@ -152,4 +158,3 @@
//#define SONAR_SUPPORT 1
//#define TMP3X_SUPPORT 1
//#define V9261F_SUPPORT 1
//#define GEIGER_SUPPORT 1
5 changes: 5 additions & 0 deletions code/espurna/config/dependencies.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
#define DEBUG_WEB_SUPPORT 0
#endif

#if not WEB_SUPPORT
#undef API_SUPPORT
#define API_SUPPORT 0 // API support requires web support
#endif

#if not WEB_SUPPORT
#undef SSDP_SUPPORT
#define SSDP_SUPPORT 0 // SSDP support requires web support
Expand Down
4 changes: 4 additions & 0 deletions code/espurna/config/general.h
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,10 @@
// API
// -----------------------------------------------------------------------------

#ifndef API_SUPPORT
#define API_SUPPORT 1 // API (REST & RPC) support built in
#endif

// This will only be enabled if WEB_SUPPORT is 1 (this is the default value)
#ifndef API_ENABLED
#define API_ENABLED 0 // Do not enable API by default
Expand Down
2 changes: 1 addition & 1 deletion code/espurna/config/hardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@
// the port and remove UART noise on serial line
#if not RFB_DIRECT
#define SERIAL_BAUDRATE 19200
#define DEBUG_SERIAL_SUPPORT 0
//#define DEBUG_SERIAL_SUPPORT 0
#endif

#elif defined(ITEAD_SONOFF_B1)
Expand Down
27 changes: 18 additions & 9 deletions code/espurna/config/progmem.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,15 @@ PROGMEM const char espurna_modules[] =
#if ALEXA_SUPPORT
"ALEXA "
#endif
#if API_SUPPORT
"API "
#endif
#if BROKER_SUPPORT
"BROKER "
#endif
#if BUTTON_SUPPORT
"BUTTON "
#endif
#if DEBUG_SERIAL_SUPPORT
"DEBUG_SERIAL "
#endif
Expand Down Expand Up @@ -61,15 +67,18 @@ PROGMEM const char espurna_modules[] =
#if IR_SUPPORT
"IR "
#endif
#if LED_SUPPORT
"LED "
#endif
#if LLMNR_SUPPORT
"LLMNR "
#endif
#if MDNS_SERVER_SUPPORT
"MDNS_SERVER "
#endif
#if MDNS_CLIENT_SUPPORT
"MDNS_CLIENT "
#endif
#if MDNS_SERVER_SUPPORT
"MDNS_SERVER "
#endif
#if MQTT_SUPPORT
"MQTT "
#endif
Expand All @@ -82,12 +91,12 @@ PROGMEM const char espurna_modules[] =
#if NTP_SUPPORT
"NTP "
#endif
#if RF_SUPPORT
"RF "
#endif
#if RFM69_SUPPORT
"RFM69 "
#endif
#if RF_SUPPORT
"RF "
#endif
#if SCHEDULER_SUPPORT
"SCHEDULER "
#endif
Expand Down Expand Up @@ -169,9 +178,6 @@ PROGMEM const char espurna_sensors[] =
#if GUVAS12SD_SUPPORT
"GUVAS12SD "
#endif
#if SONAR_SUPPORT
"SONAR "
#endif
#if HLW8012_SUPPORT
"HLW8012 "
#endif
Expand All @@ -196,6 +202,9 @@ PROGMEM const char espurna_sensors[] =
#if SI7021_SUPPORT
"SI7021 "
#endif
#if SONAR_SUPPORT
"SONAR "
#endif
#if TMP3X_SUPPORT
"TMP3X "
#endif
Expand Down
2 changes: 1 addition & 1 deletion code/espurna/config/sensors.h
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@

//------------------------------------------------------------------------------
// SHT3X I2C (Wemos) temperature & humidity sensor
// Enable support by passing SHT3X_SUPPORT=1 build flag
// Enable support by passing SHT3X_I2C_SUPPORT=1 build flag
//------------------------------------------------------------------------------

#ifndef SHT3X_I2C_SUPPORT
Expand Down
Binary file modified code/espurna/data/index.all.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.light.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.rfbridge.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.rfm69.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.sensor.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.small.html.gz
Binary file not shown.
4 changes: 3 additions & 1 deletion code/espurna/espurna.ino
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,13 @@ void setup() {
#if WEB_SUPPORT
webSetup();
wsSetup();
apiSetup();
#if DEBUG_WEB_SUPPORT
debugWebSetup();
#endif
#endif
#if API_SUPPORT
apiSetup();
#endif

// lightSetup must be called before relaySetup
#if LIGHT_PROVIDER != LIGHT_PROVIDER_NONE
Expand Down
13 changes: 10 additions & 3 deletions code/espurna/light.ino
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ void _fromHSV(const char * hsv) {
void _fromKelvin(unsigned long kelvin) {

if (!_light_has_color) return;

_light_mireds = constrain(round(1000000UL / kelvin), LIGHT_MIN_MIREDS, LIGHT_MAX_MIREDS);

if (_light_use_cct) {
Expand Down Expand Up @@ -826,6 +826,10 @@ void _lightWebSocketOnAction(uint32_t client_id, const char * action, JsonObject
}
}

#endif

#if API_SUPPORT

void _lightAPISetup() {
// API entry points (protected with apikey)
if (_light_has_color) {
Expand Down Expand Up @@ -896,7 +900,7 @@ void _lightAPISetup() {
}
}

#endif // WEB_SUPPORT
#endif // API_SUPPORT

#if TERMINAL_SUPPORT

Expand Down Expand Up @@ -1069,7 +1073,6 @@ void lightSetup() {
_lightColorRestore();

#if WEB_SUPPORT
_lightAPISetup();
wsOnSendRegister(_lightWebSocketOnSend);
wsOnActionRegister(_lightWebSocketOnAction);
wsOnReceiveRegister(_lightWebSocketOnReceive);
Expand All @@ -1081,6 +1084,10 @@ void lightSetup() {
});
#endif

#if API_SUPPORT
_lightAPISetup();
#endif

#if MQTT_SUPPORT
mqttRegister(_lightMQTTCallback);
#endif
Expand Down
8 changes: 5 additions & 3 deletions code/espurna/relay.ino
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ void relaySetupWS() {
// REST API
//------------------------------------------------------------------------------

#if WEB_SUPPORT
#if API_SUPPORT

void relaySetupAPI() {

Expand Down Expand Up @@ -700,7 +700,7 @@ void relaySetupAPI() {

}

#endif // WEB_SUPPORT
#endif // API_SUPPORT

//------------------------------------------------------------------------------
// MQTT
Expand Down Expand Up @@ -1007,9 +1007,11 @@ void relaySetup() {
espurnaRegisterLoop(_relayLoop);

#if WEB_SUPPORT
relaySetupAPI();
relaySetupWS();
#endif
#if API_SUPPORT
relaySetupAPI();
#endif
#if MQTT_SUPPORT
relaySetupMQTT();
#endif
Expand Down
16 changes: 11 additions & 5 deletions code/espurna/sensor.ino
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ void _sensorWebSocketStart(JsonObject& root) {

}

#endif // WEB_SUPPORT

#if API_SUPPORT

void _sensorAPISetup() {

for (unsigned char magnitude_id=0; magnitude_id<_magnitudes.size(); magnitude_id++) {
Expand All @@ -242,7 +246,8 @@ void _sensorAPISetup() {
}

}
#endif

#endif // API_SUPPORT

#if TERMINAL_SUPPORT

Expand Down Expand Up @@ -1027,19 +1032,20 @@ void sensorSetup() {
// Configure stored values
_sensorConfigure();

// Websockets
#if WEB_SUPPORT

// Websockets
wsOnSendRegister(_sensorWebSocketStart);
wsOnReceiveRegister(_sensorWebSocketOnReceive);
wsOnSendRegister(_sensorWebSocketSendData);
wsOnAfterParseRegister(_sensorConfigure);
#endif

// API
// API
#if API_SUPPORT
_sensorAPISetup();

#endif

// Terminal
#if TERMINAL_SUPPORT
_sensorInitCommands();
#endif
Expand Down
Loading

0 comments on commit 4f61d3a

Please sign in to comment.