Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
gemu2015 committed Dec 3, 2024
1 parent ab8d38c commit b2b62a1
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
// #include <lwip/sockets.h>
// #include <lwip/netdb.h>
// #include <errno.h>

#undef connect
#undef write
#undef read
Expand Down
27 changes: 22 additions & 5 deletions tasmota/include/Powerwall.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@
// include libraries
ESP_SSLClient ssl_client;
//EthernetClient basic_client;
WiFiClient basic_client;

//WiFiClient basic_client;
WiFiClientImpl basic_client;

class Powerwall {
private:
//const char* powerwall_ip;
String powerwall_ip;
String tesla_email;
String tesla_password;
Expand Down Expand Up @@ -315,7 +314,7 @@ String Powerwall::GetRequest(String url, String in_authCookie) {
AddLog(PWL_LOGLVL, PSTR("PWL: cookie %s"), in_authCookie.c_str());

ssl_client.setInsecure();
ssl_client.setTimeout(3000);
ssl_client.setTimeout(5000);
ssl_client.setClient(&basic_client);
//ssl_client.setBufferSizes(4096 /* rx */, 512 /* tx */);
ssl_client.setBufferSizes(16384, 512);
Expand Down Expand Up @@ -352,10 +351,17 @@ String Powerwall::GetRequest(String url, String in_authCookie) {
AddLog(PWL_LOGLVL, PSTR("PWL: request: %s"), request.c_str());

uint32_t timeout = 500;
int32_t chunked = 0;
while (ssl_client.connected()) {
if (ssl_client.available()) {
String response = ssl_client.readStringUntil('\n');
AddLog(PWL_LOGLVL, PSTR("PWL: result %s"), response.c_str());
if (chunked == -2) {
// process chunc size
chunked = strtol(response.c_str(), 0, 16);
AddLog(PWL_LOGLVL, PSTR("PWL: chunc size %d"), chunked);
break;
}
char *cp = (char*)response.c_str();
if (!strncmp_P(cp, PSTR("HTTP"), 4)) {
char *sp = strchr(cp, ' ');
Expand All @@ -372,8 +378,18 @@ String Powerwall::GetRequest(String url, String in_authCookie) {
}
}
}
if (!strncmp_P(cp, PSTR("Transfer-Encoding: chunked"), 26)) {
chunked = -1;
AddLog(PWL_LOGLVL, PSTR("PWL: chunked %d"), chunked);
}

if (response == "\r") {
break;
if (chunked) {
// skip
chunked = -2;
} else {
break;
}
}
}
timeout--;
Expand All @@ -388,6 +404,7 @@ String Powerwall::GetRequest(String url, String in_authCookie) {
dlen = ssl_client.available();
AddLog(PWL_LOGLVL, PSTR("PWL: count %d, dlen %d"), count, dlen);
delay(100);
yield();
}

if (dlen) {
Expand Down
3 changes: 1 addition & 2 deletions tasmota/tasmota_xdrv_driver/xdrv_10_scripter.ino
Original file line number Diff line number Diff line change
Expand Up @@ -7150,7 +7150,6 @@ char *GetLongIString(char *lp, char **dstr) {
lp = GetStringArgument(lp, OPER_EQU, *dstr, 0);
} else {
lp++;

char *cp;
#if 0
cp = strchr(lp, '"');
Expand All @@ -7159,7 +7158,7 @@ char *GetLongIString(char *lp, char **dstr) {
*dstr = (char*)calloc(slen + 2, 1);
if (!*dstr) return lp;
memmove(*dstr, lp , slen);
#else
#else
char *llp = lp;
loop:
cp = strchr(lp, '"');
Expand Down
6 changes: 3 additions & 3 deletions tasmota/tasmota_xsns_sensor/xsns_53_sml.ino
Original file line number Diff line number Diff line change
Expand Up @@ -1564,7 +1564,7 @@ void sml_shift_in(uint32_t meters, uint32_t shard) {
mp->spos = 0;
memmove(&mp->sbuff[0], &mp->sbuff[6], mp->sbsiz - 6);
#ifdef MODBUS_DEBUG
AddLog(LOG_LEVEL_INFO, PSTR("receive index >> %d"), mp->index);
AddLog(LOG_LEVEL_INFO, PSTR("meter %d, receive index >> %d"), meters, mp->index);
Hexdump(mp->sbuff, 10);
#endif
SML_Decode(meters);
Expand All @@ -1582,7 +1582,7 @@ void sml_shift_in(uint32_t meters, uint32_t shard) {
if (mlen > mp->sbsiz) mlen = mp->sbsiz;
if (mp->spos >= mlen) {
#ifdef MODBUS_DEBUG
AddLog(LOG_LEVEL_INFO, PSTR("receive index >> %d"), mp->index);
AddLog(LOG_LEVEL_INFO, PSTR("meter %d, receive index >> %d"), meters, mp->index);
Hexdump(mp->sbuff, 10);
#endif
SML_Decode(meters);
Expand Down Expand Up @@ -4451,7 +4451,7 @@ void SML_Send_Seq(uint32_t meter, char *seq) {
#ifdef MODBUS_DEBUG
uint8_t type = mp->type;
if (!sml_globs.dump2log && (type == 'm' || type == 'M' || type == 'k')) {
AddLog(LOG_LEVEL_INFO, PSTR("transmit index >> %d"),sml_globs.mp[meter].index);
AddLog(LOG_LEVEL_INFO, PSTR("meter %d, transmit index >> %d"), meter, sml_globs.mp[meter].index);
Hexdump(sbuff, slen);
}
#endif
Expand Down

0 comments on commit b2b62a1

Please sign in to comment.