From 47384e7057db57379c5d30cefde03699ee4a0f16 Mon Sep 17 00:00:00 2001 From: SteWers <42718143+SteWers@users.noreply.github.com> Date: Sat, 20 Jan 2024 11:10:40 +0100 Subject: [PATCH] [SolaxX1] Improve web presentation (#20535) * [SolaxX1] Improve web presentation * [SolaxX1] delay --- .../tasmota_xnrg_energy/xnrg_12_solaxX1.ino | 130 ++++++++---------- 1 file changed, 61 insertions(+), 69 deletions(-) diff --git a/tasmota/tasmota_xnrg_energy/xnrg_12_solaxX1.ino b/tasmota/tasmota_xnrg_energy/xnrg_12_solaxX1.ino index f74b59b5a..356c8d65d 100644 --- a/tasmota/tasmota_xnrg_energy/xnrg_12_solaxX1.ino +++ b/tasmota/tasmota_xnrg_energy/xnrg_12_solaxX1.ino @@ -108,7 +108,7 @@ struct SOLAXX1_LIVEDATA { float dc2_power = 0; int16_t runMode = 0; uint32_t errorCode = 0; - uint8_t SerialNumber[16] = {0x6e, 0x2f, 0x61}; // "n/a" + uint8_t SerialNumber[16] = {0x00}; } solaxX1; struct SOLAXX1_GLOBALDATA { @@ -127,15 +127,14 @@ struct SOLAXX1_SENDDATA { uint8_t ControlCode[1] = {0x00}; uint8_t FunctionCode[1] = {0x00}; uint8_t DataLength[1] = {0x00}; - uint8_t Payload[16] = {0}; + uint8_t Payload[16] = {0x00}; } solaxX1_SendData; TasmotaSerial *solaxX1Serial; /*********************************************************************************************/ -void solaxX1_RS485Send(void) -{ +void solaxX1_RS485Send(void) { uint8_t message[30]; memcpy(message, solaxX1_SendData.Header, 2); memcpy(message + 2, solaxX1_SendData.Source, 2); @@ -162,8 +161,7 @@ void solaxX1_RS485Send(void) AddLogBuffer(LOG_LEVEL_DEBUG_MORE, message, 9 + solaxX1_SendData.DataLength[0]); } -bool solaxX1_RS485Receive(uint8_t *ReadBuffer) -{ +bool solaxX1_RS485Receive(uint8_t *ReadBuffer) { uint8_t len = 0; while (solaxX1Serial->available() > 0) { ReadBuffer[len++] = (uint8_t)solaxX1Serial->read(); @@ -173,8 +171,7 @@ bool solaxX1_RS485Receive(uint8_t *ReadBuffer) return !(ReadBuffer[len - 1] == lowByte(crc) && ReadBuffer[len - 2] == highByte(crc)); } -uint16_t solaxX1_calculateCRC(uint8_t *bExternTxPackage, uint8_t bLen) -{ +uint16_t solaxX1_calculateCRC(uint8_t *bExternTxPackage, uint8_t bLen) { uint8_t i; uint16_t wChkSum = 0; for (i = 0; i < bLen; i++) { @@ -183,8 +180,7 @@ uint16_t solaxX1_calculateCRC(uint8_t *bExternTxPackage, uint8_t bLen) return wChkSum; } -void solaxX1_ExtractText(uint8_t *DataIn, uint8_t *DataOut, uint8_t Begin, uint8_t End) -{ +void solaxX1_ExtractText(uint8_t *DataIn, uint8_t *DataOut, uint8_t Begin, uint8_t End) { uint8_t i; for (i = Begin; i <= End; i++) { DataOut[i - Begin] = DataIn[i]; @@ -192,8 +188,7 @@ void solaxX1_ExtractText(uint8_t *DataIn, uint8_t *DataOut, uint8_t Begin, uint8 DataOut[End - Begin + 1] = 0; } -void solaxX1_QueryOfflineInverters(void) -{ +void solaxX1_QueryOfflineInverters(void) { solaxX1_SendData.Source[0] = 0x01; solaxX1_SendData.Destination[0] = 0x00; solaxX1_SendData.Destination[1] = 0x00; @@ -203,8 +198,7 @@ void solaxX1_QueryOfflineInverters(void) solaxX1_RS485Send(); } -void solaxX1_SendInverterAddress(void) -{ +void solaxX1_SendInverterAddress(void) { solaxX1_SendData.Source[0] = 0x00; solaxX1_SendData.Destination[0] = 0x00; solaxX1_SendData.Destination[1] = 0x00; @@ -215,8 +209,7 @@ void solaxX1_SendInverterAddress(void) solaxX1_RS485Send(); } -void solaxX1_QueryLiveData(void) -{ +void solaxX1_QueryLiveData(void) { solaxX1_SendData.Source[0] = 0x01; solaxX1_SendData.Destination[0] = 0x00; solaxX1_SendData.Destination[1] = INVERTER_ADDRESS; @@ -226,8 +219,7 @@ void solaxX1_QueryLiveData(void) solaxX1_RS485Send(); } -void solaxX1_QueryIDData(void) -{ +void solaxX1_QueryIDData(void) { solaxX1_SendData.Source[0] = 0x01; solaxX1_SendData.Destination[0] = 0x00; solaxX1_SendData.Destination[1] = INVERTER_ADDRESS; @@ -237,8 +229,7 @@ void solaxX1_QueryIDData(void) solaxX1_RS485Send(); } -void solaxX1_QueryConfigData(void) -{ +void solaxX1_QueryConfigData(void) { solaxX1_SendData.Source[0] = 0x01; solaxX1_SendData.Destination[0] = 0x00; solaxX1_SendData.Destination[1] = INVERTER_ADDRESS; @@ -248,7 +239,7 @@ void solaxX1_QueryConfigData(void) solaxX1_RS485Send(); } -uint8_t solaxX1_ParseErrorCode(uint32_t code){ +uint8_t solaxX1_ParseErrorCode(uint32_t code) { solaxX1_ErrCode.ErrMessage = code; if (code == 0) return 0; if (solaxX1_ErrCode.MainsLostFault) return 1; @@ -264,8 +255,7 @@ uint8_t solaxX1_ParseErrorCode(uint32_t code){ /*********************************************************************************************/ -void solaxX1_250MSecond(void) // Every 250 milliseconds -{ +void solaxX1_250MSecond(void) { // Every 250 milliseconds uint8_t DataRead[80] = {0}; uint8_t TempData[16] = {0}; char TempDataChar[32]; @@ -299,7 +289,8 @@ void solaxX1_250MSecond(void) // Every 250 milliseconds Energy->apparent_power[0] = Energy->active_power[0]; // U*I from inverter is not valid for apparent power; U*I could be lower than active power //temporal = (float)((DataRead[29] << 8) | DataRead[30]) * 0.1f; // Not Used Energy->import_active[0] = ((DataRead[31] << 24) | (DataRead[32] << 16) | (DataRead[33] << 8) | DataRead[34]) * 0.1f; // Energy Total - solaxX1.runtime_total = (DataRead[35] << 24) | (DataRead[36] << 16) | (DataRead[37] << 8) | DataRead[38]; // Work Time Total + uint32_t runtime_total = (DataRead[35] << 24) | (DataRead[36] << 16) | (DataRead[37] << 8) | DataRead[38]; // Work Time Total + if (runtime_total) solaxX1.runtime_total = runtime_total; // Work Time valid solaxX1.runMode = (DataRead[39] << 8) | DataRead[40]; // Work mode //temporal = (float)((DataRead[41] << 8) | DataRead[42]); // Grid voltage fault value 0.1V //temporal = (float)((DataRead[43] << 8) | DataRead[44]); // Gird frequency fault value 0.01Hz @@ -460,12 +451,10 @@ void solaxX1_250MSecond(void) // Every 250 milliseconds } } solaxX1_global.SendRetry_count--; - return; } // end solaxX1_250MSecond -void solaxX1_SnsInit(void) -{ +void solaxX1_SnsInit(void) { AddLog(LOG_LEVEL_INFO, PSTR("SX1: Init - RX-pin: %d, TX-pin: %d, RTS-pin: %d"), Pin(GPIO_SOLAXX1_RX), Pin(GPIO_SOLAXX1_TX), Pin(GPIO_SOLAXX1_RTS)); solaxX1Serial = new TasmotaSerial(Pin(GPIO_SOLAXX1_RX), Pin(GPIO_SOLAXX1_TX), 1); if (solaxX1Serial->begin(SOLAXX1_SPEED)) { @@ -481,15 +470,13 @@ void solaxX1_SnsInit(void) } } -void solaxX1_DrvInit(void) -{ +void solaxX1_DrvInit(void) { if (PinUsed(GPIO_SOLAXX1_RX) && PinUsed(GPIO_SOLAXX1_TX)) { TasmotaGlobal.energy_driver = XNRG_12; } } -bool SolaxX1_cmd(void) -{ +bool SolaxX1_cmd(void) { if (!solaxX1_global.AddressAssigned) { AddLog(LOG_LEVEL_INFO, PSTR("SX1: No inverter registered")); return false; @@ -514,12 +501,11 @@ bool SolaxX1_cmd(void) } #ifdef USE_WEBSERVER -const char HTTP_SNS_solaxX1_Num[] PROGMEM = "{s}" D_SOLAX_X1 " %s{m}