[FEATURE_SD] Fix build issues when FEATURE_SD is defined (not finished)

When enabling the FEATURE_SD, something with the define of __FlashStringHelper is not correct anymore.

This needs a lot of changes which were needed anyway.
But also arrays of __FlashStringHelper must be changed.

All done so far, only need to have a look at    
static const __FlashStringHelper *gpMenu[8][3] = {
This commit is contained in:
Gijs Noorlander
2019-10-29 18:07:48 +01:00
parent 682bcbec2b
commit c49142402e
23 changed files with 671 additions and 519 deletions
+2
View File
@@ -24,6 +24,8 @@
#include "src/Commands/wd.h"
#include "src/Commands/WiFi.h"
#include "define_plugin_sets.h"
/*********************************************************************************************\
* Registers command
+1 -1
View File
@@ -365,7 +365,7 @@ void SendStatus(byte source, const String& status)
}
#ifdef USES_MQTT
boolean MQTTpublish(int controller_idx, const char *topic, const char *payload, boolean retained)
bool MQTTpublish(int controller_idx, const char *topic, const char *payload, boolean retained)
{
const bool success = MQTTDelayHandler.addToQueue(MQTT_queue_element(controller_idx, topic, payload, retained));
+21 -25
View File
@@ -1,39 +1,35 @@
/*********************************************************************************************\
Convert bearing in degree to bearing string
\*********************************************************************************************/
String getBearing(int degrees)
{
const __FlashStringHelper *bearing[] = {
F("N"),
F("NNE"),
F("NE"),
F("ENE"),
F("E"),
F("ESE"),
F("SE"),
F("SSE"),
F("S"),
F("SSW"),
F("SW"),
F("WSW"),
F("W"),
F("WNW"),
F("NW"),
F("NNW")
};
int nr_directions = (int)(sizeof(bearing) / sizeof(bearing[0]));
const int nr_directions = 16;
float stepsize = (360.0 / nr_directions);
if (degrees < 0) { degrees += 360; } // Allow for bearing -360 .. 359
int bearing_idx = int((degrees + (stepsize / 2.0)) / stepsize) % nr_directions;
if (bearing_idx < 0) {
return "";
}
else {
return bearing[bearing_idx];
if (bearing_idx >= 0) {
switch (bearing_idx) {
case 0: return F("N");
case 1: return F("NNE");
case 2: return F("NE");
case 3: return F("ENE");
case 4: return F("E");
case 5: return F("ESE");
case 6: return F("SE");
case 7: return F("SSE");
case 8: return F("S");
case 9: return F("SSW");
case 10: return F("SW");
case 11: return F("WSW");
case 12: return F("W");
case 13: return F("WNW");
case 14: return F("NW");
case 15: return F("NNW");
}
}
return "";
}
float CelsiusToFahrenheit(float celsius) {
+27 -1
View File
@@ -113,7 +113,7 @@ byte getProtocolIndex(byte Number);
// void runPeriodicalMQTT();
// void updateMQTTclient_connected();
// int firstEnabledMQTTController();
int firstEnabledMQTTController();
// String getMQTT_state();
void callback(char *c_topic,
byte *b_payload,
@@ -122,6 +122,7 @@ void MQTTDisconnect();
bool MQTTConnect(int controller_idx);
bool MQTTCheck(int controller_idx);
void schedule_all_tasks_using_MQTT_controller();
bool MQTTpublish(int controller_idx, const char *topic, const char *payload, boolean retained);
#endif // ifdef USES_MQTT
@@ -147,4 +148,29 @@ String parseStringKeepCase(const String& string, byte indexFind);
String parseStringToEnd(const String& string, byte indexFind);
String parseStringToEndKeepCase(const String& string, byte indexFind);
String describeAllowedIPrange();
void clearAccessBlock();
String rulesProcessingFile(const String& fileName, String& event);
int Calculate(const char *input, float* result);
# include <ESP8266WiFiType.h>
void WifiScan();
void WiFiConnectRelaxed();
void WifiDisconnect();
void setAP(bool enable);
void setSTA(bool enable);
void setWifiMode(WiFiMode_t wifimode);
String SaveSettings(void);
String LoadSettings();
unsigned long FreeMem(void);
void ResetFactory();
void reboot();
void SendUDPCommand(byte destUnit, char *data, byte dataLength);
#include <FS.h>
void printDirectory(File dir, int numTabs);
#endif // ESPEASY_FWD_DECL_H
+6 -17
View File
@@ -2343,6 +2343,7 @@ void SendValueLogger(taskIndex_t TaskIndex)
{
#if !defined(BUILD_NO_DEBUG) || defined(FEATURE_SD)
bool featureSD = false;
String logger;
#ifdef FEATURE_SD
featureSD = true;
#endif
@@ -2350,7 +2351,6 @@ void SendValueLogger(taskIndex_t TaskIndex)
if (featureSD || loglevelActiveFor(LOG_LEVEL_DEBUG)) {
deviceIndex_t DeviceIndex = getDeviceIndex_from_TaskIndex(TaskIndex);
if (validDeviceIndex(DeviceIndex)) {
String logger;
LoadTaskSettings(TaskIndex);
for (byte varNr = 0; varNr < Device[DeviceIndex].ValueCount; varNr++)
{
@@ -2465,29 +2465,18 @@ void checkRAMtoLog(void){
myRamTracker.getTraceBuffer();
}
void checkRAM(const __FlashStringHelper* flashString, int a ) {
String s=String(a);
checkRAM(flashString,s);
}
void checkRAM(const __FlashStringHelper* flashString, const String &a ) {
String s = flashString;
checkRAM(s,a);
void checkRAM(const String &flashString, int a ) {
checkRAM(flashString, String(a));
}
void checkRAM(const String &flashString, const String &a ) {
String s = flashString;
s+=" (";
s+=a;
s+=")";
s += " (";
s += a;
s += ')';
checkRAM(s);
}
void checkRAM( const __FlashStringHelper* flashString)
{
checkRAM(String(flashString));
}
void checkRAM( const String &descr ) {
myRamTracker.registerRamState(descr);
+17 -18
View File
@@ -42,13 +42,12 @@ String return_see_serial(struct EventStruct *event)
return F("Output sent to serial");
}
String Command_GetORSetIP(struct EventStruct *event,
const __FlashStringHelper *targetDescription,
const char *Line,
byte *IP,
IPAddress dhcpIP,
int arg)
String Command_GetORSetIP(struct EventStruct *event,
const String & targetDescription,
const char *Line,
byte *IP,
IPAddress dhcpIP,
int arg)
{
bool hasArgument = false;
{
@@ -81,12 +80,12 @@ String Command_GetORSetIP(struct EventStruct *event,
return return_command_success();
}
String Command_GetORSetString(struct EventStruct *event,
const __FlashStringHelper *targetDescription,
const char *Line,
char *target,
size_t len,
int arg
String Command_GetORSetString(struct EventStruct *event,
const String & targetDescription,
const char *Line,
char *target,
size_t len,
int arg
)
{
bool hasArgument = false;
@@ -118,11 +117,11 @@ String Command_GetORSetString(struct EventStruct *event,
return return_command_success();
}
String Command_GetORSetBool(struct EventStruct *event,
const __FlashStringHelper *targetDescription,
const char *Line,
bool *value,
int arg)
String Command_GetORSetBool(struct EventStruct *event,
const String & targetDescription,
const char *Line,
bool *value,
int arg)
{
bool hasArgument = false;
{
+20 -19
View File
@@ -9,30 +9,31 @@ class IPAddress;
String return_command_success();
String return_command_failed();
String return_not_connected();
String return_result(struct EventStruct *event, const String& result);
String return_result(struct EventStruct *event,
const String & result);
String return_see_serial(struct EventStruct *event);
bool IsNumeric(const char *source);
bool IsNumeric(const char *source);
String Command_GetORSetIP(struct EventStruct *event,
const __FlashStringHelper *targetDescription,
const char *Line,
byte *IP,
IPAddress dhcpIP,
int arg);
String Command_GetORSetIP(struct EventStruct *event,
const String & targetDescription,
const char *Line,
byte *IP,
IPAddress dhcpIP,
int arg);
String Command_GetORSetString(struct EventStruct *event,
const __FlashStringHelper *targetDescription,
const char *Line,
char *target,
size_t len,
int arg
String Command_GetORSetString(struct EventStruct *event,
const String & targetDescription,
const char *Line,
char *target,
size_t len,
int arg
);
String Command_GetORSetBool(struct EventStruct *event,
const __FlashStringHelper *targetDescription,
const char *Line,
bool *value,
int arg);
String Command_GetORSetBool(struct EventStruct *event,
const String & targetDescription,
const char *Line,
bool *value,
int arg);
#endif // COMMAND_COMMON_H
+69
View File
@@ -0,0 +1,69 @@
#include "MQTT.h"
#include "../../ESPEasy_common.h"
#include "../Commands/Common.h"
#include "../Globals/Settings.h"
#include "../../ESPEasy_fdwdecl.h"
String Command_MQTT_Retain(struct EventStruct *event, const char *Line)
{
return Command_GetORSetBool(event, F("MQTT Retain:"),
Line,
(bool *)&Settings.MQTTRetainFlag,
1);
}
String Command_MQTT_UseUnitNameAsClientId(struct EventStruct *event, const char *Line)
{
return Command_GetORSetBool(event, F("MQTT Use Unit Name as ClientId:"),
Line,
(bool *)&Settings.MQTTUseUnitNameAsClientId,
1);
}
String Command_MQTT_messageDelay(struct EventStruct *event, const char *Line)
{
if (HasArgv(Line, 2)) {
Settings.MessageDelay = event->Par1;
}
else {
String result = F("MQTT message delay:");
result += Settings.MessageDelay;
serialPrintln();
serialPrintln(result);
return result;
}
return return_command_success();
}
String Command_MQTT_Publish(struct EventStruct *event, const char *Line)
{
if (WiFiConnected()) {
// ToDo TD-er: Not sure about this function, but at least it sends to an existing MQTTclient
int enabledMqttController = firstEnabledMQTTController();
if (enabledMqttController >= 0) {
// Command structure: Publish,<topic>,<value>
String topic = parseStringKeepCase(Line, 1);
String value = parseStringKeepCase(Line, 2);
if ((topic.length() > 0) && (value.length() > 0)) {
// @giig1967g: if payload starts with '=' then treat it as a Formula and evaluate accordingly
// The evaluated value is already present in event->Par2
// FIXME TD-er: Is the evaluated value always present in event->Par2 ?
// Should it already be evaluated, or should we evaluate it now?
if (value.c_str()[0] != '=') {
MQTTpublish(enabledMqttController, topic.c_str(), value.c_str(), Settings.MQTTRetainFlag);
}
else {
MQTTpublish(enabledMqttController, topic.c_str(), String(event->Par2).c_str(), Settings.MQTTRetainFlag);
}
}
return return_command_success();
}
return F("No MQTT controller enabled");
}
return return_not_connected();
}
+5 -59
View File
@@ -1,66 +1,12 @@
#ifndef COMMAND_MQTT_H
#define COMMAND_MQTT_H
class String;
String Command_MQTT_Retain(struct EventStruct *event, const char *Line)
{
return Command_GetORSetBool(event, F("MQTT Retain:"),
Line,
(bool *)&Settings.MQTTRetainFlag,
1);
}
String Command_MQTT_Retain(struct EventStruct *event, const char *Line);
String Command_MQTT_UseUnitNameAsClientId(struct EventStruct *event, const char *Line);
String Command_MQTT_messageDelay(struct EventStruct *event, const char *Line);
String Command_MQTT_Publish(struct EventStruct *event, const char *Line);
String Command_MQTT_UseUnitNameAsClientId(struct EventStruct *event, const char *Line)
{
return Command_GetORSetBool(event, F("MQTT Use Unit Name as ClientId:"),
Line,
(bool *)&Settings.MQTTUseUnitNameAsClientId,
1);
}
String Command_MQTT_messageDelay(struct EventStruct *event, const char *Line)
{
if (HasArgv(Line, 2)) {
Settings.MessageDelay = event->Par1;
}
else {
String result = F("MQTT message delay:");
result += Settings.MessageDelay;
serialPrintln();
serialPrintln(result);
return result;
}
return return_command_success();
}
String Command_MQTT_Publish(struct EventStruct *event, const char *Line)
{
if (WiFiConnected()) {
// ToDo TD-er: Not sure about this function, but at least it sends to an existing MQTTclient
int enabledMqttController = firstEnabledMQTTController();
if (enabledMqttController >= 0) {
// Command structure: Publish,<topic>,<value>
String topic = parseStringKeepCase(Line, 1);
String value = parseStringKeepCase(Line, 2);
if ((topic.length() > 0) && (value.length() > 0)) {
// @giig1967g: if payload starts with '=' then treat it as a Formula and evaluate accordingly
// The evaluated value is already present in event->Par2
// FIXME TD-er: Is the evaluated value always present in event->Par2 ?
// Should it already be evaluated, or should we evaluate it now?
if (value.c_str()[0] != '=') {
MQTTpublish(enabledMqttController, topic.c_str(), value.c_str(), Settings.MQTTRetainFlag);
}
else {
MQTTpublish(enabledMqttController, topic.c_str(), String(event->Par2).c_str(), Settings.MQTTRetainFlag);
}
}
return return_command_success();
}
return F("No MQTT controller enabled");
}
return return_not_connected();
}
#endif // COMMAND_MQTT_H
+41
View File
@@ -0,0 +1,41 @@
#include "Networks.h"
#include "../../ESPEasy_common.h"
#include "../Commands/Common.h"
#include "../Globals/Settings.h"
#include "../../ESPEasy_fdwdecl.h"
String Command_AccessInfo_Ls(struct EventStruct *event, const char* Line)
{
String result = F("Allowed IP range : ");
result += describeAllowedIPrange();
return return_result(event, result);
}
String Command_AccessInfo_Clear (struct EventStruct *event, const char* Line)
{
clearAccessBlock();
return Command_AccessInfo_Ls(event, Line);
}
String Command_DNS (struct EventStruct *event, const char* Line)
{
return Command_GetORSetIP(event, F("DNS:"), Line, Settings.DNS,WiFi.dnsIP(0),1);
}
String Command_Gateway (struct EventStruct *event, const char* Line)
{
return Command_GetORSetIP(event, F("Gateway:"), Line, Settings.Gateway,WiFi.gatewayIP(),1);
}
String Command_IP (struct EventStruct *event, const char* Line)
{
return Command_GetORSetIP(event, F("IP:"), Line, Settings.IP,WiFi.localIP(),1);
}
String Command_Subnet (struct EventStruct *event, const char* Line)
{
return Command_GetORSetIP(event, F("Subnet:"), Line, Settings.Subnet,WiFi.subnetMask(),1);
}
+7 -33
View File
@@ -1,40 +1,14 @@
#ifndef COMMAND_NETWORKS_H
#define COMMAND_NETWORKS_H
class String;
String Command_AccessInfo_Ls(struct EventStruct *event, const char* Line)
{
String result = F("Allowed IP range : ");
result += describeAllowedIPrange();
return return_result(event, result);
}
String Command_AccessInfo_Clear (struct EventStruct *event, const char* Line)
{
clearAccessBlock();
return Command_AccessInfo_Ls(event, Line);
}
String Command_DNS (struct EventStruct *event, const char* Line)
{
return Command_GetORSetIP(event, F("DNS:"), Line, Settings.DNS,WiFi.dnsIP(0),1);
}
String Command_Gateway (struct EventStruct *event, const char* Line)
{
return Command_GetORSetIP(event, F("Gateway:"), Line, Settings.Gateway,WiFi.gatewayIP(),1);
}
String Command_IP (struct EventStruct *event, const char* Line)
{
return Command_GetORSetIP(event, F("IP:"), Line, Settings.IP,WiFi.localIP(),1);
}
String Command_Subnet (struct EventStruct *event, const char* Line)
{
return Command_GetORSetIP(event, F("Subnet:"), Line, Settings.Subnet,WiFi.subnetMask(),1);
}
String Command_AccessInfo_Ls(struct EventStruct *event, const char* Line);
String Command_AccessInfo_Clear (struct EventStruct *event, const char* Line);
String Command_DNS (struct EventStruct *event, const char* Line);
String Command_Gateway (struct EventStruct *event, const char* Line);
String Command_IP (struct EventStruct *event, const char* Line);
String Command_Subnet (struct EventStruct *event, const char* Line);
#endif // COMMAND_NETWORKS_H
+54
View File
@@ -0,0 +1,54 @@
#include "Rules.h"
#include "../../ESPEasy_common.h"
#include "../Commands/Common.h"
#include "../Globals/Settings.h"
#include "../../ESPEasy-Globals.h"
#include "../../ESPEasy_fdwdecl.h"
String Command_Rules_Execute(struct EventStruct *event, const char *Line)
{
String filename;
if (GetArgv(Line, filename, 2)) {
String event;
rulesProcessingFile(filename, event);
}
return return_command_success();
}
String Command_Rules_UseRules(struct EventStruct *event, const char *Line)
{
return Command_GetORSetBool(event, F("Rules:"),
Line,
(bool *)&Settings.UseRules,
1);
}
String Command_Rules_Events(struct EventStruct *event, const char *Line)
{
String eventName = Line;
eventName = eventName.substring(6);
eventName.replace('$', '#');
if (Settings.UseRules) {
rulesProcessing(eventName);
}
return return_command_success();
}
String Command_Rules_Let(struct EventStruct *event, const char *Line)
{
String TmpStr1;
if (GetArgv(Line, TmpStr1, 3)) {
float result = 0.0;
Calculate(TmpStr1.c_str(), &result);
customFloatVar[event->Par1 - 1] = result;
}
return return_command_success();
}
+5 -44
View File
@@ -1,50 +1,11 @@
#ifndef COMMAND_RULES_H
#define COMMAND_RULES_H
class String;
String Command_Rules_Execute(struct EventStruct *event, const char *Line)
{
String filename;
if (GetArgv(Line, filename, 2)) {
String event;
rulesProcessingFile(filename, event);
}
return return_command_success();
}
String Command_Rules_UseRules(struct EventStruct *event, const char *Line)
{
return Command_GetORSetBool(event, F("Rules:"),
Line,
(bool *)&Settings.UseRules,
1);
}
String Command_Rules_Events(struct EventStruct *event, const char *Line)
{
String eventName = Line;
eventName = eventName.substring(6);
eventName.replace('$', '#');
if (Settings.UseRules) {
rulesProcessing(eventName);
}
return return_command_success();
}
String Command_Rules_Let(struct EventStruct *event, const char *Line)
{
String TmpStr1;
if (GetArgv(Line, TmpStr1, 3)) {
float result = 0.0;
Calculate(TmpStr1.c_str(), &result);
customFloatVar[event->Par1 - 1] = result;
}
return return_command_success();
}
String Command_Rules_Execute(struct EventStruct *event, const char *Line);
String Command_Rules_UseRules(struct EventStruct *event, const char *Line);
String Command_Rules_Events(struct EventStruct *event, const char *Line);
String Command_Rules_Let(struct EventStruct *event, const char *Line);
#endif // COMMAND_RULES_H
+34
View File
@@ -0,0 +1,34 @@
#include "SDCARD.h"
#include "../../ESPEasy_common.h"
#include "../Commands/Common.h"
#include "../Globals/Settings.h"
#include "../../ESPEasy_fdwdecl.h"
#ifdef FEATURE_SD
#include <SD.h>
String Command_SD_LS(struct EventStruct *event, const char* Line)
{
File root = SD.open("/");
root.rewindDirectory();
printDirectory(root, 0);
root.close();
return return_see_serial(event);
}
String Command_SD_Remove(struct EventStruct *event, const char* Line)
{
String fname = Line;
fname = fname.substring(9);
String result = F("Removing:");
result += fname.c_str();
SD.remove((char*)fname.c_str());
return return_result(event, result);
}
#endif
+4 -17
View File
@@ -1,26 +1,13 @@
#ifndef COMMAND_SDCARD_H
#define COMMAND_SDCARD_H
class String;
#ifdef FEATURE_SD
String Command_SD_LS(struct EventStruct *event, const char* Line)
{
File root = SD.open("/");
root.rewindDirectory();
printDirectory(root, 0);
root.close();
return return_see_serial(event);
}
String Command_SD_Remove(struct EventStruct *event, const char* Line)
{
String fname = Line;
fname = fname.substring(9);
String result = F("Removing:");
result += fname.c_str();
SD.remove((char*)fname.c_str());
return return_result(event, result);
}
String Command_SD_LS(struct EventStruct *event, const char* Line);
String Command_SD_Remove(struct EventStruct *event, const char* Line);
#endif
#endif // COMMAND_SDCARD_H
+91
View File
@@ -0,0 +1,91 @@
#include "Settings.h"
#include "../../ESPEasy_common.h"
#include "../Commands/Common.h"
#include "../Globals/Settings.h"
#include "../Globals/SecuritySettings.h"
#include "../../ESPEasy_fdwdecl.h"
String Command_Settings_Build(struct EventStruct *event, const char* Line)
{
if (HasArgv(Line, 2)) {
Settings.Build = event->Par1;
} else {
serialPrintln();
String result = F("Build:");
result += Settings.Build;
return return_result(event, result);
}
return return_command_success();
}
String Command_Settings_Unit(struct EventStruct *event, const char* Line)
{
if (HasArgv(Line, 2)) {
Settings.Unit = event->Par1;
}else {
serialPrintln();
String result = F("Unit:");
result += Settings.Unit;
return return_result(event, result);
}
return return_command_success();
}
String Command_Settings_Name(struct EventStruct *event, const char* Line)
{
return Command_GetORSetString(event, F("Name:"),
Line,
Settings.Name,
sizeof(Settings.Name),
1);
}
String Command_Settings_Password(struct EventStruct *event, const char* Line)
{
return Command_GetORSetString(event, F("Password:"),
Line,
SecuritySettings.Password,
sizeof(SecuritySettings.Password),
1
);
}
String Command_Settings_Save(struct EventStruct *event, const char* Line)
{
SaveSettings();
return return_command_success();
}
String Command_Settings_Load(struct EventStruct *event, const char* Line)
{
LoadSettings();
return return_command_success();
}
String Command_Settings_Print(struct EventStruct *event, const char* Line)
{
serialPrintln();
serialPrintln(F("System Info"));
serialPrint(F(" IP Address : ")); serialPrintln(WiFi.localIP().toString());
serialPrint(F(" Build : ")); serialPrintln(String((int)BUILD));
serialPrint(F(" Name : ")); serialPrintln(Settings.Name);
serialPrint(F(" Unit : ")); serialPrintln(String((int)Settings.Unit));
serialPrint(F(" WifiSSID : ")); serialPrintln(SecuritySettings.WifiSSID);
serialPrint(F(" WifiKey : ")); serialPrintln(SecuritySettings.WifiKey);
serialPrint(F(" WifiSSID2 : ")); serialPrintln(SecuritySettings.WifiSSID2);
serialPrint(F(" WifiKey2 : ")); serialPrintln(SecuritySettings.WifiKey2);
serialPrint(F(" Free mem : ")); serialPrintln(String(FreeMem()));
return return_see_serial(event);
}
String Command_Settings_Reset(struct EventStruct *event, const char* Line)
{
ResetFactory();
reboot();
return return_command_success();
}
+9 -80
View File
@@ -1,88 +1,17 @@
#ifndef COMMAND_SETTINGS_H
#define COMMAND_SETTINGS_H
#include "../Globals/SecuritySettings.h"
String Command_Settings_Build(struct EventStruct *event, const char* Line)
{
if (HasArgv(Line, 2)) {
Settings.Build = event->Par1;
} else {
serialPrintln();
String result = F("Build:");
result += Settings.Build;
return return_result(event, result);
}
return return_command_success();
}
String Command_Settings_Unit(struct EventStruct *event, const char* Line)
{
if (HasArgv(Line, 2)) {
Settings.Unit = event->Par1;
}else {
serialPrintln();
String result = F("Unit:");
result += Settings.Unit;
return return_result(event, result);
}
return return_command_success();
}
String Command_Settings_Name(struct EventStruct *event, const char* Line)
{
return Command_GetORSetString(event, F("Name:"),
Line,
Settings.Name,
sizeof(Settings.Name),
1);
}
String Command_Settings_Password(struct EventStruct *event, const char* Line)
{
return Command_GetORSetString(event, F("Password:"),
Line,
SecuritySettings.Password,
sizeof(SecuritySettings.Password),
1
);
}
String Command_Settings_Save(struct EventStruct *event, const char* Line)
{
SaveSettings();
return return_command_success();
}
String Command_Settings_Load(struct EventStruct *event, const char* Line)
{
LoadSettings();
return return_command_success();
}
String Command_Settings_Print(struct EventStruct *event, const char* Line)
{
serialPrintln();
serialPrintln(F("System Info"));
serialPrint(F(" IP Address : ")); serialPrintln(WiFi.localIP().toString());
serialPrint(F(" Build : ")); serialPrintln(String((int)BUILD));
serialPrint(F(" Name : ")); serialPrintln(Settings.Name);
serialPrint(F(" Unit : ")); serialPrintln(String((int)Settings.Unit));
serialPrint(F(" WifiSSID : ")); serialPrintln(SecuritySettings.WifiSSID);
serialPrint(F(" WifiKey : ")); serialPrintln(SecuritySettings.WifiKey);
serialPrint(F(" WifiSSID2 : ")); serialPrintln(SecuritySettings.WifiSSID2);
serialPrint(F(" WifiKey2 : ")); serialPrintln(SecuritySettings.WifiKey2);
serialPrint(F(" Free mem : ")); serialPrintln(String(FreeMem()));
return return_see_serial(event);
}
String Command_Settings_Reset(struct EventStruct *event, const char* Line)
{
ResetFactory();
reboot();
return return_command_success();
}
class String;
String Command_Settings_Build(struct EventStruct *event, const char* Line);
String Command_Settings_Unit(struct EventStruct *event, const char* Line);
String Command_Settings_Name(struct EventStruct *event, const char* Line);
String Command_Settings_Password(struct EventStruct *event, const char* Line);
String Command_Settings_Save(struct EventStruct *event, const char* Line);
String Command_Settings_Load(struct EventStruct *event, const char* Line);
String Command_Settings_Print(struct EventStruct *event, const char* Line);
String Command_Settings_Reset(struct EventStruct *event, const char* Line);
#endif // COMMAND_SETTINGS_H
+56
View File
@@ -0,0 +1,56 @@
#include "Time.h"
#include "../../ESPEasy_common.h"
#include "../Commands/Common.h"
#include "../Globals/Settings.h"
#include "../../ESPEasy_fdwdecl.h"
String Command_NTPHost(struct EventStruct *event, const char* Line)
{
return Command_GetORSetString(event, F("NTPHost:"),
Line,
Settings.NTPHost,
sizeof(Settings.NTPHost),
1);
}
String Command_useNTP(struct EventStruct *event, const char* Line)
{
if (HasArgv(Line, 2)) {
Settings.UseNTP = event->Par1;
} else {
serialPrintln();
String result = F("UseNTP:");
result += toString(Settings.UseNTP);
return return_result(event, result);
}
return return_command_success();
}
String Command_TimeZone(struct EventStruct *event, const char* Line)
{
if (HasArgv(Line, 2)) {
Settings.TimeZone = event->Par1;
} else {
serialPrintln();
String result = F("TimeZone:");
result += Settings.TimeZone;
return return_result(event, result);
}
return return_command_success();
}
String Command_DST(struct EventStruct *event, const char* Line)
{
if (HasArgv(Line, 2)) {
Settings.DST = event->Par1;
}else {
serialPrintln();
String result = F("DST:");
result += toString(Settings.DST);
return return_result(event, result);
}
return return_command_success();
}
+5 -47
View File
@@ -1,53 +1,11 @@
#ifndef COMMAND_TIME_H
#define COMMAND_TIME_H
class String;
String Command_NTPHost(struct EventStruct *event, const char* Line)
{
return Command_GetORSetString(event, F("NTPHost:"),
Line,
Settings.NTPHost,
sizeof(Settings.NTPHost),
1);
}
String Command_useNTP(struct EventStruct *event, const char* Line)
{
if (HasArgv(Line, 2)) {
Settings.UseNTP = event->Par1;
} else {
serialPrintln();
String result = F("UseNTP:");
result += toString(Settings.UseNTP);
return return_result(event, result);
}
return return_command_success();
}
String Command_TimeZone(struct EventStruct *event, const char* Line)
{
if (HasArgv(Line, 2)) {
Settings.TimeZone = event->Par1;
} else {
serialPrintln();
String result = F("TimeZone:");
result += Settings.TimeZone;
return return_result(event, result);
}
return return_command_success();
}
String Command_DST(struct EventStruct *event, const char* Line)
{
if (HasArgv(Line, 2)) {
Settings.DST = event->Par1;
}else {
serialPrintln();
String result = F("DST:");
result += toString(Settings.DST);
return return_result(event, result);
}
return return_command_success();
}
String Command_NTPHost(struct EventStruct *event, const char* Line);
String Command_useNTP(struct EventStruct *event, const char* Line);
String Command_TimeZone(struct EventStruct *event, const char* Line);
String Command_DST(struct EventStruct *event, const char* Line);
#endif // COMMAND_TIME_H
+66
View File
@@ -0,0 +1,66 @@
#include "UDP.h"
#include "../../ESPEasy_common.h"
#include "../Commands/Common.h"
#include "../Globals/Settings.h"
#include "../../ESPEasy-Globals.h"
#include "../../ESPEasy_fdwdecl.h"
String Command_UDP_Test (struct EventStruct *event, const char* Line)
{
for (byte x = 0; x < event->Par2; x++)
{
String eventName = "Test ";
eventName += x;
SendUDPCommand(event->Par1, (char*)eventName.c_str(), eventName.length());
}
return return_command_success();
}
String Command_UDP_Port(struct EventStruct *event, const char* Line)
{
return Command_GetORSetBool(event, F("UDPPort:"),
Line,
(bool *)&Settings.UDPPort,
1);
}
String Command_UPD_SendTo(struct EventStruct *event, const char* Line)
{
// FIXME TD-er: This one is not using parseString* function
String eventName = Line;
eventName = eventName.substring(7);
int index = eventName.indexOf(',');
if (index > 0)
{
eventName = eventName.substring(index + 1);
SendUDPCommand(event->Par1, (char*)eventName.c_str(), eventName.length());
}
return return_command_success();
}
String Command_UDP_SendToUPD(struct EventStruct *event, const char* Line)
{
if (WiFiConnected()) {
String strLine = Line;
String ip = parseString(strLine, 2);
String port = parseString(strLine, 3);
if (!isInt(port)) return return_command_failed();
String message = parseStringToEndKeepCase(strLine, 4);
IPAddress UDP_IP;
if(UDP_IP.fromString(ip)) {
portUDP.beginPacket(UDP_IP, port.toInt());
#if defined(ESP8266)
portUDP.write(message.c_str(), message.length());
#endif
#if defined(ESP32)
portUDP.write((uint8_t*)message.c_str(), message.length());
#endif
portUDP.endPacket();
}
return return_command_success();
}
return return_not_connected();
}
+5 -57
View File
@@ -1,63 +1,11 @@
#ifndef COMMAND_UDP_H
#define COMMAND_UDP_H
class String;
String Command_UDP_Test (struct EventStruct *event, const char* Line)
{
for (byte x = 0; x < event->Par2; x++)
{
String eventName = "Test ";
eventName += x;
SendUDPCommand(event->Par1, (char*)eventName.c_str(), eventName.length());
}
return return_command_success();
}
String Command_UDP_Port(struct EventStruct *event, const char* Line)
{
return Command_GetORSetBool(event, F("UDPPort:"),
Line,
(bool *)&Settings.UDPPort,
1);
}
String Command_UPD_SendTo(struct EventStruct *event, const char* Line)
{
// FIXME TD-er: This one is not using parseString* function
String eventName = Line;
eventName = eventName.substring(7);
int index = eventName.indexOf(',');
if (index > 0)
{
eventName = eventName.substring(index + 1);
SendUDPCommand(event->Par1, (char*)eventName.c_str(), eventName.length());
}
return return_command_success();
}
String Command_UDP_SendToUPD(struct EventStruct *event, const char* Line)
{
if (WiFiConnected()) {
String strLine = Line;
String ip = parseString(strLine, 2);
String port = parseString(strLine, 3);
if (!isInt(port)) return return_command_failed();
String message = parseStringToEndKeepCase(strLine, 4);
IPAddress UDP_IP;
if(UDP_IP.fromString(ip)) {
portUDP.beginPacket(UDP_IP, port.toInt());
#if defined(ESP8266)
portUDP.write(message.c_str(), message.length());
#endif
#if defined(ESP32)
portUDP.write((uint8_t*)message.c_str(), message.length());
#endif
portUDP.endPacket();
}
return return_command_success();
}
return return_not_connected();
}
String Command_UDP_Test (struct EventStruct *event, const char* Line);
String Command_UDP_Port(struct EventStruct *event, const char* Line);
String Command_UPD_SendTo(struct EventStruct *event, const char* Line);
String Command_UDP_SendToUPD(struct EventStruct *event, const char* Line);
#endif // COMMAND_UDP_H
+113
View File
@@ -0,0 +1,113 @@
#include "WiFi.h"
#include "../../ESPEasy_common.h"
#include "../Commands/Common.h"
#include "../Globals/Settings.h"
#include "../../ESPEasy_fdwdecl.h"
String Command_Wifi_SSID(struct EventStruct *event, const char* Line)
{
return Command_GetORSetString(event, F("Wifi SSID:"),
Line,
SecuritySettings.WifiSSID,
sizeof(SecuritySettings.WifiSSID),
1);
}
String Command_Wifi_Key(struct EventStruct *event, const char* Line)
{
return Command_GetORSetString(event, F("Wifi Key:"),
Line,
SecuritySettings.WifiKey,
sizeof(SecuritySettings.WifiKey),
1);
}
String Command_Wifi_SSID2(struct EventStruct *event, const char* Line)
{
return Command_GetORSetString(event, F("Wifi2 SSID:"),
Line,
SecuritySettings.WifiSSID2,
sizeof(SecuritySettings.WifiSSID2),
1);
}
String Command_Wifi_Key2(struct EventStruct *event, const char* Line)
{
return Command_GetORSetString(event, F("Wifi2 Key:"),
Line,
SecuritySettings.WifiKey2,
sizeof(SecuritySettings.WifiKey2),
1);
}
String Command_Wifi_Scan(struct EventStruct *event, const char* Line)
{
WifiScan();
return return_command_success();
}
String Command_Wifi_Connect(struct EventStruct *event, const char* Line)
{
WiFiConnectRelaxed();
return return_command_success();
}
String Command_Wifi_Disconnect(struct EventStruct *event, const char* Line)
{
WifiDisconnect();
return return_command_success();
}
String Command_Wifi_APMode(struct EventStruct *event, const char* Line)
{
setAP(true);
return return_command_success();
}
String Command_Wifi_STAMode(struct EventStruct *event, const char* Line)
{
setSTA(true);
return return_command_success();
}
String Command_Wifi_Mode(struct EventStruct *event, const char* Line)
{
String TmpStr1;
if (GetArgv(Line, TmpStr1, 2)) {
WiFiMode_t mode = WIFI_MODE_MAX;
if (event->Par1 > 0) {
mode = (WiFiMode_t)(event->Par1 - 1);
} else {
TmpStr1.toLowerCase();
if (strcmp_P(TmpStr1.c_str(), PSTR("off")) == 0) mode = WIFI_OFF;
else if (strcmp_P(TmpStr1.c_str(), PSTR("sta")) == 0) mode = WIFI_STA;
else if (strcmp_P(TmpStr1.c_str(), PSTR("ap")) == 0) mode = WIFI_AP;
else if (strcmp_P(TmpStr1.c_str(), PSTR("ap+sta")) == 0) mode = WIFI_AP_STA;
}
if (mode >= WIFI_OFF && mode < WIFI_MODE_MAX) {
setWifiMode(mode);
} else {
serialPrintln();
return return_result(event, F("Wifi Mode: invalid arguments"));
}
} else {
serialPrintln();
String result = F("WiFi Mode:");
result += toString(WiFi.getMode());
return return_result(event, result);
}
return return_command_success();
}
// FIXME: TD-er This is not an erase, but actually storing the current settings
// in the wifi settings of the core library
String Command_WiFi_Erase(struct EventStruct *event, const char* Line)
{
WiFi.persistent(true); // use SDK storage of SSID/WPA parameters
WifiDisconnect(); // this will store empty ssid/wpa into sdk storage
WiFi.persistent(false); // Do not use SDK storage of SSID/WPA parameters
return return_command_success();
}
+13 -101
View File
@@ -3,111 +3,23 @@
#include "../Globals/SecuritySettings.h"
class String;
#define WIFI_MODE_MAX (WiFiMode_t)4
String Command_Wifi_SSID(struct EventStruct *event, const char* Line)
{
return Command_GetORSetString(event, F("Wifi SSID:"),
Line,
SecuritySettings.WifiSSID,
sizeof(SecuritySettings.WifiSSID),
1);
}
String Command_Wifi_Key(struct EventStruct *event, const char* Line)
{
return Command_GetORSetString(event, F("Wifi Key:"),
Line,
SecuritySettings.WifiKey,
sizeof(SecuritySettings.WifiKey),
1);
}
String Command_Wifi_SSID2(struct EventStruct *event, const char* Line)
{
return Command_GetORSetString(event, F("Wifi2 SSID:"),
Line,
SecuritySettings.WifiSSID2,
sizeof(SecuritySettings.WifiSSID2),
1);
}
String Command_Wifi_Key2(struct EventStruct *event, const char* Line)
{
return Command_GetORSetString(event, F("Wifi2 Key:"),
Line,
SecuritySettings.WifiKey2,
sizeof(SecuritySettings.WifiKey2),
1);
}
String Command_Wifi_Scan(struct EventStruct *event, const char* Line)
{
WifiScan();
return return_command_success();
}
String Command_Wifi_Connect(struct EventStruct *event, const char* Line)
{
WiFiConnectRelaxed();
return return_command_success();
}
String Command_Wifi_Disconnect(struct EventStruct *event, const char* Line)
{
WifiDisconnect();
return return_command_success();
}
String Command_Wifi_APMode(struct EventStruct *event, const char* Line)
{
setAP(true);
return return_command_success();
}
String Command_Wifi_STAMode(struct EventStruct *event, const char* Line)
{
setSTA(true);
return return_command_success();
}
String Command_Wifi_Mode(struct EventStruct *event, const char* Line)
{
String TmpStr1;
if (GetArgv(Line, TmpStr1, 2)) {
WiFiMode_t mode = WIFI_MODE_MAX;
if (event->Par1 > 0) {
mode = (WiFiMode_t)(event->Par1 - 1);
} else {
TmpStr1.toLowerCase();
if (strcmp_P(TmpStr1.c_str(), PSTR("off")) == 0) mode = WIFI_OFF;
else if (strcmp_P(TmpStr1.c_str(), PSTR("sta")) == 0) mode = WIFI_STA;
else if (strcmp_P(TmpStr1.c_str(), PSTR("ap")) == 0) mode = WIFI_AP;
else if (strcmp_P(TmpStr1.c_str(), PSTR("ap+sta")) == 0) mode = WIFI_AP_STA;
}
if (mode >= WIFI_OFF && mode < WIFI_MODE_MAX) {
setWifiMode(mode);
} else {
serialPrintln();
return return_result(event, F("Wifi Mode: invalid arguments"));
}
} else {
serialPrintln();
String result = F("WiFi Mode:");
result += toString(WiFi.getMode());
return return_result(event, result);
}
return return_command_success();
}
String Command_Wifi_SSID(struct EventStruct *event, const char* Line);
String Command_Wifi_Key(struct EventStruct *event, const char* Line);
String Command_Wifi_SSID2(struct EventStruct *event, const char* Line);
String Command_Wifi_Key2(struct EventStruct *event, const char* Line);
String Command_Wifi_Scan(struct EventStruct *event, const char* Line);
String Command_Wifi_Connect(struct EventStruct *event, const char* Line);
String Command_Wifi_Disconnect(struct EventStruct *event, const char* Line);
String Command_Wifi_APMode(struct EventStruct *event, const char* Line);
String Command_Wifi_STAMode(struct EventStruct *event, const char* Line);
String Command_Wifi_Mode(struct EventStruct *event, const char* Line);
// FIXME: TD-er This is not an erase, but actually storing the current settings
// in the wifi settings of the core library
String Command_WiFi_Erase(struct EventStruct *event, const char* Line)
{
WiFi.persistent(true); // use SDK storage of SSID/WPA parameters
WifiDisconnect(); // this will store empty ssid/wpa into sdk storage
WiFi.persistent(false); // Do not use SDK storage of SSID/WPA parameters
return return_command_success();
}
String Command_WiFi_Erase(struct EventStruct *event, const char* Line);
#endif // COMMAND_WIFI_H