From 7a80ab450b2aa210a343a3ca3e8cbe799dbb5587 Mon Sep 17 00:00:00 2001 From: pretoriano80 Date: Mon, 15 Aug 2022 16:13:37 +0300 Subject: [PATCH 01/11] Add quick configuration for Aubess Mini Smart Switch 16A --- src/httpserver/http_fns.c | 3 ++- src/new_builtin_devices.c | 26 ++++++++++++++++++++++++++ src/new_pins.h | 2 +- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/httpserver/http_fns.c b/src/httpserver/http_fns.c index 17a85cd03..a36d6c8ff 100644 --- a/src/httpserver/http_fns.c +++ b/src/httpserver/http_fns.c @@ -45,7 +45,8 @@ template_t g_templates [] = { { Setup_Device_Empty, "Empty"}, // BK7231N devices { Setup_Device_BK7231N_CB2S_QiachipSmartSwitch, "[BK7231N][CB2S] QiaChip Smart Switch"}, - {Setup_Device_BK7231N_KS_602_TOUCH, "[BK7231N] KS 602 Touch Switch US"}, + { Setup_Device_BK7231N_KS_602_TOUCH, "[BK7231N] KS 602 Touch Switch US"}, + { Setup_Device_Aubess_Mini_Smart_Switch_16A, "[BK7231N] Aubess Mini Smart Switch 16A"}, // BK7231T devices { Setup_Device_BK7231T_WB2S_QiachipSmartSwitch, "[BK7231T][WB2S] QiaChip Smart Switch"}, { Setup_Device_TuyaWL_SW01_16A, "WL SW01 16A"}, diff --git a/src/new_builtin_devices.c b/src/new_builtin_devices.c index b66dd4e8d..90e0869a3 100644 --- a/src/new_builtin_devices.c +++ b/src/new_builtin_devices.c @@ -805,5 +805,31 @@ void Setup_Device_Enbrighten_WFD4103(){ PIN_SetPinRoleForPinIndex(26, IOR_Button); PIN_SetPinChannelForPinIndex(26, 1); + CFG_Save_SetupTimer(); +} + +// Aubess Mini Smart Switch 16A +void Setup_Device_Aubess_Mini_Smart_Switch_16A() { + + // pins are: + // led - led_n = P6 + // embedded button - btn = P8 + // switch - btn = P14 + // relay - rel = P15 + + CFG_ClearPins(); + // Led + PIN_SetPinRoleForPinIndex(6, IOR_LED_n); + PIN_SetPinChannelForPinIndex(6, 1); + // Embedded Button + PIN_SetPinRoleForPinIndex(8, IOR_Button); + PIN_SetPinChannelForPinIndex(8, 1); + // Switch + PIN_SetPinRoleForPinIndex(14, IOR_Button); + PIN_SetPinChannelForPinIndex(14, 1); + // Relay + PIN_SetPinRoleForPinIndex(15, IOR_Relay); + PIN_SetPinChannelForPinIndex(15, 1); + CFG_Save_SetupTimer(); } \ No newline at end of file diff --git a/src/new_pins.h b/src/new_pins.h index 670e14b48..90529cb73 100644 --- a/src/new_pins.h +++ b/src/new_pins.h @@ -241,6 +241,6 @@ void Setup_Device_13A_Socket_CB2S(); void Setup_Device_Deta_Smart_Double_Power_Point_6922HA_Series2(); void Setup_Device_BK7231N_KS_602_TOUCH(); void Setup_Device_Enbrighten_WFD4103(); - +void Setup_Device_Aubess_Mini_Smart_Switch_16A(); #endif From 55c308813cb1a5a49a859bf3abe90c89ffb90836 Mon Sep 17 00:00:00 2001 From: openshwprojects Date: Tue, 16 Aug 2022 11:21:52 +0200 Subject: [PATCH 02/11] support for alternate CW lighting mode --- src/cmnds/cmd_newLEDDriver.c | 113 +++++++++++++++++++++++++---------- src/cmnds/cmd_public.h | 1 + src/httpserver/http_fns.c | 1 + src/new_pins.h | 3 +- 4 files changed, 85 insertions(+), 33 deletions(-) diff --git a/src/cmnds/cmd_newLEDDriver.c b/src/cmnds/cmd_newLEDDriver.c index 0f0294e6b..41720f7ec 100644 --- a/src/cmnds/cmd_newLEDDriver.c +++ b/src/cmnds/cmd_newLEDDriver.c @@ -71,6 +71,17 @@ float led_temperature_min = HASS_TEMPERATURE_MIN; float led_temperature_max = HASS_TEMPERATURE_MAX; float led_temperature_current = 0; + +int isCWMode() { + int pwmCount; + + pwmCount = PIN_CountPinsWithRole(IOR_PWM); + + if(pwmCount == 2) + return 1; + return 0; +} + void apply_smart_light() { int i; int firstChannelIndex; @@ -86,42 +97,73 @@ void apply_smart_light() { firstChannelIndex = 1; } - for(i = 0; i < 5; i++) { - float raw, final; - - raw = baseColors[i]; + if(isCWMode() && CFG_HasFlag(OBK_FLAG_LED_ALTERNATE_CW_MODE)) { + int value_brightness = 0; + int value_cold_or_warm = 0; + for(i = 0; i < 5; i++) { + finalColors[i] = 0; + finalRGBCW[i] = 0; + } if(g_lightEnableAll) { - final = raw * g_brightness; - } else { - final = 0; + value_cold_or_warm = LED_GetTemperature0to1Range() * 100.0f; + value_brightness = g_brightness * 100.0f; + for(i = 3; i < 5; i++) { + finalColors[i] = baseColors[i] * g_brightness; + finalRGBCW[i] = baseColors[i] * g_brightness; + } } - if(g_lightMode == Light_Temperature) { - // skip channels 0, 1, 2 - // (RGB) - if(i < 3) - { + CHANNEL_Set(firstChannelIndex, value_cold_or_warm, CHANNEL_SET_FLAG_SKIP_MQTT); + CHANNEL_Set(firstChannelIndex+1, value_brightness, CHANNEL_SET_FLAG_SKIP_MQTT); + } else { + for(i = 0; i < 5; i++) { + float raw, final; + + raw = baseColors[i]; + + if(g_lightEnableAll) { + final = raw * g_brightness; + } else { final = 0; } - } else if(g_lightMode == Light_RGB) { - // skip channels 3, 4 - if(i >= 3) - { - final = 0; + if(g_lightMode == Light_Temperature) { + // skip channels 0, 1, 2 + // (RGB) + if(i < 3) + { + final = 0; + } + } else if(g_lightMode == Light_RGB) { + // skip channels 3, 4 + if(i >= 3) + { + final = 0; + } + } else { + } - } else { + finalColors[i] = final; + finalRGBCW[i] = final; + channelToUse = firstChannelIndex + i; + + // log printf with %f crashes N platform? + //ADDLOG_INFO(LOG_FEATURE_CMD, "apply_smart_light: ch %i raw is %f, bright %f, final %f, enableAll is %i", + // channelToUse,raw,g_brightness,final,g_lightEnableAll); + + if(isCWMode()) { + // in CW mode, we have only set two channels + // We don't have RGB channels + // so, do simple mapping + if(i == 4) { + CHANNEL_Set(firstChannelIndex+0, final * g_cfg_colorScaleToChannel, CHANNEL_SET_FLAG_SKIP_MQTT); + } else if(i == 5) { + CHANNEL_Set(firstChannelIndex+1, final * g_cfg_colorScaleToChannel, CHANNEL_SET_FLAG_SKIP_MQTT); + } + } else { + CHANNEL_Set(channelToUse, final * g_cfg_colorScaleToChannel, CHANNEL_SET_FLAG_SKIP_MQTT); + } } - finalColors[i] = final; - finalRGBCW[i] = final; - - channelToUse = firstChannelIndex + i; - - // log printf with %f crashes N platform? - //ADDLOG_INFO(LOG_FEATURE_CMD, "apply_smart_light: ch %i raw is %f, bright %f, final %f, enableAll is %i", - // channelToUse,raw,g_brightness,final,g_lightEnableAll); - - CHANNEL_Set(channelToUse, final * g_cfg_colorScaleToChannel, CHANNEL_SET_FLAG_SKIP_MQTT); } #ifndef OBK_DISABLE_ALL_DRIVERS if(DRV_IsRunning("SM2135")) { @@ -191,18 +233,25 @@ OBK_Publish_Result LED_SendCurrentLightMode() { } return OBK_PUBLISH_WAS_NOT_REQUIRED; } -void LED_SetTemperature(int tmpInteger, bool bApply) { +float LED_GetTemperature0to1Range() { float f; - - led_temperature_current = tmpInteger; - f = (tmpInteger - led_temperature_min); + f = (led_temperature_current - led_temperature_min); f = f / (led_temperature_max - led_temperature_min); if(f<0) f = 0; if(f>1) f =1; + return f; +} +void LED_SetTemperature(int tmpInteger, bool bApply) { + float f; + + led_temperature_current = tmpInteger; + + f = LED_GetTemperature0to1Range(); + baseColors[3] = (255.0f) * (1-f); baseColors[4] = (255.0f) * f; diff --git a/src/cmnds/cmd_public.h b/src/cmnds/cmd_public.h index 0660df986..661d1b82c 100644 --- a/src/cmnds/cmd_public.h +++ b/src/cmnds/cmd_public.h @@ -88,6 +88,7 @@ float LED_GetDimmer(); int LED_IsRunningDriver(); float LED_GetTemperature(); void LED_SetTemperature(int tmpInteger, bool bApply); +float LED_GetTemperature0to1Range(); void LED_SetDimmer(int iVal); int LED_SetBaseColor(const void *context, const char *cmd, const char *args, int bAll); void LED_SetEnableAll(int bEnable); diff --git a/src/httpserver/http_fns.c b/src/httpserver/http_fns.c index 17a85cd03..01032a8ee 100644 --- a/src/httpserver/http_fns.c +++ b/src/httpserver/http_fns.c @@ -1652,6 +1652,7 @@ const char *g_obk_flagNames[] = { "[CMD] Enable TCP console command server (for Putty, etc)", "[BTN] Instant touch reaction instead of waiting for release (aka SetOption 13)", "[MQTT] [Debug] Always set Retain flag to all published values", + "[LED] Alternate CW light mode (first PWM for warm/cold slider, second for brightness)", "error", "error", }; diff --git a/src/new_pins.h b/src/new_pins.h index 670e14b48..4aa59316d 100644 --- a/src/new_pins.h +++ b/src/new_pins.h @@ -102,8 +102,9 @@ typedef struct pinsState_s { #define OBK_FLAG_CMD_ENABLETCPRAWPUTTYSERVER 5 #define OBK_FLAG_BTN_INSTANTTOUCH 6 #define OBK_FLAG_MQTT_ALWAYSSETRETAIN 7 +#define OBK_FLAG_LED_ALTERNATE_CW_MODE 8 -#define OBK_TOTAL_FLAGS 7 +#define OBK_TOTAL_FLAGS 9 // // Main config structure (less than 2KB) From ab640ad39f4679cdde035b58fc8e6a4d0ac307ff Mon Sep 17 00:00:00 2001 From: openshwprojects Date: Tue, 16 Aug 2022 11:30:40 +0200 Subject: [PATCH 03/11] dont send rgb in single color/cw mode --- src/cmnds/cmd_newLEDDriver.c | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/src/cmnds/cmd_newLEDDriver.c b/src/cmnds/cmd_newLEDDriver.c index 41720f7ec..d2728bd19 100644 --- a/src/cmnds/cmd_newLEDDriver.c +++ b/src/cmnds/cmd_newLEDDriver.c @@ -82,6 +82,19 @@ int isCWMode() { return 0; } +int shouldSendRGB() { + int pwmCount; + + pwmCount = PIN_CountPinsWithRole(IOR_PWM); + + // single colors and CW don't send rgb + if(pwmCount <= 2) + return 0; + + return 1; +} + + void apply_smart_light() { int i; int firstChannelIndex; @@ -178,6 +191,10 @@ static OBK_Publish_Result sendColorChange() { char s[16]; byte c[3]; + if(shouldSendRGB()==0) { + return OBK_PUBLISH_WAS_NOT_REQUIRED; + } + c[0] = (byte)(baseColors[0]); c[1] = (byte)(baseColors[1]); c[2] = (byte)(baseColors[2]); @@ -199,6 +216,10 @@ static void sendFinalColor() { char s[16]; byte c[3]; + if(shouldSendRGB()==0) { + return OBK_PUBLISH_WAS_NOT_REQUIRED; + } + c[0] = (byte)(finalColors[0]); c[1] = (byte)(finalColors[1]); c[2] = (byte)(finalColors[2]); @@ -332,11 +353,14 @@ void LED_SetDimmer(int iVal) { apply_smart_light(); LED_SendDimmerChange(); - if(CFG_HasFlag(OBK_FLAG_MQTT_BROADCASTLEDPARAMSTOGETHER)) { - sendColorChange(); - } - if(CFG_HasFlag(OBK_FLAG_MQTT_BROADCASTLEDFINALCOLOR)) { - sendFinalColor(); + + if(shouldSendRGB()) { + if(CFG_HasFlag(OBK_FLAG_MQTT_BROADCASTLEDPARAMSTOGETHER)) { + sendColorChange(); + } + if(CFG_HasFlag(OBK_FLAG_MQTT_BROADCASTLEDFINALCOLOR)) { + sendFinalColor(); + } } } From dea08cc69210bbd8abe3393bf1106a2ae7349d20 Mon Sep 17 00:00:00 2001 From: Indu Prakash Date: Tue, 16 Aug 2022 11:06:07 +0000 Subject: [PATCH 04/11] Added support for custom ntp server --- src/driver/drv_ntp.c | 15 ++++++++++++++- src/new_cfg.c | 12 ++++++++++++ src/new_cfg.h | 3 ++- src/new_pins.h | 3 ++- 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/driver/drv_ntp.c b/src/driver/drv_ntp.c index f8ce961ca..b1cde64f2 100644 --- a/src/driver/drv_ntp.c +++ b/src/driver/drv_ntp.c @@ -3,6 +3,7 @@ // https://www.elektroda.pl/rtvforum/topic3712112.html #include "../new_common.h" +#include "../new_cfg.h" // Commands register, execution API and cmd tokenizer #include "../cmnds/cmd_public.h" @@ -67,9 +68,21 @@ int NTP_SetTimeZoneOfs(const void *context, const char *cmd, const char *args, i addLogAdv(LOG_INFO, LOG_FEATURE_NTP,"NTP offset set, wait for next ntp packet to apply changes\n"); return 1; } +int NTP_SetServer(const void *context, const char *cmd, const char *args, int cmdFlags) { + Tokenizer_TokenizeString(args); + if(Tokenizer_GetArgsCount() < 1) { + addLogAdv(LOG_INFO, LOG_FEATURE_NTP,"Argument missing e.g. ntp_setServer ipAddress\n"); + return 0; + } + char *newValue = Tokenizer_GetArg(0); + CFG_SetNTPServer(newValue); + addLogAdv(LOG_INFO, LOG_FEATURE_NTP, "NTP server set to %s\n", newValue); + return 1; +} void NTP_Init() { CMD_RegisterCommand("ntp_timeZoneOfs","",NTP_SetTimeZoneOfs, "Sets the time zone offset in hours", NULL); + CMD_RegisterCommand("ntp_setServer", "", NTP_SetServer, "Sets the NTP server", NULL); } unsigned int NTP_GetCurrentTime() { @@ -122,7 +135,7 @@ void NTP_SendRequest(bool bBlocking) { memset((char *) &g_address, 0, sizeof(g_address)); g_address.sin_family = AF_INET; - g_address.sin_addr.s_addr = inet_addr("217.147.223.78"); // this is address of host which I want to send the socket + g_address.sin_addr.s_addr = inet_addr(CFG_GetNTPServer()); // this is address of host which I want to send the socket g_address.sin_port = htons(123); diff --git a/src/new_cfg.c b/src/new_cfg.c index b76066f3b..1fbfac55a 100644 --- a/src/new_cfg.c +++ b/src/new_cfg.c @@ -137,6 +137,8 @@ void CFG_SetDefaultConfig() { sprintf(g_cfg.longDeviceName,DEVICENAME_PREFIX_FULL"_%02X%02X%02X%02X",mac[2],mac[3],mac[4],mac[5]); sprintf(g_cfg.shortDeviceName,DEVICENAME_PREFIX_SHORT"%02X%02X%02X%02X",mac[2],mac[3],mac[4],mac[5]); + strcpy(g_cfg.ntpServer, "217.147.223.78"); //bart.nexellent.net + g_cfg_pendingChanges++; } @@ -446,6 +448,16 @@ void PIN_SetPinChannel2ForPinIndex(int index, int ch) { // } // } //} + +const char *CFG_GetNTPServer() { + return g_cfg.ntpServer; +} +void CFG_SetNTPServer(const char *s) { + if(strcpy_safe_checkForChanges(g_cfg.ntpServer, s,sizeof(g_cfg.ntpServer))) { + g_cfg_pendingChanges++; + } +} + void CFG_InitAndLoad() { byte chkSum; diff --git a/src/new_cfg.h b/src/new_cfg.h index 4edfc3b55..62ca3ced2 100644 --- a/src/new_cfg.h +++ b/src/new_cfg.h @@ -61,7 +61,8 @@ int CFG_DeviceGroups_GetRecvFlags(); void CFG_SetFlag(int flag, bool bValue); bool CFG_HasFlag(int flag); int CFG_GetFlags(); - +const char* CFG_GetNTPServer(); +void CFG_SetNTPServer(const char *s); #endif diff --git a/src/new_pins.h b/src/new_pins.h index 9d2790ba5..e8491b6c1 100644 --- a/src/new_pins.h +++ b/src/new_pins.h @@ -146,7 +146,8 @@ typedef struct mainConfig_s { int dgr_sendFlags; int dgr_recvFlags; char dgr_name[16]; - byte unusedSectorA[104]; + char ntpServer[20]; + byte unusedSectorA[84]; byte unusedSectorB[128]; byte unusedSectorC[55]; byte timeRequiredToMarkBootSuccessfull; From 0f188f65f0fef0b5b7f04dda8950fb4fdee1b9e7 Mon Sep 17 00:00:00 2001 From: LuisThe0ne <76198980+LuisThe0ne@users.noreply.github.com> Date: Tue, 16 Aug 2022 13:13:06 +0200 Subject: [PATCH 05/11] Update README.md --- README.md | 88 ++----------------------------------------------------- 1 file changed, 2 insertions(+), 86 deletions(-) diff --git a/README.md b/README.md index 78e1ed941..27ee9a5fc 100644 --- a/README.md +++ b/README.md @@ -30,95 +30,11 @@ OpenBeken features: - Automatic reconnect when WiFi network goes out - and much more -# Building +# Building. Flashing and OTA Updates OpenBeken supports online builds for all platforms (BK7231T, BK7231N, XR809, BL602, W800), but if you want to compile it yourself, see [BUILDING.md](https://github.com/openshwprojects/OpenBK7231T_App/blob/main/BUILDING.md) -# flashing for BK7231T - -## UART (Windows only) - -get BKwriter 1.60 exe (extract zip) from [here](https://github.com/openshwprojects/OpenBK7231T/blob/master/bk_writer1.60.zip) - -Use USB to TTL converter with 3.3V logic levels, like HW 597 - -connect the PC to TX1 and RX1 on the bk7231 (TX2 and RX2 are optional, only for log) - -start flash in BKwriter 1.60 (select COM port, etc) -then re-power the device (or reset with CEN by temporary connecting CEN to ground) until the flashing program continues, repeat if required. - -## UART (multiplatform method, Python required) - -clone the repo https://github.com/OpenBekenIOT/hid_download_py - -Use USB to TTL converter with 3.3V logic levels, like HW 597 - -connect the PC to TX1 and RX1 on the bk7231 (TX2 and RX2 are optional, only for log) - -start flash using: -`python uartprogram \apps\\output\1.0.0\_UA_.bin -d -w` -then re-power the device (or reset with CEN temporary connecting CEN to ground) until the flashing program continues, repeat if required. - -e.g. -`python uartprogram C:\DataNoBackup\tuya\tuya-iotos-embeded-sdk-wifi-ble-bk7231t\apps\my_alpha_demo\output\1.0.0\my_alpha_demo_UA_1.0.0.bin -d com4 -w` - -## SPI - -see https://github.com/OpenBekenIOT/hid_download_py/blob/master/SPIFlash.md - -## OTA - -Once the firmware has been flashed for the first time, it can be flashed over wifi (note: change hardcoded firmware URL in new_http.c) - -Setup a simple webserver to serve `\apps\\output\1.0.0\_.rbl` - -Visit /ota - here start the flashing process. - -## First run - -At first boot, if the new firmware does not find your wifi SSID and password in the Tuya flash, it will start as an access point. - -The access point will come up on 192.168.4.1, however some machines may not get an ip from it - you may need to configure your connecting for a staitc IP on that network, e.g. 192.168.4.10 - -Once you are connected and have an IP, go to http://192.168.4.1/index , select config then wifi, and setup your wifi. - -After a reboot, the device should connect to your lan. - -# Flashing for BK7231N - -BKwriter 1.60 doesn't work for BK7231N for me, in BK7231 mode it errors with "invalid CRC" and in BK7231N mode it fails to unprotect the device. -For BK7231N, one should use: - -https://github.com/OpenBekenIOT/hid_download_py - -Flash BK7231N QIO binary, like that: - -`python uartprogram W:\GIT\OpenBK7231N\apps\OpenBK7231N_App\output\1.0.0\OpenBK7231N_app_QIO_1.0.0.bin --unprotect -d com10 -w --startaddr 0x0` - - Remember - QIO binary with --unprotect and --startaddr 0x0, this is for N chip, not for T. - -You can see an example of detailed teardown and BK7231N flashing here: https://www.elektroda.com/rtvforum/topic3874289.html - -# Flashing for XR809 - -Get USB to UART converter, start phoenixMC.exe from OpenXR809 repository and follow this guide: https://www.elektroda.com/rtvforum/topic3806769.html - -# Building and flashing for BL602 - -Follow the BL602 guide: -https://www.elektroda.com/rtvforum/topic3889041.html - -# Flashing for W800/W801 - -Use wm_tool.exe, command line utility from this SDK https://github.com/openshwprojects/OpenW800 - -wm_tool.exe -c COM9 -dl W:\GIT\wm_sdk_w800\bin\w800\w800.fls - -wm_tool.exe will then wait for device reset. Repower it or connect RESET to ground, then it will start the flashing - -# OTA for W800/W801 - - 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. +[See Wiki for Instructions](https://github.com/openshwprojects/OpenBK7231T_App/wiki/Wiki-Home#flashing-ota-updates-and-building) # Testing HTTP server on Windows From 8758ce3fe2fa745f4787be6cba6fae4bea10ee65 Mon Sep 17 00:00:00 2001 From: LuisThe0ne <76198980+LuisThe0ne@users.noreply.github.com> Date: Tue, 16 Aug 2022 13:21:20 +0200 Subject: [PATCH 06/11] Update README.md --- README.md | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 86 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 27ee9a5fc..78e1ed941 100644 --- a/README.md +++ b/README.md @@ -30,11 +30,95 @@ OpenBeken features: - Automatic reconnect when WiFi network goes out - and much more -# Building. Flashing and OTA Updates +# Building OpenBeken supports online builds for all platforms (BK7231T, BK7231N, XR809, BL602, W800), but if you want to compile it yourself, see [BUILDING.md](https://github.com/openshwprojects/OpenBK7231T_App/blob/main/BUILDING.md) -[See Wiki for Instructions](https://github.com/openshwprojects/OpenBK7231T_App/wiki/Wiki-Home#flashing-ota-updates-and-building) +# flashing for BK7231T + +## UART (Windows only) + +get BKwriter 1.60 exe (extract zip) from [here](https://github.com/openshwprojects/OpenBK7231T/blob/master/bk_writer1.60.zip) + +Use USB to TTL converter with 3.3V logic levels, like HW 597 + +connect the PC to TX1 and RX1 on the bk7231 (TX2 and RX2 are optional, only for log) + +start flash in BKwriter 1.60 (select COM port, etc) +then re-power the device (or reset with CEN by temporary connecting CEN to ground) until the flashing program continues, repeat if required. + +## UART (multiplatform method, Python required) + +clone the repo https://github.com/OpenBekenIOT/hid_download_py + +Use USB to TTL converter with 3.3V logic levels, like HW 597 + +connect the PC to TX1 and RX1 on the bk7231 (TX2 and RX2 are optional, only for log) + +start flash using: +`python uartprogram \apps\\output\1.0.0\_UA_.bin -d -w` +then re-power the device (or reset with CEN temporary connecting CEN to ground) until the flashing program continues, repeat if required. + +e.g. +`python uartprogram C:\DataNoBackup\tuya\tuya-iotos-embeded-sdk-wifi-ble-bk7231t\apps\my_alpha_demo\output\1.0.0\my_alpha_demo_UA_1.0.0.bin -d com4 -w` + +## SPI + +see https://github.com/OpenBekenIOT/hid_download_py/blob/master/SPIFlash.md + +## OTA + +Once the firmware has been flashed for the first time, it can be flashed over wifi (note: change hardcoded firmware URL in new_http.c) + +Setup a simple webserver to serve `\apps\\output\1.0.0\_.rbl` + +Visit /ota - here start the flashing process. + +## First run + +At first boot, if the new firmware does not find your wifi SSID and password in the Tuya flash, it will start as an access point. + +The access point will come up on 192.168.4.1, however some machines may not get an ip from it - you may need to configure your connecting for a staitc IP on that network, e.g. 192.168.4.10 + +Once you are connected and have an IP, go to http://192.168.4.1/index , select config then wifi, and setup your wifi. + +After a reboot, the device should connect to your lan. + +# Flashing for BK7231N + +BKwriter 1.60 doesn't work for BK7231N for me, in BK7231 mode it errors with "invalid CRC" and in BK7231N mode it fails to unprotect the device. +For BK7231N, one should use: + +https://github.com/OpenBekenIOT/hid_download_py + +Flash BK7231N QIO binary, like that: + +`python uartprogram W:\GIT\OpenBK7231N\apps\OpenBK7231N_App\output\1.0.0\OpenBK7231N_app_QIO_1.0.0.bin --unprotect -d com10 -w --startaddr 0x0` + + Remember - QIO binary with --unprotect and --startaddr 0x0, this is for N chip, not for T. + +You can see an example of detailed teardown and BK7231N flashing here: https://www.elektroda.com/rtvforum/topic3874289.html + +# Flashing for XR809 + +Get USB to UART converter, start phoenixMC.exe from OpenXR809 repository and follow this guide: https://www.elektroda.com/rtvforum/topic3806769.html + +# Building and flashing for BL602 + +Follow the BL602 guide: +https://www.elektroda.com/rtvforum/topic3889041.html + +# Flashing for W800/W801 + +Use wm_tool.exe, command line utility from this SDK https://github.com/openshwprojects/OpenW800 + +wm_tool.exe -c COM9 -dl W:\GIT\wm_sdk_w800\bin\w800\w800.fls + +wm_tool.exe will then wait for device reset. Repower it or connect RESET to ground, then it will start the flashing + +# OTA for W800/W801 + + 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 From ffe0b2b1438c15a66ac691077408febb71cc481d Mon Sep 17 00:00:00 2001 From: LuisThe0ne <76198980+LuisThe0ne@users.noreply.github.com> Date: Tue, 16 Aug 2022 13:22:18 +0200 Subject: [PATCH 07/11] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 78e1ed941..506209e61 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,10 @@ OpenBeken features: - Automatic reconnect when WiFi network goes out - and much more +# Wiki + +For more Information refer to the [WIKI](github.com/openshwprojects/OpenBK7231T_App/wiki/Wiki-Home) + # Building OpenBeken supports online builds for all platforms (BK7231T, BK7231N, XR809, BL602, W800), but if you want to compile it yourself, see [BUILDING.md](https://github.com/openshwprojects/OpenBK7231T_App/blob/main/BUILDING.md) From 6c5bff688bb7a4149e54e397a4988ea7155c5ae8 Mon Sep 17 00:00:00 2001 From: LuisThe0ne <76198980+LuisThe0ne@users.noreply.github.com> Date: Tue, 16 Aug 2022 13:24:02 +0200 Subject: [PATCH 08/11] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 506209e61..41a322af3 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ OpenBeken features: # Wiki -For more Information refer to the [WIKI](github.com/openshwprojects/OpenBK7231T_App/wiki/Wiki-Home) +For more Information refer to the [WIKI](https://github.com/openshwprojects/OpenBK7231T_App/wiki/Wiki-Home) # Building From 2e745ab99ede3fea4a9281266b6b34e4a019f142 Mon Sep 17 00:00:00 2001 From: Indu Prakash Date: Tue, 16 Aug 2022 11:28:15 +0000 Subject: [PATCH 09/11] Added ntp_info --- src/driver/drv_ntp.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/driver/drv_ntp.c b/src/driver/drv_ntp.c index b1cde64f2..aeb3fa719 100644 --- a/src/driver/drv_ntp.c +++ b/src/driver/drv_ntp.c @@ -68,6 +68,8 @@ int NTP_SetTimeZoneOfs(const void *context, const char *cmd, const char *args, i addLogAdv(LOG_INFO, LOG_FEATURE_NTP,"NTP offset set, wait for next ntp packet to apply changes\n"); return 1; } + +//Set custom NTP server int NTP_SetServer(const void *context, const char *cmd, const char *args, int cmdFlags) { Tokenizer_TokenizeString(args); if(Tokenizer_GetArgsCount() < 1) { @@ -79,10 +81,20 @@ int NTP_SetServer(const void *context, const char *cmd, const char *args, int cm addLogAdv(LOG_INFO, LOG_FEATURE_NTP, "NTP server set to %s\n", newValue); return 1; } + +//Display settings used by the NTP driver +int NTP_Info(const void *context, const char *cmd, const char *args, int cmdFlags) { + addLogAdv(LOG_INFO, LOG_FEATURE_NTP, "Server=%s, Time offset=%d\n", CFG_GetNTPServer(), g_timeOffsetHours); + return 1; +} + void NTP_Init() { CMD_RegisterCommand("ntp_timeZoneOfs","",NTP_SetTimeZoneOfs, "Sets the time zone offset in hours", NULL); CMD_RegisterCommand("ntp_setServer", "", NTP_SetServer, "Sets the NTP server", NULL); + CMD_RegisterCommand("ntp_info", "", NTP_Info, "Display NTP related settings", NULL); + + addLogAdv(LOG_INFO, LOG_FEATURE_NTP, "NTP driver initialized with server=%s, offset=%d\n", CFG_GetNTPServer(), g_timeOffsetHours); } unsigned int NTP_GetCurrentTime() { From f84a909ebb1176d88bfcc85546512c18913978c3 Mon Sep 17 00:00:00 2001 From: Indu Prakash Date: Wed, 17 Aug 2022 02:21:17 +0000 Subject: [PATCH 10/11] Increased field size --- src/new_pins.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/new_pins.h b/src/new_pins.h index e8491b6c1..88e3e0763 100644 --- a/src/new_pins.h +++ b/src/new_pins.h @@ -146,8 +146,8 @@ typedef struct mainConfig_s { int dgr_sendFlags; int dgr_recvFlags; char dgr_name[16]; - char ntpServer[20]; - byte unusedSectorA[84]; + char ntpServer[32]; + byte unusedSectorA[72]; byte unusedSectorB[128]; byte unusedSectorC[55]; byte timeRequiredToMarkBootSuccessfull; From ec8d4692df0d253fa5d3a03f2450cd9f6feb5b61 Mon Sep 17 00:00:00 2001 From: LuisThe0ne <76198980+LuisThe0ne@users.noreply.github.com> Date: Wed, 17 Aug 2022 09:36:55 +0200 Subject: [PATCH 11/11] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 41a322af3..15a8fd607 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ For more Information refer to the [WIKI](https://github.com/openshwprojects/Open OpenBeken supports online builds for all platforms (BK7231T, BK7231N, XR809, BL602, W800), but if you want to compile it yourself, see [BUILDING.md](https://github.com/openshwprojects/OpenBK7231T_App/blob/main/BUILDING.md) -# flashing for BK7231T +# Flashing for BK7231T ## UART (Windows only)