Skip to content

Commit

Permalink
fix powerwall
Browse files Browse the repository at this point in the history
  • Loading branch information
gemu2015 committed Dec 4, 2024
1 parent 639b1d8 commit 3ce6b0e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 24 deletions.
2 changes: 1 addition & 1 deletion lib/libesp32/ESP-Mail-Client/src/SSLClient/ESP_SSLClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#define ESP_SSLCLIENT_H


#define ESP_SSLCLIENT_ENABLE_DEBUG
//#define ESP_SSLCLIENT_ENABLE_DEBUG

#include "ESP_SSLClient_FS.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#pragma once

// for enable debugging
#define ESP_SSLCLIENT_ENABLE_DEBUG
//#define ESP_SSLCLIENT_ENABLE_DEBUG

/** Call ssl_client.setDebugLevel(x) to set the debug
* esp_ssl_debug_none = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ using namespace BearSSL;

#endif

#define ESP_SSLCLIENT_ENABLE_DEBUG
//#define ESP_SSLCLIENT_ENABLE_DEBUG

class BSSL_SSL_Client : public Client
{
Expand Down
46 changes: 25 additions & 21 deletions tasmota/include/Powerwall.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

#define PW_RETRIES 2


#define PWL_LOGLVL LOG_LEVEL_INFO
#define PWL_LOGLVL LOG_LEVEL_DEBUG

// include libraries
ESP_SSLClient ssl_client;
Expand Down Expand Up @@ -399,27 +398,32 @@ String Powerwall::GetRequest(String url, String in_authCookie) {
}
}

uint16_t dlen;
for (uint32_t count = 0; count < 10; count++) {
dlen = ssl_client.available();
AddLog(PWL_LOGLVL, PSTR("PWL: count %d, dlen %d"), count, dlen);
delay(100);
yield();
}

if (dlen) {
String result;
//result = ssl_client.readStringUntil('\n');
char string[dlen + 2];
ssl_client.read((uint8_t*)string, dlen);
ssl_client.stop();
string[dlen] = 0;
String result = "\r";

timeout = 100;
char *string = (char*)calloc(4096,1);
if (string) {
char *cp = string;
while (ssl_client.connected()) {
uint16_t dlen;
dlen = ssl_client.available();
if (dlen) {
ssl_client.read((uint8_t*)cp, dlen);
cp += dlen;
*cp = 0;
}
delay(10);
timeout--;
if (!timeout) {
break;
}
}
AddLog(PWL_LOGLVL, PSTR("PWL: result %s"), string);
return string;
} else {
ssl_client.stop();
return "/r";
result = string;
free(string);
}
ssl_client.stop();
return result;
}

/**
Expand Down

0 comments on commit 3ce6b0e

Please sign in to comment.