mirror of
https://github.com/openshwprojects/OpenBK7231T_App.git
synced 2026-02-07 01:55:29 +00:00
Allow to disable more drivers and features in order to reduce binary size (#1500)
* Update obk_config.h * Update obk_config.h * shared * fx * he * fix * fx * ffff * F * T * tre * fcx * leeed * ww * w * fx * t * ENABLE_OLD_YAML_GENERATOR * w * startyuip[ * dis all * remove test post * ENABLE_HTTP_SEND * extra guard * ENABLE_TCP_COMMANDLINE * better OBK_DISABLE_ALL_DRIVERS * tr * ENABLE_PING_WATCHDOG * ENABLE_HA_DISCOVERY * TEST WITH EMPTY USER_MAIN * fx * no mqtt * nm * tr * ENABLE_MQTT * Update cmd_newLEDDriver.c * tr * header * fx * Update user_main.c * t * Update hal_main_bk7231.c * w * ENABLE_DRIVER_IR * RESTORE * fx * #warning "Platform not defined" * fx 1 * Update obk_config.h * ENABLE_DRIVER_TESTPOWER * DS1820 * fx * fx * enable DHT on W800 * Update Makefile * ntp w800 * ntp * ssdp * OWM AND CHARTS * why utils net has flash pub included * nmakefile only, no refs * makefile only * drv * Update Makefile * drcs * ENABLE_DRIVER_BMP280 * Update Makefile * d * ENABLE_I2C * Update Makefile * fin
This commit is contained in:
@ -6,6 +6,8 @@
|
||||
#include "../driver/drv_public.h"
|
||||
#include "../new_pins.h"
|
||||
|
||||
#if ENABLE_HA_DISCOVERY
|
||||
|
||||
/*
|
||||
Abbreviated node names - https://www.home-assistant.io/docs/mqtt/discovery/
|
||||
Light - https://www.home-assistant.io/integrations/light.mqtt/
|
||||
@ -367,6 +369,7 @@ HassDeviceInfo* hass_init_relay_device_info(int index, ENTITY_TYPE type, bool bT
|
||||
return info;
|
||||
}
|
||||
|
||||
#if ENABLE_LED_BASIC
|
||||
/// @brief Initializes HomeAssistant light device discovery storage.
|
||||
/// @param type
|
||||
/// @return
|
||||
@ -433,6 +436,7 @@ HassDeviceInfo* hass_init_light_device_info(ENTITY_TYPE type) {
|
||||
|
||||
return info;
|
||||
}
|
||||
#endif
|
||||
|
||||
/// @brief Initializes HomeAssistant binary sensor device discovery storage.
|
||||
/// @param index
|
||||
@ -758,3 +762,5 @@ void hass_free_device_info(HassDeviceInfo* info) {
|
||||
|
||||
os_free(info);
|
||||
}
|
||||
|
||||
#endif // ENABLE_HA_DISCOVERY
|
||||
|
||||
@ -1,5 +1,9 @@
|
||||
|
||||
#include "new_http.h"
|
||||
#include "../obk_config.h"
|
||||
|
||||
#if ENABLE_HA_DISCOVERY
|
||||
|
||||
#include "../cJSON/cJSON.h"
|
||||
#include "../new_pins.h"
|
||||
#include "../mqtt/new_mqtt.h"
|
||||
@ -128,3 +132,4 @@ const char* hass_build_discovery_json(HassDeviceInfo* info);
|
||||
void hass_free_device_info(HassDeviceInfo* info);
|
||||
char *hass_generate_multiplyAndRound_template(int decimalPlacesForRounding, int decimalPointOffset, int divider);
|
||||
|
||||
#endif // ENABLE_HA_DISCOVERY
|
||||
|
||||
@ -208,11 +208,16 @@ int http_fn_index(http_request_t* request) {
|
||||
if (DRV_IsRunning("SM16703P")) {
|
||||
bForceShowRGB = true;
|
||||
}
|
||||
else
|
||||
else
|
||||
#endif
|
||||
#if ENABLE_LED_BASIC
|
||||
if (LED_IsLedDriverChipRunning()) {
|
||||
bForceShowRGBCW = true;
|
||||
}
|
||||
#else
|
||||
{
|
||||
}
|
||||
#endif
|
||||
}
|
||||
http_setup(request, httpMimeTypeHTML); //Add mimetype regardless of the request
|
||||
|
||||
@ -246,6 +251,7 @@ int http_fn_index(http_request_t* request) {
|
||||
hprintf255(request, "<h3>Enabled %s!</h3>", CHANNEL_GetLabel(j));
|
||||
CHANNEL_Set(j, 255, 1);
|
||||
}
|
||||
#if ENABLE_LED_BASIC
|
||||
if (http_getArg(request->url, "rgb", tmpA, sizeof(tmpA))) {
|
||||
hprintf255(request, "<h3>Set RGB to %s!</h3>", tmpA);
|
||||
LED_SetBaseColor(0, "led_basecolor", tmpA, 0);
|
||||
@ -255,7 +261,7 @@ int http_fn_index(http_request_t* request) {
|
||||
LED_SetEnableAll(true);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
if (http_getArg(request->url, "off", tmpA, sizeof(tmpA))) {
|
||||
j = atoi(tmpA);
|
||||
hprintf255(request, "<h3>Disabled %s!</h3>", CHANNEL_GetLabel(j));
|
||||
@ -273,6 +279,7 @@ int http_fn_index(http_request_t* request) {
|
||||
}
|
||||
CHANNEL_Set(j, newPWMValue, 1);
|
||||
|
||||
#if ENABLE_LED_BASIC
|
||||
if (j == SPECIAL_CHANNEL_TEMPERATURE) {
|
||||
// auto enable - but only for changes made from WWW panel
|
||||
// This happens when users changes TEMPERATURE
|
||||
@ -280,6 +287,7 @@ int http_fn_index(http_request_t* request) {
|
||||
LED_SetEnableAll(true);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if (http_getArg(request->url, "dim", tmpA, sizeof(tmpA))) {
|
||||
int newDimmerValue = atoi(tmpA);
|
||||
@ -293,6 +301,7 @@ int http_fn_index(http_request_t* request) {
|
||||
}
|
||||
CHANNEL_Set(j, newDimmerValue, 1);
|
||||
|
||||
#if ENABLE_LED_BASIC
|
||||
if (j == SPECIAL_CHANNEL_BRIGHTNESS) {
|
||||
// auto enable - but only for changes made from WWW panel
|
||||
// This happens when users changes DIMMER
|
||||
@ -300,6 +309,7 @@ int http_fn_index(http_request_t* request) {
|
||||
LED_SetEnableAll(true);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if (http_getArg(request->url, "set", tmpA, sizeof(tmpA))) {
|
||||
int newSetValue = atoi(tmpA);
|
||||
@ -615,6 +625,7 @@ int http_fn_index(http_request_t* request) {
|
||||
}
|
||||
}
|
||||
|
||||
#if ENABLE_LED_BASIC
|
||||
if (bRawPWMs == 0 || bForceShowRGBCW || bForceShowRGB) {
|
||||
int c_pwms;
|
||||
int lm;
|
||||
@ -722,6 +733,7 @@ int http_fn_index(http_request_t* request) {
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
#if defined(PLATFORM_BEKEN) || defined(WINDOWS)
|
||||
if (DRV_IsRunning("PWMToggler")) {
|
||||
DRV_Toggler_AddToHtmlPage(request);
|
||||
@ -790,6 +802,7 @@ int http_fn_index(http_request_t* request) {
|
||||
hprintf255(request, "<h5>Chip temperature: %.1f°C</h5>", g_wifi_temperature);
|
||||
#endif
|
||||
|
||||
#if ENABLE_PING_WATCHDOG
|
||||
inputName = CFG_GetPingHost();
|
||||
if (inputName && *inputName && CFG_GetPingDisconnectedSecondsToRestart()) {
|
||||
hprintf255(request, "<h5>Ping watchdog (%s) - ", inputName);
|
||||
@ -801,6 +814,7 @@ int http_fn_index(http_request_t* request) {
|
||||
PingWatchDog_GetTotalLost(), PingWatchDog_GetTotalReceived(), g_timeSinceLastPingReply);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (Main_HasWiFiConnected())
|
||||
{
|
||||
int rssi = HAL_GetWifiStrength();
|
||||
@ -893,6 +907,7 @@ typedef enum {
|
||||
hprintf255(request, "<h5>Reboot reason: %i - %s</h5>", reset_reason, s);
|
||||
hprintf255(request, "<h5>Current fw: FW%i</h5>", current_fw_idx);
|
||||
#endif
|
||||
#if ENABLE_MQTT
|
||||
if (CFG_GetMQTTHost()[0] == 0) {
|
||||
hprintf255(request, "<h5>MQTT State: not configured<br>");
|
||||
}
|
||||
@ -917,6 +932,7 @@ typedef enum {
|
||||
hprintf255(request, "MQTT Stats:CONN: %d PUB: %d RECV: %d ERR: %d </h5>", MQTT_GetConnectEvents(),
|
||||
MQTT_GetPublishEventCounter(), MQTT_GetReceivedEventCounter(), MQTT_GetPublishErrorCounter());
|
||||
}
|
||||
#endif
|
||||
/* Format current PINS input state for all unused pins */
|
||||
if (CFG_HasFlag(OBK_FLAG_HTTP_PINMONITOR))
|
||||
{
|
||||
@ -1034,7 +1050,45 @@ int http_fn_about(http_request_t* request) {
|
||||
poststr(request, NULL);
|
||||
return 0;
|
||||
}
|
||||
#if ENABLE_HTTP_MQTT
|
||||
|
||||
int http_fn_cfg_mqtt_set(http_request_t* request) {
|
||||
char tmpA[128];
|
||||
http_setup(request, httpMimeTypeHTML);
|
||||
http_html_start(request, "Saving MQTT");
|
||||
|
||||
if (http_getArg(request->url, "host", tmpA, sizeof(tmpA))) {
|
||||
}
|
||||
// FIX: always set, so people can clear field
|
||||
CFG_SetMQTTHost(tmpA);
|
||||
if (http_getArg(request->url, "port", tmpA, sizeof(tmpA))) {
|
||||
CFG_SetMQTTPort(atoi(tmpA));
|
||||
}
|
||||
if (http_getArg(request->url, "user", tmpA, sizeof(tmpA))) {
|
||||
CFG_SetMQTTUserName(tmpA);
|
||||
}
|
||||
if (http_getArg(request->url, "password", tmpA, sizeof(tmpA))) {
|
||||
CFG_SetMQTTPass(tmpA);
|
||||
}
|
||||
if (http_getArg(request->url, "client", tmpA, sizeof(tmpA))) {
|
||||
CFG_SetMQTTClientId(tmpA);
|
||||
}
|
||||
if (http_getArg(request->url, "group", tmpA, sizeof(tmpA))) {
|
||||
CFG_SetMQTTGroupTopic(tmpA);
|
||||
}
|
||||
|
||||
CFG_Save_SetupTimer();
|
||||
|
||||
poststr(request, "Please wait for module to connect... if there is problem, restart it from Index html page...");
|
||||
#if ENABLE_MQTT
|
||||
g_mqtt_bBaseTopicDirty = 1;
|
||||
#endif
|
||||
poststr(request, "<br><a href=\"cfg_mqtt\">Return to MQTT settings</a><br>");
|
||||
poststr(request, htmlFooterReturnToCfgOrMainPage);
|
||||
http_html_end(request);
|
||||
poststr(request, NULL);
|
||||
return 0;
|
||||
}
|
||||
int http_fn_cfg_mqtt(http_request_t* request) {
|
||||
http_setup(request, httpMimeTypeHTML);
|
||||
http_html_start(request, "MQTT");
|
||||
@ -1057,7 +1111,8 @@ int http_fn_cfg_mqtt(http_request_t* request) {
|
||||
poststr(request, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
#if ENABLE_HTTP_IP
|
||||
int http_fn_cfg_ip(http_request_t* request) {
|
||||
char tmp[64];
|
||||
int g_changes = 0;
|
||||
@ -1107,45 +1162,9 @@ int http_fn_cfg_ip(http_request_t* request) {
|
||||
poststr(request, NULL);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
int http_fn_cfg_mqtt_set(http_request_t* request) {
|
||||
char tmpA[128];
|
||||
http_setup(request, httpMimeTypeHTML);
|
||||
http_html_start(request, "Saving MQTT");
|
||||
|
||||
if (http_getArg(request->url, "host", tmpA, sizeof(tmpA))) {
|
||||
}
|
||||
// FIX: always set, so people can clear field
|
||||
CFG_SetMQTTHost(tmpA);
|
||||
if (http_getArg(request->url, "port", tmpA, sizeof(tmpA))) {
|
||||
CFG_SetMQTTPort(atoi(tmpA));
|
||||
}
|
||||
if (http_getArg(request->url, "user", tmpA, sizeof(tmpA))) {
|
||||
CFG_SetMQTTUserName(tmpA);
|
||||
}
|
||||
if (http_getArg(request->url, "password", tmpA, sizeof(tmpA))) {
|
||||
CFG_SetMQTTPass(tmpA);
|
||||
}
|
||||
if (http_getArg(request->url, "client", tmpA, sizeof(tmpA))) {
|
||||
CFG_SetMQTTClientId(tmpA);
|
||||
}
|
||||
if (http_getArg(request->url, "group", tmpA, sizeof(tmpA))) {
|
||||
CFG_SetMQTTGroupTopic(tmpA);
|
||||
}
|
||||
|
||||
CFG_Save_SetupTimer();
|
||||
|
||||
poststr(request, "Please wait for module to connect... if there is problem, restart it from Index html page...");
|
||||
|
||||
g_mqtt_bBaseTopicDirty = 1;
|
||||
|
||||
poststr(request, "<br><a href=\"cfg_mqtt\">Return to MQTT settings</a><br>");
|
||||
poststr(request, htmlFooterReturnToCfgOrMainPage);
|
||||
http_html_end(request);
|
||||
poststr(request, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if ENABLE_HTTP_WEBAPP
|
||||
int http_fn_cfg_webapp(http_request_t* request) {
|
||||
http_setup(request, httpMimeTypeHTML);
|
||||
http_html_start(request, "Set Webapp");
|
||||
@ -1177,11 +1196,12 @@ int http_fn_cfg_webapp_set(http_request_t* request) {
|
||||
poststr(request, NULL);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#if ENABLE_HTTP_PING
|
||||
int http_fn_cfg_ping(http_request_t* request) {
|
||||
char tmpA[128];
|
||||
int bChanged;
|
||||
@ -1238,6 +1258,7 @@ int http_fn_cfg_ping(http_request_t* request) {
|
||||
poststr(request, NULL);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
int http_fn_cfg_wifi(http_request_t* request) {
|
||||
// for a test, show password as well...
|
||||
char tmpA[128];
|
||||
@ -1367,6 +1388,7 @@ int http_fn_cfg_wifi(http_request_t* request) {
|
||||
poststr(request, NULL);
|
||||
return 0;
|
||||
}
|
||||
#if ENABLE_HTTP_NAMES
|
||||
int http_fn_cfg_name(http_request_t* request) {
|
||||
// for a test, show password as well...
|
||||
char tmpA[128];
|
||||
@ -1404,7 +1426,7 @@ int http_fn_cfg_name(http_request_t* request) {
|
||||
poststr(request, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
int http_fn_cfg_wifi_set(http_request_t* request) {
|
||||
char tmpA[128];
|
||||
int bChanged;
|
||||
@ -1495,7 +1517,7 @@ int http_fn_cfg_loglevel_set(http_request_t* request) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#if ENABLE_HTTP_MAC
|
||||
int http_fn_cfg_mac(http_request_t* request) {
|
||||
// must be unsigned, else print below prints negatives as e.g. FFFFFFFe
|
||||
unsigned char mac[6];
|
||||
@ -1535,97 +1557,8 @@ int http_fn_cfg_mac(http_request_t* request) {
|
||||
poststr(request, NULL);
|
||||
return 0;
|
||||
}
|
||||
//
|
||||
//int http_fn_flash_read_tool(http_request_t* request) {
|
||||
// int len = 16;
|
||||
// int ofs = 1970176;
|
||||
// int res;
|
||||
// int rem;
|
||||
// int now;
|
||||
// int nowOfs;
|
||||
// int hex;
|
||||
// int i;
|
||||
// char tmpA[128];
|
||||
// char tmpB[64];
|
||||
//
|
||||
// http_setup(request, httpMimeTypeHTML);
|
||||
// http_html_start(request, "Flash read");
|
||||
// poststr_h4(request, "Flash Read Tool");
|
||||
// if (http_getArg(request->url, "hex", tmpA, sizeof(tmpA))) {
|
||||
// hex = atoi(tmpA);
|
||||
// }
|
||||
// else {
|
||||
// hex = 0;
|
||||
// }
|
||||
//
|
||||
// if (http_getArg(request->url, "offset", tmpA, sizeof(tmpA)) &&
|
||||
// http_getArg(request->url, "len", tmpB, sizeof(tmpB))) {
|
||||
// unsigned char buffer[128];
|
||||
// len = atoi(tmpB);
|
||||
// ofs = atoi(tmpA);
|
||||
// hprintf255(request, "Memory at %i with len %i reads: ", ofs, len);
|
||||
// poststr(request, "<br>");
|
||||
//
|
||||
// ///res = bekken_hal_flash_read (ofs, buffer,len);
|
||||
// //sprintf(tmpA,"Result %i",res);
|
||||
// // strcat(outbuf,tmpA);
|
||||
// /// strcat(outbuf,"<br>");
|
||||
//
|
||||
// nowOfs = ofs;
|
||||
// rem = len;
|
||||
// while (1) {
|
||||
// if (rem > sizeof(buffer)) {
|
||||
// now = sizeof(buffer);
|
||||
// }
|
||||
// else {
|
||||
// now = rem;
|
||||
// }
|
||||
//#if PLATFORM_XR809
|
||||
// //uint32_t flash_read(uint32_t flash, uint32_t addr,void *buf, uint32_t size)
|
||||
//#define FLASH_INDEX_XR809 0
|
||||
// res = flash_read(FLASH_INDEX_XR809, nowOfs, buffer, now);
|
||||
//#elif PLATFORM_BL602
|
||||
//
|
||||
//#elif PLATFORM_W600 || PLATFORM_W800
|
||||
//
|
||||
//#else
|
||||
// res = bekken_hal_flash_read(nowOfs, buffer, now);
|
||||
//#endif
|
||||
// for (i = 0; i < now; i++) {
|
||||
// unsigned char val = buffer[i];
|
||||
// if (!hex && isprint(val)) {
|
||||
// hprintf255(request, "'%c' ", val);
|
||||
// }
|
||||
// else {
|
||||
// hprintf255(request, "%02X ", val);
|
||||
// }
|
||||
// }
|
||||
// rem -= now;
|
||||
// nowOfs += now;
|
||||
// if (rem <= 0) {
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// poststr(request, "<br>");
|
||||
// }
|
||||
// poststr(request, "<form action=\"/flash_read_tool\">");
|
||||
//
|
||||
// poststr(request, "<input type=\"checkbox\" id=\"hex\" name=\"hex\" value=\"1\"");
|
||||
// if (hex) {
|
||||
// poststr(request, " checked");
|
||||
// }
|
||||
// poststr(request, "><label for=\"hex\">Show all hex?</label><br>");
|
||||
//
|
||||
// add_label_numeric_field(request, "Offset", "offset", ofs, "");
|
||||
// add_label_numeric_field(request, "Length", "len", len, "<br>");
|
||||
// poststr(request, SUBMIT_AND_END_FORM);
|
||||
//
|
||||
// poststr(request, htmlFooterReturnToCfgOrMainPage);
|
||||
// http_html_end(request);
|
||||
// poststr(request, NULL);
|
||||
// return 0;
|
||||
//}
|
||||
#endif
|
||||
|
||||
const char* CMD_GetResultString(commandResult_t r) {
|
||||
if (r == CMD_RES_OK)
|
||||
return "OK";
|
||||
@ -1693,6 +1626,7 @@ int http_fn_cmd_tool(http_request_t* request) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if ENABLE_HTTP_STARTUP
|
||||
int http_fn_startup_command(http_request_t* request) {
|
||||
char tmpA[512];
|
||||
http_setup(request, httpMimeTypeHTML);
|
||||
@ -1721,7 +1655,9 @@ int http_fn_startup_command(http_request_t* request) {
|
||||
poststr(request, NULL);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ENABLE_HA_DISCOVERY
|
||||
void doHomeAssistantDiscovery(const char* topic, http_request_t* request) {
|
||||
int i;
|
||||
int relayCount;
|
||||
@ -1762,7 +1698,11 @@ void doHomeAssistantDiscovery(const char* topic, http_request_t* request) {
|
||||
PIN_get_Relay_PWM_Count(&relayCount, &pwmCount, &dInputCount);
|
||||
addLogAdv(LOG_INFO, LOG_FEATURE_HTTP, "HASS counts: %i rels, %i pwms, %i inps, %i excluded", relayCount, pwmCount, dInputCount, excludedCount);
|
||||
|
||||
#if ENABLE_LED_BASIC
|
||||
ledDriverChipRunning = LED_IsLedDriverChipRunning();
|
||||
#else
|
||||
ledDriverChipRunning = 0;
|
||||
#endif
|
||||
|
||||
hooks.malloc_fn = os_malloc;
|
||||
hooks.free_fn = os_free;
|
||||
@ -1825,6 +1765,7 @@ void doHomeAssistantDiscovery(const char* topic, http_request_t* request) {
|
||||
#endif
|
||||
|
||||
|
||||
#if ENABLE_LED_BASIC
|
||||
if (pwmCount == 5 || ledDriverChipRunning || (pwmCount == 4 && CFG_HasFlag(OBK_FLAG_LED_EMULATE_COOL_WITH_RGB))) {
|
||||
if (dev_info == NULL) {
|
||||
dev_info = hass_init_light_device_info(LIGHT_RGBCW);
|
||||
@ -1858,6 +1799,7 @@ void doHomeAssistantDiscovery(const char* topic, http_request_t* request) {
|
||||
discoveryQueued = true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_DRIVER_BL0937
|
||||
if (measuringPower == true) {
|
||||
@ -2220,7 +2162,9 @@ int http_fn_ha_discovery(http_request_t* request) {
|
||||
poststr(request, NULL);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ENABLE_OLD_YAML_GENERATOR
|
||||
void http_generate_singleColor_cfg(http_request_t* request, const char* clientId) {
|
||||
hprintf255(request, " command_topic: \"cmnd/%s/led_enableAll\"\n", clientId);
|
||||
hprintf255(request, " state_topic: \"%s/led_enableAll/get\"\n", clientId);
|
||||
@ -2253,6 +2197,8 @@ void hprintf_qos_payload(http_request_t* request, const char* clientId) {
|
||||
hprintf255(request, " availability:\n");
|
||||
hprintf255(request, " - topic: \"%s/connected\"\n", clientId);
|
||||
}
|
||||
#endif
|
||||
#if ENABLE_HA_DISCOVERY
|
||||
int http_fn_ha_cfg(http_request_t* request) {
|
||||
int relayCount;
|
||||
int pwmCount;
|
||||
@ -2273,6 +2219,7 @@ int http_fn_ha_cfg(http_request_t* request) {
|
||||
http_html_start(request, "Home Assistant Setup");
|
||||
poststr_h4(request, "Home Assistant Cfg");
|
||||
hprintf255(request, "<h4>Note that your short device name is: %s</h4>", shortDeviceName);
|
||||
#if ENABLE_OLD_YAML_GENERATOR
|
||||
poststr_h4(request, "Paste this to configuration yaml");
|
||||
poststr(request, "<h5>Make sure that you have \"switch:\" keyword only once! Home Assistant doesn't like dup keywords.</h5>");
|
||||
poststr(request, "<h5>You can also use \"switch MyDeviceName:\" to avoid keyword duplication!</h5>");
|
||||
@ -2321,6 +2268,7 @@ int http_fn_ha_cfg(http_request_t* request) {
|
||||
}
|
||||
}
|
||||
}
|
||||
#if ENABLE_LED_BASIC
|
||||
if (pwmCount == 5 || LED_IsLedDriverChipRunning()) {
|
||||
// Enable + RGB control + CW control
|
||||
if (mqttAdded == 0) {
|
||||
@ -2416,8 +2364,10 @@ int http_fn_ha_cfg(http_request_t* request) {
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
poststr(request, "</textarea>");
|
||||
#endif
|
||||
poststr(request, "<br/><div><label for=\"ha_disc_topic\">Discovery topic:</label><input id=\"ha_disc_topic\" value=\"homeassistant\"><button onclick=\"send_ha_disc();\">Start Home Assistant Discovery</button> <form action=\"cfg_mqtt\" class='disp-inline'><button type=\"submit\">Configure MQTT</button></form></div><br/>");
|
||||
poststr(request, htmlFooterReturnToCfgOrMainPage);
|
||||
http_html_end(request);
|
||||
@ -2426,6 +2376,8 @@ int http_fn_ha_cfg(http_request_t* request) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void runHTTPCommandInternal(http_request_t* request, const char *cmd) {
|
||||
bool bEchoHack = strncmp(cmd, "echo", 4) == 0;
|
||||
CMD_ExecuteCommand(cmd, COMMAND_FLAG_SOURCE_HTTP);
|
||||
@ -2485,21 +2437,40 @@ int http_fn_cfg(http_request_t* request) {
|
||||
http_setup(request, httpMimeTypeHTML);
|
||||
http_html_start(request, "Config");
|
||||
postFormAction(request, "cfg_pins", "Configure Module");
|
||||
#if ENABLE_HTTP_FLAGS
|
||||
postFormAction(request, "cfg_generic", "Configure General/Flags");
|
||||
#endif
|
||||
#if ENABLE_HTTP_STARTUP
|
||||
postFormAction(request, "cfg_startup", "Configure Startup");
|
||||
#endif
|
||||
#if ENABLE_HTTP_DGR
|
||||
postFormAction(request, "cfg_dgr", "Configure Device Groups");
|
||||
#endif
|
||||
postFormAction(request, "cfg_wifi", "Configure WiFi & Web");
|
||||
#if ENABLE_HTTP_IP
|
||||
postFormAction(request, "cfg_ip", "Configure IP");
|
||||
#endif
|
||||
postFormAction(request, "cfg_mqtt", "Configure MQTT");
|
||||
#if ENABLE_HTTP_NAMES
|
||||
postFormAction(request, "cfg_name", "Configure Names");
|
||||
#endif
|
||||
#if ENABLE_HTTP_MAC
|
||||
postFormAction(request, "cfg_mac", "Change MAC");
|
||||
#endif
|
||||
#if ENABLE_HTTP_PING
|
||||
postFormAction(request, "cfg_ping", "Ping Watchdog (network lost restarter)");
|
||||
#endif
|
||||
#if ENABLE_HTTP_WEBAPP
|
||||
postFormAction(request, "cfg_webapp", "Configure WebApp");
|
||||
#endif
|
||||
#if ENABLE_HA_DISCOVERY
|
||||
postFormAction(request, "ha_cfg", "Home Assistant Configuration");
|
||||
#endif
|
||||
postFormAction(request, "ota", "OTA (update software by WiFi)");
|
||||
postFormAction(request, "cmd_tool", "Execute Custom Command");
|
||||
//postFormAction(request, "flash_read_tool", "Flash Read Tool");
|
||||
#if ENABLE_HTTP_STARTUP
|
||||
postFormAction(request, "startup_command", "Change Startup Command Text");
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
#if PLATFORM_BK7231T | PLATFORM_BK7231N
|
||||
@ -2598,9 +2569,11 @@ int http_fn_cfg_pins(http_request_t* request) {
|
||||
CFG_Save_IfThereArePendingChanges();
|
||||
|
||||
// Invoke Hass discovery if configuration has changed and not in safe mode.
|
||||
#if ENABLE_HA_DISCOVERY
|
||||
if (!bSafeMode && CFG_HasFlag(OBK_FLAG_AUTOMAIC_HASS_DISCOVERY)) {
|
||||
Main_ScheduleHomeAssistantDiscovery(1);
|
||||
}
|
||||
#endif
|
||||
hprintf255(request, "Pins update - %i reqs, %i changed!<br><br>", iChangedRequested, iChanged);
|
||||
}
|
||||
// strcat(outbuf,"<button type=\"button\">Click Me!</button>");
|
||||
@ -2723,6 +2696,7 @@ int http_fn_cfg_pins(http_request_t* request) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if ENABLE_HTTP_FLAGS
|
||||
|
||||
const char* g_obk_flagNames[] = {
|
||||
"[MQTT] Broadcast led params together (send dimmer and color when dimmer or color changes, topic name: YourDevName/led_basecolor_rgb/get, YourDevName/led_dimmer/get)",
|
||||
@ -2850,6 +2824,8 @@ int http_fn_cfg_generic(http_request_t* request) {
|
||||
poststr(request, NULL);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
#if ENABLE_HTTP_STARTUP
|
||||
int http_fn_cfg_startup(http_request_t* request) {
|
||||
int channelIndex;
|
||||
int newValue;
|
||||
@ -2904,7 +2880,8 @@ int http_fn_cfg_startup(http_request_t* request) {
|
||||
poststr(request, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
#if ENABLE_HTTP_DGR
|
||||
int http_fn_cfg_dgr(http_request_t* request) {
|
||||
char tmpA[128];
|
||||
bool bForceSet;
|
||||
@ -3002,6 +2979,7 @@ int http_fn_cfg_dgr(http_request_t* request) {
|
||||
poststr(request, NULL);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
void XR809_RequestOTAHTTP(const char* s);
|
||||
|
||||
|
||||
@ -42,6 +42,7 @@ void JSON_PrintKeyValue_Float(void* request, jsonCb_t printer, const char* key,
|
||||
}
|
||||
}
|
||||
|
||||
#if ENABLE_LED_BASIC
|
||||
static int http_tasmota_json_Dimmer(void* request, jsonCb_t printer) {
|
||||
int dimmer;
|
||||
dimmer = LED_GetDimmer();
|
||||
@ -56,6 +57,7 @@ static int http_tasmota_json_CT(void* request, jsonCb_t printer) {
|
||||
JSON_PrintKeyValue_Int(request, printer, "CT", temperature, false);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
// https://tasmota.github.io/docs/Commands/#with-mqtt
|
||||
/*
|
||||
http://<ip>/cm?cmnd=Power%20TOGGLE
|
||||
@ -87,6 +89,7 @@ static int http_tasmota_json_power(void* request, jsonCb_t printer) {
|
||||
numPWMs = PIN_CountPinsWithRoleOrRole(IOR_PWM, IOR_PWM_n);
|
||||
numRelays = 0;
|
||||
|
||||
#if ENABLE_LED_BASIC
|
||||
// LED driver (if has PWMs)
|
||||
if (LED_IsLEDRunning()) {
|
||||
http_tasmota_json_Dimmer(request, printer);
|
||||
@ -141,7 +144,9 @@ static int http_tasmota_json_power(void* request, jsonCb_t printer) {
|
||||
JSON_PrintKeyValue_String(request, printer, "POWER", "ON", false);
|
||||
}
|
||||
}
|
||||
else {
|
||||
else
|
||||
#endif
|
||||
{
|
||||
// relays driver
|
||||
for (i = 0; i < CHANNEL_MAX; i++) {
|
||||
if (h_isChannelRelay(i) || CHANNEL_GetType(i) == ChType_Toggle) {
|
||||
@ -615,10 +620,14 @@ static int http_tasmota_json_status_generic(void* request, jsonCb_t printer) {
|
||||
|
||||
PIN_get_Relay_PWM_Count(&relayCount, &pwmCount, &dInputCount);
|
||||
|
||||
#if ENABLE_LED_BASIC
|
||||
if (LED_IsLEDRunning()) {
|
||||
powerCode = LED_GetEnableAll();
|
||||
}
|
||||
else {
|
||||
else
|
||||
#endif
|
||||
|
||||
{
|
||||
powerCode = 0;
|
||||
for (i = 0; i < CHANNEL_MAX; i++) {
|
||||
bool bRelay;
|
||||
@ -784,13 +793,15 @@ int JSON_ProcessCommandReply(const char* cmd, const char* arg, void* request, js
|
||||
printer(request, "{");
|
||||
http_tasmota_json_power(request, printer);
|
||||
printer(request, "}");
|
||||
#if ENABLE_MQTT
|
||||
if (flags == COMMAND_FLAG_SOURCE_MQTT) {
|
||||
MQTT_PublishPrinterContentsToStat((struct obk_mqtt_publishReplyPrinter_s*)request, "RESULT");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else if (!wal_strnicmp(cmd, "SensorRetain", 12)) {
|
||||
printer(request, "{");
|
||||
if (CFG_HasFlag(OBK_PUBLISH_FLAG_RETAIN))
|
||||
if (CFG_HasFlag(OBK_FLAG_MQTT_ALWAYSSETRETAIN))
|
||||
{
|
||||
JSON_PrintKeyValue_String(request, printer, "SensorRetain", "ON", false);
|
||||
}
|
||||
@ -874,6 +885,7 @@ int JSON_ProcessCommandReply(const char* cmd, const char* arg, void* request, js
|
||||
JSON_PrintKeyValue_String(request, printer, "TelePeriod", "300", false);
|
||||
printer(request, "}");
|
||||
}
|
||||
#if ENABLE_LED_BASIC
|
||||
else if (!wal_strnicmp(cmd, "CT", 2)) {
|
||||
printer(request, "{");
|
||||
if (*arg == 0) {
|
||||
@ -883,9 +895,11 @@ int JSON_ProcessCommandReply(const char* cmd, const char* arg, void* request, js
|
||||
http_tasmota_json_power(request, printer);
|
||||
}
|
||||
printer(request, "}");
|
||||
#if ENABLE_MQTT
|
||||
if (flags == COMMAND_FLAG_SOURCE_MQTT) {
|
||||
MQTT_PublishPrinterContentsToStat((struct obk_mqtt_publishReplyPrinter_s*)request, "RESULT");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else if (!wal_strnicmp(cmd, "Dimmer", 6)) {
|
||||
printer(request, "{");
|
||||
@ -896,9 +910,11 @@ int JSON_ProcessCommandReply(const char* cmd, const char* arg, void* request, js
|
||||
http_tasmota_json_power(request, printer);
|
||||
}
|
||||
printer(request, "}");
|
||||
#if ENABLE_MQTT
|
||||
if (flags == COMMAND_FLAG_SOURCE_MQTT) {
|
||||
MQTT_PublishPrinterContentsToStat((struct obk_mqtt_publishReplyPrinter_s*)request, "RESULT");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else if (!wal_strnicmp(cmd, "Color", 5) || !wal_strnicmp(cmd, "HsbColor", 8)) {
|
||||
printer(request, "{");
|
||||
@ -909,31 +925,39 @@ int JSON_ProcessCommandReply(const char* cmd, const char* arg, void* request, js
|
||||
http_tasmota_json_power(request, printer);
|
||||
//}
|
||||
printer(request, "}");
|
||||
#if ENABLE_MQTT
|
||||
if (flags == COMMAND_FLAG_SOURCE_MQTT) {
|
||||
MQTT_PublishPrinterContentsToStat((struct obk_mqtt_publishReplyPrinter_s*)request, "RESULT");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
else if (!wal_strnicmp(cmd, "STATE", 5)) {
|
||||
http_tasmota_json_status_STS(request, printer, false);
|
||||
#if ENABLE_MQTT
|
||||
if (flags == COMMAND_FLAG_SOURCE_MQTT) {
|
||||
MQTT_PublishPrinterContentsToStat((struct obk_mqtt_publishReplyPrinter_s*)request, "RESULT");
|
||||
}
|
||||
if (flags == COMMAND_FLAG_SOURCE_TELESENDER) {
|
||||
MQTT_PublishPrinterContentsToTele((struct obk_mqtt_publishReplyPrinter_s*)request, "STATE");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else if (!wal_strnicmp(cmd, "SENSOR", 5)) {
|
||||
// not a Tasmota command, but still required for us
|
||||
http_tasmota_json_status_SNS(request, printer, false);
|
||||
#if ENABLE_MQTT
|
||||
if (flags == COMMAND_FLAG_SOURCE_TELESENDER) {
|
||||
MQTT_PublishPrinterContentsToTele((struct obk_mqtt_publishReplyPrinter_s*)request, "SENSOR");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else if (!wal_strnicmp(cmd, "STATUS", 6)) {
|
||||
if (!stricmp(arg, "8") || !stricmp(arg, "10")) {
|
||||
printer(request, "{");
|
||||
http_tasmota_json_status_SNS(request, printer, true);
|
||||
printer(request, "}");
|
||||
#if ENABLE_MQTT
|
||||
if (flags == COMMAND_FLAG_SOURCE_MQTT) {
|
||||
if (arg[0] == '8') {
|
||||
MQTT_PublishPrinterContentsToStat((struct obk_mqtt_publishReplyPrinter_s*)request, "STATUS8");
|
||||
@ -942,60 +966,75 @@ int JSON_ProcessCommandReply(const char* cmd, const char* arg, void* request, js
|
||||
MQTT_PublishPrinterContentsToStat((struct obk_mqtt_publishReplyPrinter_s*)request, "STATUS10");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else if (!stricmp(arg, "6")) {
|
||||
printer(request, "{");
|
||||
http_tasmota_json_status_MQT(request, printer);
|
||||
printer(request, "}");
|
||||
#if ENABLE_MQTT
|
||||
if (flags == COMMAND_FLAG_SOURCE_MQTT) {
|
||||
MQTT_PublishPrinterContentsToStat((struct obk_mqtt_publishReplyPrinter_s*)request, "STATUS6");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else if (!stricmp(arg, "7")) {
|
||||
printer(request, "{");
|
||||
http_tasmota_json_status_TIM(request, printer);
|
||||
printer(request, "}");
|
||||
#if ENABLE_MQTT
|
||||
if (flags == COMMAND_FLAG_SOURCE_MQTT) {
|
||||
MQTT_PublishPrinterContentsToStat((struct obk_mqtt_publishReplyPrinter_s*)request, "STATUS7");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else if (!stricmp(arg, "5")) {
|
||||
printer(request, "{");
|
||||
http_tasmota_json_status_NET(request, printer);
|
||||
printer(request, "}");
|
||||
#if ENABLE_MQTT
|
||||
if (flags == COMMAND_FLAG_SOURCE_MQTT) {
|
||||
MQTT_PublishPrinterContentsToStat((struct obk_mqtt_publishReplyPrinter_s*)request, "STATUS5");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else if (!stricmp(arg, "4")) {
|
||||
printer(request, "{");
|
||||
http_tasmota_json_status_MEM(request, printer);
|
||||
printer(request, "}");
|
||||
#if ENABLE_MQTT
|
||||
if (flags == COMMAND_FLAG_SOURCE_MQTT) {
|
||||
MQTT_PublishPrinterContentsToStat((struct obk_mqtt_publishReplyPrinter_s*)request, "STATUS4");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else if (!stricmp(arg, "11")) {
|
||||
printer(request, "{");
|
||||
http_tasmota_json_status_STS(request, printer, true);
|
||||
printer(request, "}");
|
||||
#if ENABLE_MQTT
|
||||
if (flags == COMMAND_FLAG_SOURCE_MQTT) {
|
||||
MQTT_PublishPrinterContentsToStat((struct obk_mqtt_publishReplyPrinter_s*)request, "STATUS11");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else if (!stricmp(arg, "2")) {
|
||||
printer(request, "{");
|
||||
http_tasmota_json_status_FWR(request, printer);
|
||||
printer(request, "}");
|
||||
#if ENABLE_MQTT
|
||||
if (flags == COMMAND_FLAG_SOURCE_MQTT) {
|
||||
MQTT_PublishPrinterContentsToStat((struct obk_mqtt_publishReplyPrinter_s*)request, "STATUS2");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
http_tasmota_json_status_generic(request, printer);
|
||||
#if ENABLE_MQTT
|
||||
if (flags == COMMAND_FLAG_SOURCE_MQTT) {
|
||||
MQTT_PublishPrinterContentsToStat((struct obk_mqtt_publishReplyPrinter_s*)request, "STATUS");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else if (!wal_strnicmp(cmd, "SetChannelType", 14)) {
|
||||
@ -1012,6 +1051,7 @@ int JSON_ProcessCommandReply(const char* cmd, const char* arg, void* request, js
|
||||
|
||||
printer(request, "%i", i);
|
||||
}
|
||||
#if ENABLE_LED_BASIC
|
||||
else if (!wal_strnicmp(cmd, "led_basecolor_rgb", 17)) {
|
||||
// OBK-specific
|
||||
char tmp[16];
|
||||
@ -1020,6 +1060,7 @@ int JSON_ProcessCommandReply(const char* cmd, const char* arg, void* request, js
|
||||
JSON_PrintKeyValue_String(request, printer, "led_basecolor_rgb", tmp, false);
|
||||
printer(request, "}");
|
||||
}
|
||||
#endif
|
||||
else if (!wal_strnicmp(cmd, "MQTTClient", 8)) {
|
||||
printer(request, "{");
|
||||
JSON_PrintKeyValue_String(request, printer, "MQTTClient", CFG_GetMQTTClientId(), false);
|
||||
@ -1071,9 +1112,11 @@ int JSON_ProcessCommandReply(const char* cmd, const char* arg, void* request, js
|
||||
sscanf(cmd + 2, "%i", &id);
|
||||
}
|
||||
http_obk_json_dps(id,request, printer);
|
||||
#if ENABLE_MQTT
|
||||
if (flags == COMMAND_FLAG_SOURCE_MQTT) {
|
||||
MQTT_PublishPrinterContentsToStat((struct obk_mqtt_publishReplyPrinter_s*)request, "DP");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@ -764,34 +764,56 @@ int HTTP_ProcessPacket(http_request_t* request) {
|
||||
if (http_checkUrlBase(urlStr, "index")) return http_fn_index(request);
|
||||
|
||||
if (http_checkUrlBase(urlStr, "about")) return http_fn_about(request);
|
||||
|
||||
|
||||
#if ENABLE_HTTP_MQTT
|
||||
if (http_checkUrlBase(urlStr, "cfg_mqtt")) return http_fn_cfg_mqtt(request);
|
||||
if (http_checkUrlBase(urlStr, "cfg_ip")) return http_fn_cfg_ip(request);
|
||||
if (http_checkUrlBase(urlStr, "cfg_mqtt_set")) return http_fn_cfg_mqtt_set(request);
|
||||
#endif
|
||||
#if ENABLE_HTTP_IP
|
||||
if (http_checkUrlBase(urlStr, "cfg_ip")) return http_fn_cfg_ip(request);
|
||||
#endif
|
||||
|
||||
#if ENABLE_HTTP_WEBAPP
|
||||
if (http_checkUrlBase(urlStr, "cfg_webapp")) return http_fn_cfg_webapp(request);
|
||||
if (http_checkUrlBase(urlStr, "cfg_webapp_set")) return http_fn_cfg_webapp_set(request);
|
||||
#endif
|
||||
|
||||
if (http_checkUrlBase(urlStr, "cfg_wifi")) return http_fn_cfg_wifi(request);
|
||||
#if ENABLE_HTTP_NAMES
|
||||
if (http_checkUrlBase(urlStr, "cfg_name")) return http_fn_cfg_name(request);
|
||||
#endif
|
||||
if (http_checkUrlBase(urlStr, "cfg_wifi_set")) return http_fn_cfg_wifi_set(request);
|
||||
|
||||
if (http_checkUrlBase(urlStr, "cfg_loglevel_set")) return http_fn_cfg_loglevel_set(request);
|
||||
#if ENABLE_HTTP_MAC
|
||||
if (http_checkUrlBase(urlStr, "cfg_mac")) return http_fn_cfg_mac(request);
|
||||
|
||||
// if (http_checkUrlBase(urlStr, "flash_read_tool")) return http_fn_flash_read_tool(request);
|
||||
#endif
|
||||
if (http_checkUrlBase(urlStr, "cmd_tool")) return http_fn_cmd_tool(request);
|
||||
if (http_checkUrlBase(urlStr, "startup_command")) return http_fn_startup_command(request);
|
||||
if (http_checkUrlBase(urlStr, "cfg_generic")) return http_fn_cfg_generic(request);
|
||||
if (http_checkUrlBase(urlStr, "cfg_startup")) return http_fn_cfg_startup(request);
|
||||
if (http_checkUrlBase(urlStr, "cfg_dgr")) return http_fn_cfg_dgr(request);
|
||||
|
||||
#if ENABLE_HTTP_STARTUP
|
||||
if (http_checkUrlBase(urlStr, "startup_command")) return http_fn_startup_command(request);
|
||||
#endif
|
||||
#if ENABLE_HTTP_FLAGS
|
||||
if (http_checkUrlBase(urlStr, "cfg_generic")) return http_fn_cfg_generic(request);
|
||||
#endif
|
||||
#if ENABLE_HTTP_STARTUP
|
||||
if (http_checkUrlBase(urlStr, "cfg_startup")) return http_fn_cfg_startup(request);
|
||||
#endif
|
||||
#if ENABLE_HTTP_DGR
|
||||
if (http_checkUrlBase(urlStr, "cfg_dgr")) return http_fn_cfg_dgr(request);
|
||||
#endif
|
||||
|
||||
#if ENABLE_HA_DISCOVERY
|
||||
if (http_checkUrlBase(urlStr, "ha_cfg")) return http_fn_ha_cfg(request);
|
||||
if (http_checkUrlBase(urlStr, "ha_discovery")) return http_fn_ha_discovery(request);
|
||||
#endif
|
||||
if (http_checkUrlBase(urlStr, "cfg")) return http_fn_cfg(request);
|
||||
|
||||
if (http_checkUrlBase(urlStr, "cfg_pins")) return http_fn_cfg_pins(request);
|
||||
#if ENABLE_HTTP_PING
|
||||
if (http_checkUrlBase(urlStr, "cfg_ping")) return http_fn_cfg_ping(request);
|
||||
#endif
|
||||
|
||||
|
||||
if (http_checkUrlBase(urlStr, "ota")) return http_fn_ota(request);
|
||||
if (http_checkUrlBase(urlStr, "ota_exec")) return http_fn_ota_exec(request);
|
||||
|
||||
Reference in New Issue
Block a user