[Memory] Move other controller queue elements to 2nd heap (ESP8266)

This commit is contained in:
TD-er
2025-02-19 23:17:18 +01:00
parent 64eff226d6
commit 5c9d7be604
17 changed files with 574 additions and 412 deletions
+72 -66
View File
@@ -49,6 +49,7 @@ bool CPlugin_003(CPlugin::Function function, struct EventStruct *event, String&
if (C003_DelayHandler == nullptr) {
break;
}
if (C003_DelayHandler->queueFull(event->ControllerIndex)) {
break;
}
@@ -58,13 +59,18 @@ bool CPlugin_003(CPlugin::Function function, struct EventStruct *event, String&
F("variableset %d,%s\n"),
event->idx,
formatUserVarNoCheck(event, 0).c_str());
std::unique_ptr<C003_queue_element> element(
new (std::nothrow) C003_queue_element(
event->ControllerIndex,
event->TaskIndex,
std::move(url)));
constexpr unsigned size = sizeof(C003_queue_element);
void *ptr = special_calloc(1, size);
success = C003_DelayHandler->addToQueue(std::move(element));
if (ptr != nullptr) {
std::unique_ptr<C003_queue_element> element(
new (ptr) C003_queue_element(
event->ControllerIndex,
event->TaskIndex,
std::move(url)));
success = C003_DelayHandler->addToQueue(std::move(element));
}
Scheduler.scheduleNextDelayQueue(SchedulerIntervalTimer_e::TIMER_C003_DELAY_QUEUE, C003_DelayHandler->getNextScheduleTime());
break;
@@ -88,69 +94,69 @@ bool CPlugin_003(CPlugin::Function function, struct EventStruct *event, String&
bool do_process_c003_delay_queue(cpluginID_t cpluginID, const Queue_element_base& element_base, ControllerSettingsStruct& ControllerSettings) {
const C003_queue_element& element = static_cast<const C003_queue_element&>(element_base);
// *INDENT-ON*
bool success = false;
bool success = false;
// Use WiFiClient class to create TCP connections
WiFiClient client;
// Use WiFiClient class to create TCP connections
WiFiClient client;
if (!try_connect_host(cpluginID, client, ControllerSettings, F("TELNT: ")))
{
return success;
}
// strcpy_P(log, PSTR("TELNT: Sending enter"));
// addLog(LOG_LEVEL_ERROR, log);
client.print(" \n");
unsigned long timer = millis() + 200;
while (!client_available(client) && !timeOutReached(timer)) {
delay(1);
}
timer = millis() + 1000;
while (client_available(client) && !timeOutReached(timer) && !success)
{
// String line = client.readStringUntil('\n');
String line;
safeReadStringUntil(client, line, '\n');
if (line.startsWith(F("Enter your password:")))
{
success = true;
#ifndef BUILD_NO_DEBUG
addLog(LOG_LEVEL_DEBUG, F("TELNT: Password request ok"));
#endif
}
delay(1);
}
#ifndef BUILD_NO_DEBUG
addLog(LOG_LEVEL_DEBUG, F("TELNT: Sending pw"));
#endif
client.println(getControllerPass(element._controller_idx, ControllerSettings));
delay(100);
while (client_available(client)) {
client.read();
}
#ifndef BUILD_NO_DEBUG
addLog(LOG_LEVEL_DEBUG, F("TELNT: Sending cmd"));
#endif
client.print(element.txt);
delay(10);
while (client_available(client)) {
client.read();
}
#ifndef BUILD_NO_DEBUG
addLog(LOG_LEVEL_DEBUG, F("TELNT: closing connection"));
#endif
client.stop();
if (!try_connect_host(cpluginID, client, ControllerSettings, F("TELNT: ")))
{
return success;
}
// strcpy_P(log, PSTR("TELNT: Sending enter"));
// addLog(LOG_LEVEL_ERROR, log);
client.print(" \n");
unsigned long timer = millis() + 200;
while (!client_available(client) && !timeOutReached(timer)) {
delay(1);
}
timer = millis() + 1000;
while (client_available(client) && !timeOutReached(timer) && !success)
{
// String line = client.readStringUntil('\n');
String line;
safeReadStringUntil(client, line, '\n');
if (line.startsWith(F("Enter your password:")))
{
success = true;
# ifndef BUILD_NO_DEBUG
addLog(LOG_LEVEL_DEBUG, F("TELNT: Password request ok"));
# endif
}
delay(1);
}
# ifndef BUILD_NO_DEBUG
addLog(LOG_LEVEL_DEBUG, F("TELNT: Sending pw"));
# endif
client.println(getControllerPass(element._controller_idx, ControllerSettings));
delay(100);
while (client_available(client)) {
client.read();
}
# ifndef BUILD_NO_DEBUG
addLog(LOG_LEVEL_DEBUG, F("TELNT: Sending cmd"));
# endif
client.print(element.txt);
delay(10);
while (client_available(client)) {
client.read();
}
# ifndef BUILD_NO_DEBUG
addLog(LOG_LEVEL_DEBUG, F("TELNT: closing connection"));
# endif
client.stop();
return success;
}
#endif // ifdef USES_C003
+9 -3
View File
@@ -48,7 +48,8 @@ bool CPlugin_004(CPlugin::Function function, struct EventStruct *event, String&
{
success = true;
switch (event->idx) {
switch (event->idx)
{
case ControllerSettingsStruct::CONTROLLER_USER:
string = F("ThingHTTP Name");
break;
@@ -72,9 +73,14 @@ bool CPlugin_004(CPlugin::Function function, struct EventStruct *event, String&
break;
}
std::unique_ptr<C004_queue_element> element(new (std::nothrow) C004_queue_element(event));
constexpr unsigned size = sizeof(C004_queue_element);
void *ptr = special_calloc(1, size);
success = C004_DelayHandler->addToQueue(std::move(element));
if (ptr != nullptr) {
std::unique_ptr<C004_queue_element> element(new (ptr) C004_queue_element(event));
success = C004_DelayHandler->addToQueue(std::move(element));
}
Scheduler.scheduleNextDelayQueue(SchedulerIntervalTimer_e::TIMER_C004_DELAY_QUEUE, C004_DelayHandler->getNextScheduleTime());
break;
+31 -25
View File
@@ -77,8 +77,13 @@ bool CPlugin_007(CPlugin::Function function, struct EventStruct *event, String&
break;
}
std::unique_ptr<C007_queue_element> element(new (std::nothrow) C007_queue_element(event));
success = C007_DelayHandler->addToQueue(std::move(element));
constexpr unsigned size = sizeof(C007_queue_element);
void *ptr = special_calloc(1, size);
if (ptr != nullptr) {
std::unique_ptr<C007_queue_element> element(new (ptr) C007_queue_element(event));
success = C007_DelayHandler->addToQueue(std::move(element));
}
Scheduler.scheduleNextDelayQueue(SchedulerIntervalTimer_e::TIMER_C007_DELAY_QUEUE, C007_DelayHandler->getNextScheduleTime());
break;
@@ -101,35 +106,36 @@ bool CPlugin_007(CPlugin::Function function, struct EventStruct *event, String&
// *INDENT-OFF*
bool do_process_c007_delay_queue(cpluginID_t cpluginID, const Queue_element_base& element_base, ControllerSettingsStruct& ControllerSettings) {
const C007_queue_element& element = static_cast<const C007_queue_element&>(element_base);
// *INDENT-ON*
if (ControllerSettings.Publish[0] == '\0') {
strcpy_P(ControllerSettings.Publish, PSTR(C007_DEFAULT_URL));
}
String url = strformat(F("%s?node=%d&json="), ControllerSettings.Publish, Settings.Unit);
for (uint8_t i = 0; i < element.valueCount; ++i) {
url += strformat(F("%cfield%d:%s"), (i == 0) ? '{' : ',', element.idx + i, element.txt[i].c_str());
}
url += strformat(F("}&apikey=%s"), getControllerPass(element._controller_idx, ControllerSettings).c_str()); // "0UDNN17RW6XAS2E5" // api key
// *INDENT-ON*
if (ControllerSettings.Publish[0] == '\0') {
strcpy_P(ControllerSettings.Publish, PSTR(C007_DEFAULT_URL));
}
String url = strformat(F("%s?node=%d&json="), ControllerSettings.Publish, Settings.Unit);
for (uint8_t i = 0; i < element.valueCount; ++i) {
url += strformat(F("%cfield%d:%s"), (i == 0) ? '{' : ',', element.idx + i, element.txt[i].c_str());
}
url += strformat(F("}&apikey=%s"), getControllerPass(element._controller_idx, ControllerSettings).c_str()); // "0UDNN17RW6XAS2E5" // api key
# ifndef BUILD_NO_DEBUG
if (loglevelActiveFor(LOG_LEVEL_DEBUG_MORE)) {
addLog(LOG_LEVEL_DEBUG_MORE, url);
}
if (loglevelActiveFor(LOG_LEVEL_DEBUG_MORE)) {
addLog(LOG_LEVEL_DEBUG_MORE, url);
}
# endif // ifndef BUILD_NO_DEBUG
int httpCode = -1;
send_via_http(
cpluginID,
ControllerSettings,
element._controller_idx,
url,
F("GET"),
EMPTY_STRING,
EMPTY_STRING,
httpCode);
return (httpCode >= 100) && (httpCode < 300);
int httpCode = -1;
send_via_http(
cpluginID,
ControllerSettings,
element._controller_idx,
url,
F("GET"),
EMPTY_STRING,
EMPTY_STRING,
httpCode);
return (httpCode >= 100) && (httpCode < 300);
}
#endif // ifdef USES_C007
+41 -30
View File
@@ -59,6 +59,7 @@ bool CPlugin_008(CPlugin::Function function, struct EventStruct *event, String&
if (C008_DelayHandler == nullptr) {
break;
}
if (C008_DelayHandler->queueFull(event->ControllerIndex)) {
break;
}
@@ -67,7 +68,7 @@ bool CPlugin_008(CPlugin::Function function, struct EventStruct *event, String&
String pubname;
{
// Place the ControllerSettings in a scope to free the memory as soon as we got all relevant information.
MakeControllerSettings(ControllerSettings); //-V522
MakeControllerSettings(ControllerSettings); // -V522
if (!AllocatedControllerSettings()) {
addLog(LOG_LEVEL_ERROR, F("C008 : Generic HTTP - Cannot send, out of RAM"));
@@ -79,8 +80,14 @@ bool CPlugin_008(CPlugin::Function function, struct EventStruct *event, String&
const bool contains_valname = pubname.indexOf(F("%valname%")) != -1;
uint8_t valueCount = getValueCountForTask(event->TaskIndex);
std::unique_ptr<C008_queue_element> element(new (std::nothrow) C008_queue_element(event, valueCount));
success = C008_DelayHandler->addToQueue(std::move(element));
constexpr unsigned size = sizeof(C008_queue_element);
void *ptr = special_calloc(1, size);
if (ptr != nullptr) {
std::unique_ptr<C008_queue_element> element(new (ptr) C008_queue_element(event, valueCount));
success = C008_DelayHandler->addToQueue(std::move(element));
}
if (success) {
// Element was added.
@@ -89,35 +96,38 @@ bool CPlugin_008(CPlugin::Function function, struct EventStruct *event, String&
C008_queue_element& element = static_cast<C008_queue_element&>(*(C008_DelayHandler->sendQueue.back()));
// Collect the values at the same run, to make sure all are from the same sample
//LoadTaskSettings(event->TaskIndex); // FIXME TD-er: This can probably be removed
// LoadTaskSettings(event->TaskIndex); // FIXME TD-er: This can probably be removed
for (uint8_t x = 0; x < valueCount; x++)
{
bool isvalid;
const String formattedValue = formatUserVar(event, x , isvalid);
bool isvalid;
const String formattedValue = formatUserVar(event, x, isvalid);
if (isvalid) {
// First store in a temporary string, so we can use move_special to allocate on the best heap
String txt;
txt += '/';
txt += pubname;
if (contains_valname) {
parseSingleControllerVariable(txt, event, x, true);
}
parseControllerVariables(txt, event, true);
# ifndef BUILD_NO_DEBUG
if (loglevelActiveFor(LOG_LEVEL_DEBUG)) {
addLog(LOG_LEVEL_DEBUG, strformat(
F("C008 : pubname: %s value: %s"),
pubname.c_str(),
formattedValue.c_str()
));
F("C008 : pubname: %s value: %s"),
pubname.c_str(),
formattedValue.c_str()
));
}
#endif
# endif // ifndef BUILD_NO_DEBUG
txt.replace(F("%value%"), formattedValue);
move_special(element.txt[x], std::move(txt));
# ifndef BUILD_NO_DEBUG
if (loglevelActiveFor(LOG_LEVEL_DEBUG_MORE)) {
addLog(LOG_LEVEL_DEBUG_MORE, concat(F("C008 : "), element.txt[x]));
}
@@ -150,26 +160,27 @@ bool CPlugin_008(CPlugin::Function function, struct EventStruct *event, String&
// *INDENT-OFF*
bool do_process_c008_delay_queue(cpluginID_t cpluginID, const Queue_element_base& element_base, ControllerSettingsStruct& ControllerSettings) {
const C008_queue_element& element = static_cast<const C008_queue_element&>(element_base);
// *INDENT-ON*
while (element.txt[element.valuesSent].isEmpty()) {
// A non valid value, which we are not going to send.
// Increase sent counter until a valid value is found.
if (element.checkDone(true)) {
return true;
}
}
int httpCode = -1;
send_via_http(
cpluginID,
ControllerSettings,
element._controller_idx,
element.txt[element.valuesSent],
F("GET"),
EMPTY_STRING,
EMPTY_STRING,
httpCode);
return element.checkDone((httpCode >= 100) && (httpCode < 300));
// *INDENT-ON*
while (element.txt[element.valuesSent].isEmpty()) {
// A non valid value, which we are not going to send.
// Increase sent counter until a valid value is found.
if (element.checkDone(true)) {
return true;
}
}
int httpCode = -1;
send_via_http(
cpluginID,
ControllerSettings,
element._controller_idx,
element.txt[element.valuesSent],
F("GET"),
EMPTY_STRING,
EMPTY_STRING,
httpCode);
return element.checkDone((httpCode >= 100) && (httpCode < 300));
}
#endif // ifdef USES_C008
+102 -96
View File
@@ -1,9 +1,9 @@
#include "src/Helpers/_CPlugin_Helper.h"
#ifdef USES_C009
#include "src/DataTypes/NodeTypeID.h"
#include "src/Helpers/StringProvider.h"
#include "src/CustomBuild/ESPEasy_buildinfo.h"
# include "src/DataTypes/NodeTypeID.h"
# include "src/Helpers/StringProvider.h"
# include "src/CustomBuild/ESPEasy_buildinfo.h"
// #######################################################################################################
// ########################### Controller Plugin 009: FHEM HTTP ##########################################
@@ -80,8 +80,13 @@ bool CPlugin_009(CPlugin::Function function, struct EventStruct *event, String&
break;
}
std::unique_ptr<C009_queue_element> element(new (std::nothrow) C009_queue_element(event));
success = C009_DelayHandler->addToQueue(std::move(element));
constexpr unsigned size = sizeof(C009_queue_element);
void *ptr = special_calloc(1, size);
if (ptr != nullptr) {
std::unique_ptr<C009_queue_element> element(new (ptr) C009_queue_element(event));
success = C009_DelayHandler->addToQueue(std::move(element));
}
Scheduler.scheduleNextDelayQueue(SchedulerIntervalTimer_e::TIMER_C009_DELAY_QUEUE, C009_DelayHandler->getNextScheduleTime());
}
break;
@@ -109,109 +114,110 @@ bool CPlugin_009(CPlugin::Function function, struct EventStruct *event, String&
bool do_process_c009_delay_queue(cpluginID_t cpluginID, const Queue_element_base& element_base, ControllerSettingsStruct& ControllerSettings) {
const C009_queue_element& element = static_cast<const C009_queue_element&>(element_base);
// *INDENT-ON*
String jsonString;
// Make an educated guess on the actual length, based on earlier requests.
static size_t expectedJsonLength = 100;
{
// Reserve on the heap with most space
if (!reserve_special(jsonString, expectedJsonLength)) {
// Not enough free memory
return false;
}
String jsonString;
// Make an educated guess on the actual length, based on earlier requests.
static size_t expectedJsonLength = 100;
{
// Reserve on the heap with most space
if (!reserve_special(jsonString, expectedJsonLength)) {
// Not enough free memory
return false;
}
}
{
jsonString += '{';
{
jsonString += '{';
jsonString += to_json_object_value(F("module"), F("ESPEasy"));
jsonString += ',';
jsonString += to_json_object_value(F("version"), F("1.04"));
// Create nested object "ESP" inside "data"
jsonString += ',';
jsonString += F("\"data\":{");
{
jsonString += to_json_object_value(F("module"), F("ESPEasy"));
jsonString += ',';
jsonString += to_json_object_value(F("version"), F("1.04"));
// Create nested object "ESP" inside "data"
jsonString += ',';
jsonString += F("\"data\":{");
jsonString += F("\"ESP\":{");
{
jsonString += F("\"ESP\":{");
{
// Create nested objects in "ESP":
jsonString += to_json_object_value(F("name"), Settings.getName());
jsonString += ',';
jsonString += to_json_object_value(F("unit"), static_cast<int>(Settings.Unit));
jsonString += ',';
jsonString += to_json_object_value(F("version"), static_cast<int>(Settings.Version));
jsonString += ',';
jsonString += to_json_object_value(F("build"), static_cast<int>(Settings.Build));
jsonString += ',';
jsonString += to_json_object_value(F("build_notes"), F(BUILD_NOTES));
jsonString += ',';
jsonString += to_json_object_value(F("build_git"), getValue(LabelType::GIT_BUILD));
jsonString += ',';
jsonString += to_json_object_value(F("node_type_id"), static_cast<int>(NODE_TYPE_ID));
jsonString += ',';
jsonString += to_json_object_value(F("sleep"), static_cast<int>(Settings.deepSleep_wakeTime));
// embed IP, important if there is NAT/PAT
// char ipStr[20];
// IPAddress ip = NetworkLocalIP();
// sprintf_P(ipStr, PSTR("%u.%u.%u.%u"), ip[0], ip[1], ip[2], ip[3]);
jsonString += ',';
jsonString += to_json_object_value(F("ip"), formatIP(NetworkLocalIP()));
}
jsonString += '}'; // End "ESP"
// Create nested objects in "ESP":
jsonString += to_json_object_value(F("name"), Settings.getName());
jsonString += ',';
jsonString += to_json_object_value(F("unit"), static_cast<int>(Settings.Unit));
jsonString += ',';
jsonString += to_json_object_value(F("version"), static_cast<int>(Settings.Version));
jsonString += ',';
jsonString += to_json_object_value(F("build"), static_cast<int>(Settings.Build));
jsonString += ',';
jsonString += to_json_object_value(F("build_notes"), F(BUILD_NOTES));
jsonString += ',';
jsonString += to_json_object_value(F("build_git"), getValue(LabelType::GIT_BUILD));
jsonString += ',';
jsonString += to_json_object_value(F("node_type_id"), static_cast<int>(NODE_TYPE_ID));
jsonString += ',';
jsonString += to_json_object_value(F("sleep"), static_cast<int>(Settings.deepSleep_wakeTime));
// Create nested object "SENSOR" json object inside "data"
jsonString += F("\"SENSOR\":{");
{
// char itemNames[valueCount][2];
for (uint8_t x = 0; x < element.valueCount; x++)
{
// Each sensor value get an own object (0..n)
// sprintf(itemNames[x],"%d",x);
if (x != 0) {
jsonString += ',';
}
jsonString += '"';
jsonString += x;
jsonString += F("\":{");
{
jsonString += to_json_object_value(F("deviceName"), getTaskDeviceName(element._taskIndex));
jsonString += ',';
jsonString += to_json_object_value(F("valueName"), Cache.getTaskDeviceValueName(element._taskIndex, x));
jsonString += ',';
jsonString += to_json_object_value(F("type"), static_cast<int>(element.sensorType));
jsonString += ',';
jsonString += to_json_object_value(F("value"), element.txt[x]);
}
jsonString += '}'; // End "sensor value N"
}
}
jsonString += '}'; // End "SENSOR"
// embed IP, important if there is NAT/PAT
// char ipStr[20];
// IPAddress ip = NetworkLocalIP();
// sprintf_P(ipStr, PSTR("%u.%u.%u.%u"), ip[0], ip[1], ip[2], ip[3]);
jsonString += ',';
jsonString += to_json_object_value(F("ip"), formatIP(NetworkLocalIP()));
}
jsonString += '}'; // End "data"
jsonString += '}'; // End "ESP"
jsonString += ',';
// Create nested object "SENSOR" json object inside "data"
jsonString += F("\"SENSOR\":{");
{
// char itemNames[valueCount][2];
for (uint8_t x = 0; x < element.valueCount; x++)
{
// Each sensor value get an own object (0..n)
// sprintf(itemNames[x],"%d",x);
if (x != 0) {
jsonString += ',';
}
jsonString += '"';
jsonString += x;
jsonString += F("\":{");
{
jsonString += to_json_object_value(F("deviceName"), getTaskDeviceName(element._taskIndex));
jsonString += ',';
jsonString += to_json_object_value(F("valueName"), Cache.getTaskDeviceValueName(element._taskIndex, x));
jsonString += ',';
jsonString += to_json_object_value(F("type"), static_cast<int>(element.sensorType));
jsonString += ',';
jsonString += to_json_object_value(F("value"), element.txt[x]);
}
jsonString += '}'; // End "sensor value N"
}
}
jsonString += '}'; // End "SENSOR"
}
jsonString += '}'; // End JSON structure
jsonString += '}'; // End "data"
}
jsonString += '}'; // End JSON structure
}
if (expectedJsonLength < jsonString.length()) {
expectedJsonLength = jsonString.length();
}
if (expectedJsonLength < jsonString.length()) {
expectedJsonLength = jsonString.length();
}
// addLog(LOG_LEVEL_INFO, F("C009 Test JSON:"));
// addLog(LOG_LEVEL_INFO, jsonString);
// addLog(LOG_LEVEL_INFO, F("C009 Test JSON:"));
// addLog(LOG_LEVEL_INFO, jsonString);
int httpCode = -1;
send_via_http(
cpluginID,
ControllerSettings,
element._controller_idx,
F("/ESPEasy"),
F("POST"),
EMPTY_STRING,
jsonString,
httpCode);
return (httpCode >= 100) && (httpCode < 300);
int httpCode = -1;
send_via_http(
cpluginID,
ControllerSettings,
element._controller_idx,
F("/ESPEasy"),
F("POST"),
EMPTY_STRING,
jsonString,
httpCode);
return (httpCode >= 100) && (httpCode < 300);
}
#endif // ifdef USES_C009
+58 -50
View File
@@ -57,6 +57,7 @@ bool CPlugin_010(CPlugin::Function function, struct EventStruct *event, String&
if (C010_DelayHandler == nullptr) {
break;
}
if (C010_DelayHandler->queueFull(event->ControllerIndex)) {
break;
}
@@ -67,47 +68,53 @@ bool CPlugin_010(CPlugin::Function function, struct EventStruct *event, String&
break;
}
//LoadTaskSettings(event->TaskIndex); // FIXME TD-er: This can probably be removed
// LoadTaskSettings(event->TaskIndex); // FIXME TD-er: This can probably be removed
std::unique_ptr<C010_queue_element> element(new (std::nothrow) C010_queue_element(event, valueCount));
constexpr unsigned size = sizeof(C010_queue_element);
void *ptr = special_calloc(1, size);
{
String pubname;
if (ptr != nullptr) {
std::unique_ptr<C010_queue_element> element(new (ptr) C010_queue_element(event, valueCount));
{
MakeControllerSettings(ControllerSettings); //-V522
String pubname;
{
MakeControllerSettings(ControllerSettings); // -V522
if (!AllocatedControllerSettings()) {
break;
if (!AllocatedControllerSettings()) {
break;
}
LoadControllerSettings(event->ControllerIndex, *ControllerSettings);
pubname = ControllerSettings->Publish;
}
LoadControllerSettings(event->ControllerIndex, *ControllerSettings);
pubname = ControllerSettings->Publish;
}
const bool contains_valname = pubname.indexOf(F("%valname%")) != -1;
const bool contains_valname = pubname.indexOf(F("%valname%")) != -1;
for (uint8_t x = 0; x < valueCount; x++)
{
bool isvalid;
const String formattedValue = formatUserVar(event, x, isvalid);
for (uint8_t x = 0; x < valueCount; x++)
{
bool isvalid;
const String formattedValue = formatUserVar(event, x, isvalid);
if (isvalid) {
String txt;
txt = pubname;
if (contains_valname) {
parseSingleControllerVariable(txt, event, x, false);
if (isvalid) {
String txt;
txt = pubname;
if (contains_valname) {
parseSingleControllerVariable(txt, event, x, false);
}
parseControllerVariables(txt, event, false);
txt.replace(F("%value%"), formattedValue);
move_special(element->txt[x], std::move(txt));
# ifndef BUILD_NO_DEBUG
if (loglevelActiveFor(LOG_LEVEL_DEBUG_MORE)) {
addLog(LOG_LEVEL_DEBUG_MORE, element->txt[x]);
}
# endif // ifndef BUILD_NO_DEBUG
}
parseControllerVariables(txt, event, false);
txt.replace(F("%value%"), formattedValue);
move_special(element->txt[x], std::move(txt));
#ifndef BUILD_NO_DEBUG
if (loglevelActiveFor(LOG_LEVEL_DEBUG_MORE))
addLog(LOG_LEVEL_DEBUG_MORE, element->txt[x]);
#endif
}
}
}
success = C010_DelayHandler->addToQueue(std::move(element));
success = C010_DelayHandler->addToQueue(std::move(element));
}
Scheduler.scheduleNextDelayQueue(SchedulerIntervalTimer_e::TIMER_C010_DELAY_QUEUE, C010_DelayHandler->getNextScheduleTime());
break;
}
@@ -133,33 +140,34 @@ bool CPlugin_010(CPlugin::Function function, struct EventStruct *event, String&
// *INDENT-OFF*
bool do_process_c010_delay_queue(cpluginID_t cpluginID, const Queue_element_base& element_base, ControllerSettingsStruct& ControllerSettings) {
const C010_queue_element& element = static_cast<const C010_queue_element&>(element_base);
// *INDENT-ON*
while (element.txt[element.valuesSent].isEmpty()) {
// A non valid value, which we are not going to send.
// Increase sent counter until a valid value is found.
if (element.checkDone(true)) {
return true;
}
while (element.txt[element.valuesSent].isEmpty()) {
// A non valid value, which we are not going to send.
// Increase sent counter until a valid value is found.
if (element.checkDone(true)) {
return true;
}
WiFiUDP C010_portUDP;
}
WiFiUDP C010_portUDP;
if (!beginWiFiUDP_randomPort(C010_portUDP)) { return false; }
if (!beginWiFiUDP_randomPort(C010_portUDP)) { return false; }
if (!try_connect_host(cpluginID, C010_portUDP, ControllerSettings)) {
return false;
}
if (!try_connect_host(cpluginID, C010_portUDP, ControllerSettings)) {
return false;
}
C010_portUDP.write(
reinterpret_cast<const uint8_t *>(element.txt[element.valuesSent].c_str()),
element.txt[element.valuesSent].length());
bool reply = C010_portUDP.endPacket();
C010_portUDP.write(
reinterpret_cast<const uint8_t *>(element.txt[element.valuesSent].c_str()),
element.txt[element.valuesSent].length());
bool reply = C010_portUDP.endPacket();
C010_portUDP.stop();
C010_portUDP.stop();
if (ControllerSettings.MustCheckReply) {
return element.checkDone(reply);
}
return element.checkDone(true);
if (ControllerSettings.MustCheckReply) {
return element.checkDone(reply);
}
return element.checkDone(true);
}
#endif // ifdef USES_C010
+94 -61
View File
@@ -19,6 +19,7 @@ bool C011_sendBinary = false;
struct C011_ConfigStruct
{
void zero_last() {
HttpMethod[C011_HTTP_METHOD_MAX_LEN - 1] = 0;
HttpUri[C011_HTTP_URI_MAX_LEN - 1] = 0;
@@ -30,16 +31,22 @@ struct C011_ConfigStruct
char HttpUri[C011_HTTP_URI_MAX_LEN] = { 0 };
char HttpHeader[C011_HTTP_HEADER_MAX_LEN] = { 0 };
char HttpBody[C011_HTTP_BODY_MAX_LEN] = { 0 };
};
// Forward declarations
bool load_C011_ConfigStruct(controllerIndex_t ControllerIndex, String& HttpMethod, String& HttpUri, String& HttpHeader, String& HttpBody);
bool load_C011_ConfigStruct(controllerIndex_t ControllerIndex,
String & HttpMethod,
String & HttpUri,
String & HttpHeader,
String & HttpBody);
boolean Create_schedule_HTTP_C011(struct EventStruct *event);
void DeleteNotNeededValues(String& s, uint8_t numberOfValuesWanted);
void ReplaceTokenByValue(String& s, struct EventStruct *event, bool sendBinary);
void DeleteNotNeededValues(String& s,
uint8_t numberOfValuesWanted);
void ReplaceTokenByValue(String & s,
struct EventStruct *event,
bool sendBinary);
bool CPlugin_011(CPlugin::Function function, struct EventStruct *event, String& string)
{
@@ -68,7 +75,7 @@ bool CPlugin_011(CPlugin::Function function, struct EventStruct *event, String&
case CPlugin::Function::CPLUGIN_INIT:
{
{
MakeControllerSettings(ControllerSettings); //-V522
MakeControllerSettings(ControllerSettings); // -V522
if (AllocatedControllerSettings()) {
LoadControllerSettings(event->ControllerIndex, *ControllerSettings);
@@ -99,8 +106,8 @@ bool CPlugin_011(CPlugin::Function function, struct EventStruct *event, String&
}
addTableSeparator(F("HTTP Config"), 2, 3);
{
uint8_t choice = 0;
const __FlashStringHelper * methods[] = { F("GET"), F("POST"), F("PUT"), F("HEAD"), F("PATCH") };
uint8_t choice = 0;
const __FlashStringHelper *methods[] = { F("GET"), F("POST"), F("PUT"), F("HEAD"), F("PATCH") };
constexpr int nrOptions = NR_ELEMENTS(methods);
@@ -127,7 +134,7 @@ bool CPlugin_011(CPlugin::Function function, struct EventStruct *event, String&
}
{
// Place in scope to delete ControllerSettings as soon as it is no longer needed
MakeControllerSettings(ControllerSettings); //-V522
MakeControllerSettings(ControllerSettings); // -V522
if (!AllocatedControllerSettings()) {
addHtmlError(F("Out of memory, cannot load page"));
@@ -142,30 +149,37 @@ bool CPlugin_011(CPlugin::Function function, struct EventStruct *event, String&
case CPlugin::Function::CPLUGIN_WEBFORM_SAVE:
{
std::shared_ptr<C011_ConfigStruct> customConfig(new (std::nothrow) C011_ConfigStruct);
constexpr unsigned size = sizeof(C011_ConfigStruct);
void *ptr = special_calloc(1, size);
if (customConfig) {
uint8_t choice = 0;
String methods[] = { F("GET"), F("POST"), F("PUT"), F("HEAD"), F("PATCH") };
if (ptr != nullptr) {
std::shared_ptr<C011_ConfigStruct> customConfig(new (ptr) C011_ConfigStruct);
for (uint8_t i = 0; i < 5; i++)
{
if (methods[i].equals(customConfig->HttpMethod)) {
choice = i;
if (customConfig) {
uint8_t choice = 0;
String methods[] = { F("GET"), F("POST"), F("PUT"), F("HEAD"), F("PATCH") };
for (uint8_t i = 0; i < 5; i++)
{
if (methods[i].equals(customConfig->HttpMethod)) {
choice = i;
}
}
int httpmethod = getFormItemInt(F("P011httpmethod"), choice);
String httpuri = webArg(F("P011httpuri"));
String httpheader = webArg(F("P011httpheader"));
String httpbody = webArg(F("P011httpbody"));
strlcpy(customConfig->HttpMethod, methods[httpmethod].c_str(), sizeof(customConfig->HttpMethod));
strlcpy(customConfig->HttpUri, httpuri.c_str(), sizeof(customConfig->HttpUri));
strlcpy(customConfig->HttpHeader, httpheader.c_str(), sizeof(customConfig->HttpHeader));
strlcpy(customConfig->HttpBody, httpbody.c_str(), sizeof(customConfig->HttpBody));
customConfig->zero_last();
SaveCustomControllerSettings(event->ControllerIndex,
reinterpret_cast<const uint8_t *>(customConfig.get()),
sizeof(C011_ConfigStruct));
}
int httpmethod = getFormItemInt(F("P011httpmethod"), choice);
String httpuri = webArg(F("P011httpuri"));
String httpheader = webArg(F("P011httpheader"));
String httpbody = webArg(F("P011httpbody"));
strlcpy(customConfig->HttpMethod, methods[httpmethod].c_str(), sizeof(customConfig->HttpMethod));
strlcpy(customConfig->HttpUri, httpuri.c_str(), sizeof(customConfig->HttpUri));
strlcpy(customConfig->HttpHeader, httpheader.c_str(), sizeof(customConfig->HttpHeader));
strlcpy(customConfig->HttpBody, httpbody.c_str(), sizeof(customConfig->HttpBody));
customConfig->zero_last();
SaveCustomControllerSettings(event->ControllerIndex, reinterpret_cast<const uint8_t *>(customConfig.get()), sizeof(C011_ConfigStruct));
}
break;
}
@@ -202,29 +216,36 @@ bool do_process_c011_delay_queue(cpluginID_t cpluginID, const Queue_element_base
const C011_queue_element& element = static_cast<const C011_queue_element&>(element_base);
// *INDENT-ON*
if (!NetworkConnected()) { return false; }
if (!NetworkConnected()) { return false; }
int httpCode = -1;
int httpCode = -1;
send_via_http(
cpluginID,
ControllerSettings,
element._controller_idx,
element.uri,
element.HttpMethod,
element.header,
element.postStr,
httpCode);
send_via_http(
cpluginID,
ControllerSettings,
element._controller_idx,
element.uri,
element.HttpMethod,
element.header,
element.postStr,
httpCode);
// HTTP codes:
// 1xx Informational response
// 2xx Success
return httpCode >= 100 && httpCode < 300;
// HTTP codes:
// 1xx Informational response
// 2xx Success
return httpCode >= 100 && httpCode < 300;
}
bool load_C011_ConfigStruct(controllerIndex_t ControllerIndex, String& HttpMethod, String& HttpUri, String& HttpHeader, String& HttpBody) {
// Just copy the needed strings and destruct the C011_ConfigStruct as soon as possible
std::shared_ptr<C011_ConfigStruct> customConfig(new (std::nothrow) C011_ConfigStruct);
constexpr unsigned size = sizeof(C011_ConfigStruct);
void *ptr = special_calloc(1, size);
if (ptr == nullptr) {
return false;
}
std::shared_ptr<C011_ConfigStruct>customConfig(new (ptr) C011_ConfigStruct);
if (!customConfig) {
return false;
@@ -232,9 +253,9 @@ bool load_C011_ConfigStruct(controllerIndex_t ControllerIndex, String& HttpMetho
LoadCustomControllerSettings(ControllerIndex, reinterpret_cast<uint8_t *>(customConfig.get()), sizeof(C011_ConfigStruct));
customConfig->zero_last();
move_special(HttpMethod, String(customConfig->HttpMethod));
move_special(HttpUri , String(customConfig->HttpUri));
move_special(HttpUri, String(customConfig->HttpUri));
move_special(HttpHeader, String(customConfig->HttpHeader));
move_special(HttpBody , String(customConfig->HttpBody));
move_special(HttpBody, String(customConfig->HttpBody));
return true;
}
@@ -247,10 +268,19 @@ boolean Create_schedule_HTTP_C011(struct EventStruct *event)
addLog(LOG_LEVEL_ERROR, F("No C011_DelayHandler"));
return false;
}
//LoadTaskSettings(event->TaskIndex); // FIXME TD-er: This can probably be removed
// LoadTaskSettings(event->TaskIndex); // FIXME TD-er: This can probably be removed
constexpr unsigned size = sizeof(C011_queue_element);
void *ptr = special_calloc(1, size);
if (ptr == nullptr) {
return false;
}
// Add a new element to the queue with the minimal payload
std::unique_ptr<C011_queue_element> element(new (std::nothrow) C011_queue_element(event));
std::unique_ptr<C011_queue_element>element(new (ptr) C011_queue_element(event));
bool success = C011_DelayHandler->addToQueue(std::move(element));
if (success) {
@@ -264,11 +294,11 @@ boolean Create_schedule_HTTP_C011(struct EventStruct *event)
{
if (loglevelActiveFor(LOG_LEVEL_ERROR)) {
addLogMove(LOG_LEVEL_ERROR, strformat(
F("C011 : %s %s %s %s"),
element.HttpMethod.c_str(),
element.uri.c_str(),
element.header.c_str(),
element.postStr.c_str()));
F("C011 : %s %s %s %s"),
element.HttpMethod.c_str(),
element.uri.c_str(),
element.header.c_str(),
element.postStr.c_str()));
}
C011_DelayHandler->sendQueue.pop_back();
return false;
@@ -305,7 +335,7 @@ void DeleteNotNeededValues(String& s, uint8_t numberOfValuesWanted)
{
// yes, so just remove the tokens
s.replace(startToken, EMPTY_STRING);
s.replace(endToken, EMPTY_STRING);
s.replace(endToken, EMPTY_STRING);
}
else
{
@@ -344,31 +374,34 @@ void ReplaceTokenByValue(String& s, struct EventStruct *event, bool sendBinary)
// write?db=testdb&type=%1%%vname1%%/1%%2%;%vname2%%/2%%3%;%vname3%%/3%%4%;%vname4%%/4%&value=%1%%val1%%/1%%2%;%val2%%/2%%3%;%val3%%/3%%4%;%val4%%/4%
// %1%%vname1%,Standort=%tskname% Wert=%val1%%/1%%2%%LF%%vname2%,Standort=%tskname% Wert=%val2%%/2%%3%%LF%%vname3%,Standort=%tskname%
// Wert=%val3%%/3%%4%%LF%%vname4%,Standort=%tskname% Wert=%val4%%/4%
#ifndef BUILD_NO_DEBUG
# ifndef BUILD_NO_DEBUG
if (loglevelActiveFor(LOG_LEVEL_DEBUG_MORE)) {
addLog(LOG_LEVEL_DEBUG_MORE, F("HTTP before parsing: "));
addLog(LOG_LEVEL_DEBUG_MORE, s);
}
#endif
# endif // ifndef BUILD_NO_DEBUG
const uint8_t valueCount = getValueCountForTask(event->TaskIndex);
DeleteNotNeededValues(s, valueCount);
#ifndef BUILD_NO_DEBUG
# ifndef BUILD_NO_DEBUG
if (loglevelActiveFor(LOG_LEVEL_DEBUG_MORE)) {
addLog(LOG_LEVEL_DEBUG_MORE, F("HTTP after parsing: "));
addLog(LOG_LEVEL_DEBUG_MORE, s);
}
#endif
# endif // ifndef BUILD_NO_DEBUG
parseControllerVariables(s, event, !sendBinary);
#ifndef BUILD_NO_DEBUG
# ifndef BUILD_NO_DEBUG
if (loglevelActiveFor(LOG_LEVEL_DEBUG_MORE)) {
addLog(LOG_LEVEL_DEBUG_MORE, F("HTTP after replacements: "));
addLog(LOG_LEVEL_DEBUG_MORE, s);
}
#endif
# endif // ifndef BUILD_NO_DEBUG
}
#endif // ifdef USES_C011
+9 -1
View File
@@ -59,7 +59,15 @@ bool CPlugin_012(CPlugin::Function function, struct EventStruct *event, String&
// Collect the values at the same run, to make sure all are from the same sample
uint8_t valueCount = getValueCountForTask(event->TaskIndex);
std::unique_ptr<C012_queue_element> element(new (std::nothrow) C012_queue_element(event, valueCount));
constexpr unsigned size = sizeof(C012_queue_element);
void *ptr = special_calloc(1, size);
if (ptr == nullptr) {
break;
}
std::unique_ptr<C012_queue_element> element(new (ptr) C012_queue_element(event, valueCount));
for (uint8_t x = 0; x < valueCount; x++)
{
+74 -61
View File
@@ -30,32 +30,35 @@
# define CPLUGIN_015_RECONNECT_INTERVAL 60000
# ifdef CPLUGIN_015_SSL
#ifdef ESP8266
# include <BlynkSimpleEsp8266_SSL.h>
#endif
#ifdef ESP32
# include <BlynkSimpleEsp32_SSL.h>
#endif
# ifdef ESP8266
# include <BlynkSimpleEsp8266_SSL.h>
# endif
# ifdef ESP32
# include <BlynkSimpleEsp32_SSL.h>
# endif
# define CPLUGIN_NAME_015 "Blynk SSL"
// Current official blynk server thumbprint
# define CPLUGIN_015_DEFAULT_THUMBPRINT "FD C0 7D 8D 47 97 F7 E3 07 05 D3 4E E3 BB 8E 3D C0 EA BE 1C"
# define C015_LOG_PREFIX "BL (ssl): "
# else // ifdef CPLUGIN_015_SSL
#ifdef ESP8266
# include <BlynkSimpleEsp8266.h>
#endif
#ifdef ESP32
# include <BlynkSimpleEsp32.h>
#endif
# ifdef ESP8266
# include <BlynkSimpleEsp8266.h>
# endif
# ifdef ESP32
# include <BlynkSimpleEsp32.h>
# endif
# define CPLUGIN_NAME_015 "Blynk"
# define C015_LOG_PREFIX "BL: "
# endif // ifdef CPLUGIN_015_SSL
// Forward declarations:
boolean Blynk_send_c015(const String& value, int vPin, unsigned int clientTimeout);
boolean Blynk_keep_connection_c015(int controllerIndex, ControllerSettingsStruct& ControllerSettings);
boolean Blynk_send_c015(const String& value,
int vPin,
unsigned int clientTimeout);
boolean Blynk_keep_connection_c015(int controllerIndex,
ControllerSettingsStruct& ControllerSettings);
static unsigned long _C015_LastConnectAttempt[CONTROLLER_MAX] = { 0, 0, 0 };
@@ -119,7 +122,7 @@ bool CPlugin_015(CPlugin::Function function, struct EventStruct *event, String&
# ifdef CPLUGIN_015_SSL
case CPlugin::Function::CPLUGIN_WEBFORM_LOAD:
{
char thumbprint[60] = {0};
char thumbprint[60] = { 0 };
LoadCustomControllerSettings(event->ControllerIndex, reinterpret_cast<uint8_t *>(&thumbprint), sizeof(thumbprint));
if (strlen(thumbprint) != 59) {
@@ -141,6 +144,7 @@ bool CPlugin_015(CPlugin::Function function, struct EventStruct *event, String&
if (validProtocolIndex(ProtocolIndex)) {
const cpluginID_t number = getCPluginID_from_ProtocolIndex(ProtocolIndex);
if ((i != event->ControllerIndex) && (number == 15) && Settings.ControllerEnabled[i]) {
success = false;
@@ -156,8 +160,8 @@ bool CPlugin_015(CPlugin::Function function, struct EventStruct *event, String&
_C015_LastConnectAttempt[event->ControllerIndex] = 0;
# ifdef CPLUGIN_015_SSL
char thumbprint[60] = {0};
String error = F("Specify server thumbprint with exactly 59 symbols string like " CPLUGIN_015_DEFAULT_THUMBPRINT);
char thumbprint[60] = { 0 };
String error = F("Specify server thumbprint with exactly 59 symbols string like " CPLUGIN_015_DEFAULT_THUMBPRINT);
if (!safe_strncpy(thumbprint, webArg("c015_thumbprint"), 60) || (strlen(thumbprint) != 59)) {
addHtmlError(error);
@@ -173,6 +177,7 @@ bool CPlugin_015(CPlugin::Function function, struct EventStruct *event, String&
if (C015_DelayHandler == nullptr) {
break;
}
if (C015_DelayHandler->queueFull(event->ControllerIndex)) {
break;
}
@@ -184,8 +189,13 @@ bool CPlugin_015(CPlugin::Function function, struct EventStruct *event, String&
// Collect the values at the same run, to make sure all are from the same sample
uint8_t valueCount = getValueCountForTask(event->TaskIndex);
std::unique_ptr<C015_queue_element> element(new (std::nothrow) C015_queue_element(event, valueCount));
success = C015_DelayHandler->addToQueue(std::move(element));
constexpr unsigned size = sizeof(C015_queue_element);
void *ptr = special_calloc(1, size);
if (ptr != nullptr) {
std::unique_ptr<C015_queue_element> element(new (ptr) C015_queue_element(event, valueCount));
success = C015_DelayHandler->addToQueue(std::move(element));
}
if (success) {
// Element was added.
@@ -205,19 +215,20 @@ bool CPlugin_015(CPlugin::Function function, struct EventStruct *event, String&
free_string(formattedValue);
}
const String valueName = Cache.getTaskDeviceValueName(event->TaskIndex, x);
const String valueName = Cache.getTaskDeviceValueName(event->TaskIndex, x);
const String valueFullName = strformat(
F("%s.%s"),
F("%s.%s"),
taskDeviceName.c_str(),
valueName.c_str());
const String vPinNumberStr = valueName.substring(1, 4);
int vPinNumber = vPinNumberStr.toInt();
int vPinNumber = vPinNumberStr.toInt();
if ((vPinNumber < 0) || (vPinNumber > 255)) {
vPinNumber = -1;
}
if (loglevelActiveFor(LOG_LEVEL_INFO)) {
String log = F(C015_LOG_PREFIX);
String log = F(C015_LOG_PREFIX);
log += Blynk.connected() ? F("(online): ") : F("(offline): ");
if ((vPinNumber > 0) && (vPinNumber < 256)) {
@@ -228,9 +239,9 @@ bool CPlugin_015(CPlugin::Function function, struct EventStruct *event, String&
vPinNumber);
} else {
log += strformat(
F("error got vPin number for %s, got not valid value: %s"),
valueFullName.c_str(),
vPinNumberStr.c_str());
F("error got vPin number for %s, got not valid value: %s"),
valueFullName.c_str(),
vPinNumberStr.c_str());
}
addLogMove(LOG_LEVEL_INFO, log);
}
@@ -257,34 +268,35 @@ bool CPlugin_015(CPlugin::Function function, struct EventStruct *event, String&
// *INDENT-OFF*
bool do_process_c015_delay_queue(cpluginID_t cpluginID, const Queue_element_base& element_base, ControllerSettingsStruct& ControllerSettings) {
const C015_queue_element& element = static_cast<const C015_queue_element&>(element_base);
// *INDENT-ON*
if (!Settings.ControllerEnabled[element._controller_idx]) {
// controller has been disabled. Answer true to flush queue.
if (!Settings.ControllerEnabled[element._controller_idx]) {
// controller has been disabled. Answer true to flush queue.
return true;
}
if (!NetworkConnected()) {
return false;
}
if (!Blynk_keep_connection_c015(element._controller_idx, ControllerSettings)) {
return false;
}
while (element.vPin[element.valuesSent] == -1) {
// A non valid value, which we are not going to send.
// answer ok and skip real sending
if (element.checkDone(true)) {
return true;
}
}
if (!NetworkConnected()) {
return false;
}
bool sendSuccess = Blynk_send_c015(
element.txt[element.valuesSent],
element.vPin[element.valuesSent],
ControllerSettings.ClientTimeout);
if (!Blynk_keep_connection_c015(element._controller_idx, ControllerSettings)) {
return false;
}
while (element.vPin[element.valuesSent] == -1) {
// A non valid value, which we are not going to send.
// answer ok and skip real sending
if (element.checkDone(true)) {
return true;
}
}
bool sendSuccess = Blynk_send_c015(
element.txt[element.valuesSent],
element.vPin[element.valuesSent],
ControllerSettings.ClientTimeout);
return element.checkDone(sendSuccess);
return element.checkDone(sendSuccess);
}
boolean Blynk_keep_connection_c015(int controllerIndex, ControllerSettingsStruct& ControllerSettings) {
@@ -303,7 +315,7 @@ boolean Blynk_keep_connection_c015(int controllerIndex, ControllerSettingsStruct
_C015_LastConnectAttempt[controllerIndex] = millis();
# ifdef CPLUGIN_015_SSL
char thumbprint[60] = {0};
char thumbprint[60] = { 0 };
LoadCustomControllerSettings(controllerIndex, reinterpret_cast<uint8_t *>(&thumbprint), sizeof(thumbprint));
if (strlen(thumbprint) != 59) {
@@ -312,6 +324,7 @@ boolean Blynk_keep_connection_c015(int controllerIndex, ControllerSettingsStruct
addLog(LOG_LEVEL_INFO, thumbprint);
}
strcpy(thumbprint, CPLUGIN_015_DEFAULT_THUMBPRINT);
if (loglevelActiveFor(LOG_LEVEL_INFO)) {
addLog(LOG_LEVEL_INFO, F(C015_LOG_PREFIX "using default one:"));
addLog(LOG_LEVEL_INFO, thumbprint);
@@ -421,9 +434,9 @@ String Command_Blynk_Set_c015(struct EventStruct *event, const char *Line) {
if (loglevelActiveFor(LOG_LEVEL_INFO)) {
addLogMove(LOG_LEVEL_INFO, strformat(
F(C015_LOG_PREFIX "(online): send blynk pin v%d = %s"),
vPin,
data.c_str()));
F(C015_LOG_PREFIX "(online): send blynk pin v%d = %s"),
vPin,
data.c_str()));
}
Blynk.virtualWrite(vPin, data);
@@ -449,16 +462,16 @@ BLYNK_WRITE_DEFAULT() {
if (loglevelActiveFor(LOG_LEVEL_INFO)) {
addLogMove(LOG_LEVEL_INFO, strformat(
F(C015_LOG_PREFIX "server set v%u to %f"),
vPin,
pinValue));
F(C015_LOG_PREFIX "server set v%u to %f"),
vPin,
pinValue));
}
if (Settings.UseRules) {
eventQueue.addMove(strformat(
F("blynkv%d=%f"),
vPin,
pinValue));
eventQueue.addMove(strformat(
F("blynkv%d=%f"),
vPin,
pinValue));
}
}
@@ -491,4 +504,4 @@ BLYNK_APP_DISCONNECTED() {
// addLog(LOG_LEVEL_INFO, F(C015_LOG_PREFIX "app disconnected handler"));
}
#endif // ifdef USES_C015
#endif // ifdef USES_C015
+7 -2
View File
@@ -67,8 +67,13 @@ bool CPlugin_017(CPlugin::Function function, struct EventStruct *event, String&
break;
}
std::unique_ptr<C017_queue_element> element(new (std::nothrow) C017_queue_element(event));
success = C017_DelayHandler->addToQueue(std::move(element));
constexpr unsigned size = sizeof(C017_queue_element);
void *ptr = special_calloc(1, size);
if (ptr != nullptr) {
std::unique_ptr<C017_queue_element> element(new (ptr) C017_queue_element(event));
success = C017_DelayHandler->addToQueue(std::move(element));
}
Scheduler.scheduleNextDelayQueue(SchedulerIntervalTimer_e::TIMER_C017_DELAY_QUEUE, C017_DelayHandler->getNextScheduleTime());
break;
}
+41 -7
View File
@@ -127,7 +127,14 @@ bool CPlugin_018(CPlugin::Function function, struct EventStruct *event, String&
{
// Keep this object in a small scope so we can destruct it as soon as possible again.
std::shared_ptr<C018_ConfigStruct> customConfig(new (std::nothrow) C018_ConfigStruct);
constexpr unsigned size = sizeof(C018_ConfigStruct);
void *ptr = special_calloc(1, size);
if (ptr == nullptr) {
break;
}
std::shared_ptr<C018_ConfigStruct> customConfig(new (ptr) C018_ConfigStruct);
if (!customConfig) {
break;
@@ -140,7 +147,13 @@ bool CPlugin_018(CPlugin::Function function, struct EventStruct *event, String&
}
case CPlugin::Function::CPLUGIN_WEBFORM_SAVE:
{
std::shared_ptr<C018_ConfigStruct> customConfig(new (std::nothrow) C018_ConfigStruct);
constexpr unsigned size = sizeof(C018_ConfigStruct);
void *ptr = special_calloc(1, size);
if (ptr == nullptr) {
break;
}
std::shared_ptr<C018_ConfigStruct> customConfig(new (ptr) C018_ConfigStruct);
if (customConfig) {
customConfig->webform_save();
@@ -186,7 +199,14 @@ bool CPlugin_018(CPlugin::Function function, struct EventStruct *event, String&
if (C018_data != nullptr) {
{
std::unique_ptr<C018_queue_element> element(new (std::nothrow) C018_queue_element(event, C018_data->getSampleSetCount(event->TaskIndex)));
constexpr unsigned size = sizeof(C018_queue_element);
void *ptr = special_calloc(1, size);
if (ptr == nullptr) {
break;
}
std::unique_ptr<C018_queue_element> element(new (ptr) C018_queue_element(event, C018_data->getSampleSetCount(event->TaskIndex)));
success = C018_DelayHandler->addToQueue(std::move(element));
Scheduler.scheduleNextDelayQueue(SchedulerIntervalTimer_e::TIMER_C018_DELAY_QUEUE,
C018_DelayHandler->getNextScheduleTime());
@@ -274,11 +294,19 @@ bool C018_init(struct EventStruct *event) {
C018_data = nullptr;
}
{
constexpr unsigned size = sizeof(C018_data_struct);
void *ptr = special_calloc(1, size);
C018_data = new (std::nothrow) C018_data_struct;
if (ptr == nullptr) {
return false;
}
if (C018_data == nullptr) {
return false;
C018_data = new (ptr) C018_data_struct;
if (C018_data == nullptr) {
return false;
}
}
{
// Allocate ControllerSettings object in a scope, so we can destruct it as soon as possible.
@@ -296,7 +324,13 @@ bool C018_init(struct EventStruct *event) {
Port = ControllerSettings->Port;
}
std::shared_ptr<C018_ConfigStruct> customConfig(new (std::nothrow) C018_ConfigStruct);
constexpr unsigned size = sizeof(C018_ConfigStruct);
void *ptr = special_calloc(1, size);
if (ptr == nullptr) {
return false;
}
std::shared_ptr<C018_ConfigStruct> customConfig(new (ptr) C018_ConfigStruct);
if (!customConfig) {
return false;
@@ -2,6 +2,8 @@
#if FEATURE_RTC_CACHE_STORAGE
#include "../Helpers/Memory.h"
ControllerCache_struct::~ControllerCache_struct() {
if (_RTC_cache_handler != nullptr) {
delete _RTC_cache_handler;
@@ -33,11 +35,12 @@ bool ControllerCache_struct::flush() {
void ControllerCache_struct::init() {
if (_RTC_cache_handler == nullptr) {
# ifdef USE_SECOND_HEAP
// HeapSelectIram ephemeral;
# endif // ifdef USE_SECOND_HEAP
constexpr unsigned size = sizeof(RTC_cache_handler_struct);
void *ptr = special_calloc(1, size);
_RTC_cache_handler = new (std::nothrow) RTC_cache_handler_struct;
if (ptr != nullptr) {
_RTC_cache_handler = new (ptr) RTC_cache_handler_struct;
}
if (_RTC_cache_handler != nullptr) {
_RTC_cache_handler->init();
}
+6 -1
View File
@@ -60,7 +60,12 @@ void PluginTaskData_base::initPluginStats(taskIndex_t taskIndex, taskVarIndex_t
{
if (taskVarIndex < VARS_PER_TASK) {
if (_plugin_stats_array == nullptr) {
_plugin_stats_array = new (std::nothrow) PluginStats_array();
constexpr unsigned size = sizeof(PluginStats_array);
void *ptr = special_calloc(1, size);
if (ptr != nullptr) {
_plugin_stats_array = new (ptr) PluginStats_array();
}
}
if (_plugin_stats_array != nullptr) {
-1
View File
@@ -55,7 +55,6 @@ struct ProvisioningStruct
};
typedef std::shared_ptr<ProvisioningStruct> ProvisioningStruct_ptr_type;
//# define MakeProvisioningSettings(T) ProvisioningStruct_ptr_type T(new (std::nothrow) ProvisioningStruct());
#define MakeProvisioningSettings(T) void * calloc_ptr = special_calloc(1,sizeof(ProvisioningStruct)); ProvisioningStruct_ptr_type T(new (calloc_ptr) ProvisioningStruct());
+1 -1
View File
@@ -456,7 +456,7 @@ bool PluginCallForTask(taskIndex_t taskIndex, uint8_t Function, EventStruct *Tem
void *ptr = special_calloc(1, size);
if (ptr) {
initPluginTaskData(taskIndex, new (std::nothrow) _StatsOnly_data_struct());
initPluginTaskData(taskIndex, new (ptr) _StatsOnly_data_struct());
}
}
}
+16 -2
View File
@@ -685,7 +685,12 @@ bool SSDP_begin() {
_server = nullptr;
}
_server = new (std::nothrow) UdpContext;
constexpr unsigned size = sizeof(UdpContext);
void *ptr = special_calloc(1, size);
if (ptr != nullptr) {
_server = new (ptr) UdpContext;
}
if (_server == nullptr) {
return false;
@@ -770,7 +775,16 @@ void SSDP_send(uint8_t method) {
(uint16_t)((chipId >> 8) & 0xff),
(uint16_t)chipId & 0xff);
char *buffer = new (std::nothrow) char[1460]();
char *buffer = nullptr;
# ifdef USE_SECOND_HEAP
{
HeapSelectIram ephemeral;
buffer = new (std::nothrow) char[1460]();
}
# endif // ifdef USE_SECOND_HEAP
if (buffer == nullptr) {
buffer = new (std::nothrow) char[1460]();
}
if (buffer == nullptr) { return; }
int len = snprintf(buffer, 1460,
+6 -1
View File
@@ -174,7 +174,12 @@ void handleFileUploadBase(bool toSDcard) {
# if FEATURE_TARSTREAM_SUPPORT
if ((upload.filename.length() > 3) && upload.filename.substring(upload.filename.length() - 4).equalsIgnoreCase(F(".tar"))) {
tarStream = new (std::nothrow) TarStream(upload.filename, destination);
constexpr unsigned size = sizeof(TarStream);
void *ptr = special_calloc(1, size);
if (ptr != nullptr) {
tarStream = new (ptr) TarStream(upload.filename, destination);
}
# ifndef BUILD_NO_DEBUG
if (loglevelActiveFor(LOG_LEVEL_INFO)) {