Skip to content

Commit

Permalink
added web update. not tested. #15
Browse files Browse the repository at this point in the history
  • Loading branch information
merlokk committed Apr 28, 2017
1 parent ea0bd27 commit ffb9b73
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
21 changes: 18 additions & 3 deletions ESP8266EASTRON/general.ino
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,8 @@ void reset() {
// Update from WEB
///////////////////////////////////////////////////////////////////////////

void UpdateFromWeb() {
t_httpUpdate_return ret = ESPhttpUpdate.update("192.168.0.2", 80, "/update/arduino.php", PROGRAM_VERSION);
void UpdateFromWeb(const String &server) {
t_httpUpdate_return ret = ESPhttpUpdate.update(server, 80, "/update/arduino.php", PROGRAM_VERSION);
switch(ret) {
case HTTP_UPDATE_FAILED:
DEBUG_EPRINTLN(F("[update] Update failed."));
Expand Down Expand Up @@ -320,7 +320,8 @@ const char* strCommandsDesc =
"Command reboot reboots ESP.\r\n"\
"Command startwificfg puts ESP to configure mode. Show configuration AP.\r\n"\
"Command set <param_name> <value> writes parameter to ESP memory. \r\n"\
"parameters: mqtt_server, mqtt_port, mqtt_user, mqtt_passwd, mqtt_path, device_type";
"parameters: mqtt_server, mqtt_port, mqtt_user, mqtt_passwd, mqtt_path, device_type.\r\n"\
"System commands: resetcfg, webupdate, webupdatec. ";

bool CmdCallback(String &cmd) {
if (cmd == "reboot") {
Expand All @@ -345,6 +346,20 @@ bool CmdCallback(String &cmd) {
return true;
}

if (cmd.length() >= 15 && cmd.startsWith("webupdate ")) {
String srv = cmd.substring(10);
DEBUG_PRINTLN(SF("COMMAND: web update. server=") + srv);
UpdateFromWeb(srv);
return true;
}

if (cmd.length() >= 16 && cmd.startsWith("webupdatec ")) {
String srv = cmd.substring(10);
DEBUG_PRINTLN(SF("COMMAND: web update. server=") + srv);
params.LoadFromWeb(srv + "/update/arduinocfg.php");
return true;
}

// set <param> <value>. sample: set device_type 220
if (cmd.length() > 7 && cmd.startsWith("set ")) {
String name = cmd.substring(4);
Expand Down
2 changes: 1 addition & 1 deletion lib/xparam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ bool xParam::SaveToEEPROM() {
return true;
}

bool xParam::LoadFromWeb(String &url) {
bool xParam::LoadFromWeb(const String &url) {

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/xparam.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class xParam
void ClearAll();
bool LoadFromEEPROM();
bool SaveToEEPROM();
bool LoadFromWeb(String &url);
bool LoadFromWeb(const String &url);

void GetParamsJsonStr(String &str);

Expand Down

0 comments on commit ffb9b73

Please sign in to comment.