diff --git a/README.md b/README.md index d971df109..58d0a88cc 100644 --- a/README.md +++ b/README.md @@ -146,9 +146,11 @@ wm_tool.exe will then wait for device reset. Repower it or connect RESET to grou Create a HTTP server (maybe with Node-Red), then use the update mechanism by HTTP link. Give link to w800_ota.img file from the build. The second OTA mechanism (on javascript panel, by drag and drop) is not ready yet for W800/W801. Wait for device to restart, do not repower it manually. -# Testing HTTP server on Windows +# Building for Windows -It is also possible to build a part of our App for Windows platform. It basically creates a Windows .exe for our HTTP server, so developers can create our configurator, etc, pages faster, without having any Tuya modules at hand. For building on Windows, use MSVC projects in the app directory. It is using Winsock and creates a TCP listening socket on port 80, so make sure your machine has it free to use. +It is also possible to build OpenBeken for Windows. Entire OBK builds correctly, along with script support, but MQTT from LWIP library on Windows is currently a stub and there a minor issue in Winsock code which breaks Tasmota Control compatibility. To build for Windows, open openBeken_win32_mvsc2017 in Microsoft Visual Studio Community 2017 and select configuration Debug Windows or Debug Windows Scriptonly and press build. +This should make development and testing easier. +LittleFS works in Windows build, it operates on 2MB memory saved in file, so you can even test scripting, etc # Pin roles diff --git a/favicon.ico b/favicon.ico new file mode 100644 index 000000000..8a0ccd519 Binary files /dev/null and b/favicon.ico differ diff --git a/src/cmnds/cmd_public.h b/src/cmnds/cmd_public.h index 0f8f88590..800d55baf 100644 --- a/src/cmnds/cmd_public.h +++ b/src/cmnds/cmd_public.h @@ -3,7 +3,7 @@ #include "../new_common.h" -typedef int (*commandHandler_t)(const void *context, const char *cmd, const char *args, int flags); +typedef int (*commandHandler_t)(const void* context, const char* cmd, const char* args, int flags); // command was entered in console (web app etc) #define COMMAND_FLAG_SOURCE_CONSOLE 1 @@ -21,9 +21,9 @@ typedef int (*commandHandler_t)(const void *context, const char *cmd, const char // void CMD_Init(); -void CMD_RegisterCommand(const char *name, const char *args, commandHandler_t handler, const char *userDesc, void *context); -int CMD_ExecuteCommand(const char *s, int cmdFlags); -int CMD_ExecuteCommandArgs(const char *cmd, const char *args, int cmdFlags); +void CMD_RegisterCommand(const char* name, const char* args, commandHandler_t handler, const char* userDesc, void* context); +int CMD_ExecuteCommand(const char* s, int cmdFlags); +int CMD_ExecuteCommandArgs(const char* cmd, const char* args, int cmdFlags); enum EventCode { CMD_EVENT_NONE, @@ -43,12 +43,12 @@ enum EventCode { CMD_EVENT_CHANGE_VOLTAGE, // must match order in drv_bl0942.c CMD_EVENT_CHANGE_CURRENT, CMD_EVENT_CHANGE_POWER, - CMD_EVENT_CHANGE_CONSUMPTION_TOTAL, - CMD_EVENT_CHANGE_CONSUMPTION_LAST_HOUR, + CMD_EVENT_CHANGE_CONSUMPTION_TOTAL, + CMD_EVENT_CHANGE_CONSUMPTION_LAST_HOUR, // this is for ToggleChannelOnToggle CMD_EVENT_PIN_ONTOGGLE, - + // Argument is a string // You can fire an event when TuyaMCU or something receives given string CMD_EVENT_ON_UART, @@ -87,6 +87,8 @@ enum EventCode { #define HASS_TEMPERATURE_MIN 154 #define HASS_TEMPERATURE_MAX 500 +#define KELVIN_TEMPERATURE_MIN 2000 +#define KELVIN_TEMPERATURE_MAX 6500 // In general, LED can be in two modes: // - Temperature (Cool and Warm LEDs are on) @@ -104,13 +106,13 @@ enum LightMode { // cmd_tokenizer.c int Tokenizer_GetArgsCount(); -const char *Tokenizer_GetArg(int i); -const char *Tokenizer_GetArgFrom(int i); +const char* Tokenizer_GetArg(int i); +const char* Tokenizer_GetArgFrom(int i); int Tokenizer_GetArgInteger(int i); bool Tokenizer_IsArgInteger(int i); float Tokenizer_GetArgFloat(int i); int Tokenizer_GetArgIntegerRange(int i, int rangeMax, int rangeMin); -void Tokenizer_TokenizeString(const char *s, int flags); +void Tokenizer_TokenizeString(const char* s, int flags); // cmd_repeatingEvents.c void RepeatingEvents_Init(); void RepeatingEvents_OnEverySecond(); @@ -118,7 +120,7 @@ void RepeatingEvents_OnEverySecond(); void EventHandlers_Init(); // This is useful to fire an event when a certain UART string command is received. // For example, you can fire an event while getting 55 AA 01 02 00 03 FF 01 01 06 on UART.. -void EventHandlers_FireEvent_String(byte eventCode, const char *argument); +void EventHandlers_FireEvent_String(byte eventCode, const char* argument); // This is useful to fire an event when, for example, a button is pressed. // Then eventCode is a BUTTON_PRESS and argument is a button index. void EventHandlers_FireEvent(byte eventCode, int argument); @@ -140,20 +142,20 @@ void LED_SetTemperature(int tmpInteger, bool bApply); float LED_GetTemperature0to1Range(); void LED_SetTemperature0to1Range(float f); void LED_SetDimmer(int iVal); -int LED_SetBaseColor(const void *context, const char *cmd, const char *args, int bAll); +int LED_SetBaseColor(const void* context, const char* cmd, const char* args, int bAll); void LED_SetFinalCW(byte c, byte w); void LED_SetFinalRGB(byte r, byte g, byte b); -void LED_SetFinalRGBCW(byte *rgbcw); -void LED_GetFinalChannels100(byte *rgbcw); -void LED_GetFinalHSV(int *hsv); -void LED_GetFinalRGBCW(byte *rgbcw); +void LED_SetFinalRGBCW(byte* rgbcw); +void LED_GetFinalChannels100(byte* rgbcw); +void LED_GetFinalHSV(int* hsv); +void LED_GetFinalRGBCW(byte* rgbcw); void LED_NextColor(); void LED_ToggleEnabled(); bool LED_IsLedDriverChipRunning(); bool LED_IsLEDRunning(); void LED_SetEnableAll(int bEnable); int LED_GetEnableAll(); -void LED_GetBaseColorString(char * s); +void LED_GetBaseColorString(char* s); int LED_GetMode(); float LED_GetHue(); float LED_GetSaturation(); @@ -172,7 +174,7 @@ void CMD_StartTCPCommandLine(); void SVM_RunThreads(int deltaMS); void CMD_InitScripting(); -byte *LFS_ReadFile(const char *fname); +byte* LFS_ReadFile(const char* fname); #endif // __CMD_PUBLIC_H__ diff --git a/src/httpserver/hass.c b/src/httpserver/hass.c index fbff95875..1acd7e8ab 100644 --- a/src/httpserver/hass.c +++ b/src/httpserver/hass.c @@ -141,7 +141,7 @@ HassDeviceInfo* hass_init_device_info(ENTITY_TYPE type, int index, char* payload #ifndef OBK_DISABLE_ALL_DRIVERS if ((index >= OBK_VOLTAGE) && (index <= OBK_POWER)) sprintf(g_hassBuffer, "%s %s", CFG_GetShortDeviceName(), sensor_mqttNames[index]); - if ((index >= OBK_CONSUMPTION_TOTAL) && (index <= OBK_CONSUMPTION_STATS)) + else if ((index >= OBK_CONSUMPTION_TOTAL) && (index <= OBK_CONSUMPTION_STATS)) sprintf(g_hassBuffer, "%s %s", CFG_GetShortDeviceName(), counter_mqttNames[index - OBK_CONSUMPTION_TOTAL]); #endif break; @@ -250,22 +250,24 @@ HassDeviceInfo* hass_init_sensor_device_info(int index) { sprintf(g_hassBuffer, "~/%s/get", sensor_mqttNames[index]); cJSON_AddStringToObject(info->root, STATE_TOPIC_KEY, g_hassBuffer); + + cJSON_AddStringToObject(info->root, "stat_cla", "measurement"); } - if ((index >= OBK_CONSUMPTION_TOTAL) && (index <= OBK_CONSUMPTION_STATS)) + else if ((index >= OBK_CONSUMPTION_TOTAL) && (index <= OBK_CONSUMPTION_STATS)) { const char* device_class_value = counter_devClasses[index - OBK_CONSUMPTION_TOTAL]; if (strlen(device_class_value) > 0) { cJSON_AddStringToObject(info->root, "dev_cla", device_class_value); //device_class=energy cJSON_AddStringToObject(info->root, "unit_of_meas", "Wh"); //unit_of_measurement + + //state_class can be measurement, total or total_increasing. Energy values should be total_increasing. + cJSON_AddStringToObject(info->root, "stat_cla", "total_increasing"); } sprintf(g_hassBuffer, "~/%s/get", counter_mqttNames[index - OBK_CONSUMPTION_TOTAL]); cJSON_AddStringToObject(info->root, STATE_TOPIC_KEY, g_hassBuffer); } - //state_class can be measurement, total or total_increasing. Something like daily power consumption could be total_increasing. - cJSON_AddStringToObject(info->root, "stat_cla", "measurement"); - return info; } diff --git a/src/httpserver/http_fns.c b/src/httpserver/http_fns.c index 8cb3f5a47..30213f2e9 100644 --- a/src/httpserver/http_fns.c +++ b/src/httpserver/http_fns.c @@ -142,6 +142,22 @@ void postFormAction(http_request_t* request, char* action, char* value) { hprintf255(request, "
", action, value); } +/// @brief Generate a pair of label and field elements for Name type entry. The field is limited to entry of a-zA-Z0-9_- characters. +/// @param request +/// @param label +/// @param fieldId This also gets used as the field name +/// @param value +/// @param preContent +void add_label_name_field(http_request_t* request, char* label, char* fieldId, const char* value, char* preContent) { + if (strlen(preContent) > 0) { + poststr(request, preContent); + } + + hprintf255(request, "