Skip to content

Commit

Permalink
Merged v2.0 changes and fixed some regressions
Browse files Browse the repository at this point in the history
  • Loading branch information
psy0rz committed Jan 22, 2018
2 parents 4b298d6 + 0c637da commit 3922827
Show file tree
Hide file tree
Showing 19 changed files with 969 additions and 446 deletions.
23 changes: 15 additions & 8 deletions src/Command.ino
Expand Up @@ -213,6 +213,14 @@ void ExecuteCommand(byte source, const char *Line)
taskClear(Par1 - 1, true);
}

//quickly clear all tasks, without saving (used by test suite)
if (strcasecmp_P(Command, PSTR("TaskClearAll")) == 0)
{
success = true;
for (byte t=0; t<TASKS_MAX; t++)
taskClear(t, false);
}

if (strcasecmp_P(Command, PSTR("wdconfig")) == 0)
{
success = true;
Expand Down Expand Up @@ -390,14 +398,12 @@ void ExecuteCommand(byte source, const char *Line)
String port = parseString(strLine, 3);
int msgpos = getParamStartPos(strLine, 4);
String message = strLine.substring(msgpos);
byte ipaddress[4];
str2ip((char*)ip.c_str(), ipaddress);
IPAddress UDP_IP(ipaddress[0], ipaddress[1], ipaddress[2], ipaddress[3]);
portUDP.beginPacket(UDP_IP, port.toInt());
#if defined(ESP8266)
IPAddress UDP_IP;
if(UDP_IP.fromString(ip)) {
portUDP.beginPacket(UDP_IP, port.toInt());
portUDP.write(message.c_str(), message.length());
#endif
portUDP.endPacket();
portUDP.endPacket();
}
}

if (strcasecmp_P(Command, PSTR("SendToHTTP")) == 0 && WiFi.status() == WL_CONNECTED)
Expand Down Expand Up @@ -559,9 +565,10 @@ void ExecuteCommand(byte source, const char *Line)
if (strcasecmp_P(Command, PSTR("IP")) == 0)
{
success = true;
if (GetArgv(Line, TmpStr1, 2))
if (GetArgv(Line, TmpStr1, 2)) {
if (!str2ip(TmpStr1, Settings.IP))
Serial.println("?");
}
}

if (strcasecmp_P(Command, PSTR("Settings")) == 0)
Expand Down
12 changes: 12 additions & 0 deletions src/ESPEasy.ino
Expand Up @@ -416,6 +416,18 @@ WiFiUDP portUDP;

struct SecurityStruct
{
SecurityStruct() {
memset(WifiSSID, 0, sizeof(WifiSSID));
memset(WifiKey, 0, sizeof(WifiKey));
memset(WifiSSID2, 0, sizeof(WifiSSID2));
memset(WifiKey2, 0, sizeof(WifiKey2));
memset(WifiAPKey, 0, sizeof(WifiAPKey));
for (byte i = 0; i < CONTROLLER_MAX; ++i) {
memset(ControllerUser[i], 0, sizeof(ControllerUser[i]));
memset(ControllerPassword[i], 0, sizeof(ControllerPassword[i]));
}
memset(Password, 0, sizeof(Password));
}
char WifiSSID[32];
char WifiKey[64];
char WifiSSID2[32];
Expand Down
83 changes: 33 additions & 50 deletions src/Misc.ino
Expand Up @@ -712,45 +712,25 @@ unsigned long str2int(char *string)
return temp;
}


/********************************************************************************************\
Convert a char string to IP byte array
\*********************************************************************************************/
//FIXME: change original code so it uses IPAddress and IPAddress.fromString()
boolean str2ip(char *string, byte* IP)
{
byte c;
byte part = 0;
int value = 0;

for (unsigned int x = 0; x <= strlen(string); x++)
{
c = string[x];
if (isdigit(c))
{
value *= 10;
value += c - '0';
}
boolean str2ip(const String& string, byte* IP) {
return str2ip(string.c_str(), IP);
}

else if (c == '.' || c == 0) // next octet from IP address
{
if (value <= 255)
IP[part++] = value;
else
return false;
value = 0;
}
else if (c == ' ') // ignore these
;
else // invalid token
return false;
}
if (part == 4) // correct number of octets
boolean str2ip(const char *string, byte* IP)
{
IPAddress tmpip; // Default constructor => set to 0.0.0.0
if (*string == 0 || tmpip.fromString(string)) {
// Eiher empty string or a valid IP addres, so copy value.
for (byte i = 0; i < 4; ++i)
IP[i] = tmpip[i];
return true;
}
return false;
}


/********************************************************************************************\
Save settings to SPIFFS
\*********************************************************************************************/
Expand Down Expand Up @@ -2561,26 +2541,29 @@ void ArduinoOTAInit()

String getBearing(int degrees)
{
const char* bearing[] = {
PSTR("N"),
PSTR("NNE"),
PSTR("NE"),
PSTR("ENE"),
PSTR("E"),
PSTR("ESE"),
PSTR("SE"),
PSTR("SSE"),
PSTR("S"),
PSTR("SSW"),
PSTR("SW"),
PSTR("WSW"),
PSTR("W"),
PSTR("WNW"),
PSTR("NW"),
PSTR("NNW")
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")
};

return(bearing[int(degrees/22.5)]);
int bearing_idx=int(degrees/22.5);
if (bearing_idx<0 || bearing_idx>=(int) (sizeof(bearing)/sizeof(bearing[0])))
return("");
else
return(bearing[bearing_idx]);

}

Expand Down
33 changes: 10 additions & 23 deletions src/WebServer.ino
Expand Up @@ -703,8 +703,6 @@ void handle_config() {
if (timerAPoff)
timerAPoff = millis() + 2000L; //user has reached the main page - AP can be switched off in 2..3 sec

char tmpString[64];

navMenuIndex = 1;
String name = WebServer.arg(F("name"));
//String password = WebServer.arg(F("password"));
Expand Down Expand Up @@ -757,24 +755,20 @@ void handle_config() {
}
case ONLY_IP_RANGE_ALLOWED:
case ALL_ALLOWED:
iprangelow.toCharArray(tmpString, 26);
str2ip(tmpString, SecuritySettings.AllowedIPrangeLow);
iprangehigh.toCharArray(tmpString, 26);
str2ip(tmpString, SecuritySettings.AllowedIPrangeHigh);
// iprangelow.toCharArray(tmpString, 26);
str2ip(iprangelow, SecuritySettings.AllowedIPrangeLow);
// iprangehigh.toCharArray(tmpString, 26);
str2ip(iprangehigh, SecuritySettings.AllowedIPrangeHigh);
break;
}

Settings.Delay = sensordelay.toInt();
Settings.deepSleep = (deepsleep == "on");
Settings.deepSleepOnFail = (deepsleeponfail == "on");
espip.toCharArray(tmpString, 26);
str2ip(tmpString, Settings.IP);
espgateway.toCharArray(tmpString, 26);
str2ip(tmpString, Settings.Gateway);
espsubnet.toCharArray(tmpString, 26);
str2ip(tmpString, Settings.Subnet);
espdns.toCharArray(tmpString, 26);
str2ip(tmpString, Settings.DNS);
str2ip(espip, Settings.IP);
str2ip(espgateway, Settings.Gateway);
str2ip(espsubnet, Settings.Subnet);
str2ip(espdns, Settings.DNS);
Settings.Unit = unit.toInt();
addHtmlError(reply, SaveSettings());
}
Expand Down Expand Up @@ -850,8 +844,6 @@ void handle_controllers() {
if (!isLoggedIn()) return;

struct EventStruct TempEvent;
char tmpString[64];

navMenuIndex = 2;
byte controllerindex = WebServer.arg(F("index")).toInt();
boolean controllerNotSet = controllerindex == 0;
Expand Down Expand Up @@ -920,11 +912,7 @@ void handle_controllers() {
//no protocol selected
else
{
if (controllerip.length() != 0)
{
controllerip.toCharArray(tmpString, 26);
str2ip(tmpString, ControllerSettings.IP);
}
str2ip(controllerip, ControllerSettings.IP);
}
//copy settings to struct
Settings.ControllerEnabled[controllerindex] = (controllerenabled == "on");
Expand Down Expand Up @@ -3230,8 +3218,7 @@ void handle_advanced() {
ntphost.toCharArray(tmpString, 64);
strcpy(Settings.NTPHost, tmpString);
Settings.TimeZone = timezone.toInt();
syslogip.toCharArray(tmpString, 26);
str2ip(tmpString, Settings.Syslog_IP);
str2ip(syslogip.c_str(), Settings.Syslog_IP);
Settings.UDPPort = udpport.toInt();
Settings.SyslogLevel = sysloglevel.toInt();
Settings.UseSerial = (useserial == "on");
Expand Down
8 changes: 4 additions & 4 deletions src/_C001.ino
Expand Up @@ -101,9 +101,9 @@ boolean CPlugin_001(byte function, struct EventStruct *event, String& string)
case SENSOR_TYPE_TEMP_BARO: // temp + bar used for BMP085 and BMP280
url += F("&svalue=");
url += formatUserVar(event, 0);
url += F(";");
url += formatUserVar(event, 1);
url += F(";0;0;");
url += formatUserVar(event, 1);
url += F(";0");
break;
case SENSOR_TYPE_TRIPLE:
url += F("&svalue=");
Expand Down Expand Up @@ -165,7 +165,7 @@ boolean CPlugin_001(byte function, struct EventStruct *event, String& string)
url += toString((UserVar[event->BaseVarIndex + 1] * 10),ExtraTaskSettings.TaskDeviceValueDecimals[1]);
url += ";";
url += toString((UserVar[event->BaseVarIndex + 2] * 10),ExtraTaskSettings.TaskDeviceValueDecimals[2]);
url += ";0";
url += ";0;0";
break;
}

Expand All @@ -182,7 +182,7 @@ boolean CPlugin_001(byte function, struct EventStruct *event, String& string)
client.print(request);

unsigned long timer = millis() + 200;
while (!client.available() && !timeOutReached(timer))
while (!client.available() && !timeOutReached(timer))
yield();

// Read all the lines of the reply from server and log them
Expand Down

0 comments on commit 3922827

Please sign in to comment.