Skip to content

Commit

Permalink
added dev password. close #14.
Browse files Browse the repository at this point in the history
+ small refactoring and update from web #15
  • Loading branch information
merlokk committed Apr 28, 2017
1 parent ea50214 commit ea0bd27
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 11 deletions.
2 changes: 2 additions & 0 deletions ESP8266EASTRON/ESP8266EASTRON.files
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
general.ino
general.h
../lib/eastron.cpp
../lib/eastron.h
../lib/emodbus.cpp
Expand Down
12 changes: 2 additions & 10 deletions ESP8266EASTRON/ESP8266EASTRON.ino
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,8 @@
* original repository here https://github.com/merlokk/SmartHome/tree/master/ESP8266EASTRON
* (c) Oleg Moiseenko 2017
*/

#include <Arduino.h>
#include <ESP8266WiFi.h> // https://github.com/esp8266/Arduino
#include <DNSServer.h> // Local DNS Server used for redirecting all requests to the configuration portal
#include <WiFiManager.h> // https://github.com/merlokk/WiFiManager original:https://github.com/tzapu/WiFiManager
#include <PubSubClient.h> // https://github.com/knolleary/pubsubclient/releases/tag/v2.6
#include <Ticker.h>
#include <EEPROM.h>
#include <ArduinoOTA.h>
#include <TimeLib.h> // https://github.com/PaulStoffregen/Time
#include <NtpClientLib.h> // https://github.com/gmag11/NtpClient
#include <xlogger.h> // logger https://github.com/merlokk/xlogger
// my libraries
#include <etools.h>
Expand Down Expand Up @@ -84,7 +75,8 @@ void setup() {
DEBUG_PRINTLN(str);

// set password in work mode
logger.setPassword("123454321");
if (params[F("device_passwd")].length() > 0)
logger.setPassword(params[F("device_passwd")].c_str());

ticker.detach();
digitalWrite(LED1, LEDOFF);
Expand Down
10 changes: 10 additions & 0 deletions ESP8266EASTRON/general.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
#include <ESP8266httpUpdate.h> // http updater https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h
#include <DNSServer.h> // Local DNS Server used for redirecting all requests to the configuration portal
#include <WiFiManager.h> // https://github.com/merlokk/WiFiManager original:https://github.com/tzapu/WiFiManager
#include <PubSubClient.h> // https://github.com/knolleary/pubsubclient/releases/tag/v2.6
#include <Ticker.h>
#include <EEPROM.h>
#include <ArduinoOTA.h>
#include <TimeLib.h> // https://github.com/PaulStoffregen/Time
#include <NtpClientLib.h> // https://github.com/gmag11/NtpClient

// macros for debugging
xLogger logger;
#ifdef DEBUG
Expand Down
28 changes: 27 additions & 1 deletion ESP8266EASTRON/general.ino
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,16 @@ void wifiSetup(bool withAutoConnect) {
wifiManager.addParameter(&custom_mqtt_path);
WiFiManagerParameter custom_device_type("device-type", "Device type", params[F("device_type")], 20);
wifiManager.addParameter(&custom_device_type);
WiFiManagerParameter custom_mqtt_text1("<br/>Development config: <br/>");
wifiManager.addParameter(&custom_mqtt_text1);
WiFiManagerParameter custom_passwd("device-paswd", "Device dev password", params[F("device_passwd")], 20);
wifiManager.addParameter(&custom_passwd);

wifiManager.setAPCallback(configModeCallback);
wifiManager.setConfigPortalTimeout(180);
// set config save notify callback
wifiManager.setSaveConfigCallback(saveConfigCallback);
// resets after
wifiManager.setBreakAfterConfig(true);

bool needsRestart = false;
Expand All @@ -218,6 +223,7 @@ void wifiSetup(bool withAutoConnect) {
params.SetParam(F("mqtt_passwd"), custom_mqtt_password.getValue());
params.SetParam(F("mqtt_path"), custom_mqtt_path.getValue());
params.SetParam(F("device_type"), custom_device_type.getValue());
params.SetParam(F("device_passwd"), custom_passwd.getValue());

params.SaveToEEPROM();
}
Expand Down Expand Up @@ -253,6 +259,25 @@ void reset() {
delay(1000);
}

///////////////////////////////////////////////////////////////////////////
// Update from WEB
///////////////////////////////////////////////////////////////////////////

void UpdateFromWeb() {
t_httpUpdate_return ret = ESPhttpUpdate.update("192.168.0.2", 80, "/update/arduino.php", PROGRAM_VERSION);
switch(ret) {
case HTTP_UPDATE_FAILED:
DEBUG_EPRINTLN(F("[update] Update failed."));
break;
case HTTP_UPDATE_NO_UPDATES:
DEBUG_PRINTLN(F("[update] Update no Update."));
break;
case HTTP_UPDATE_OK:
DEBUG_PRINTLN(F("[update] Update ok.")); // may not called we reboot the ESP
break;
}
}

///////////////////////////////////////////////////////////////////////////
// ArduinoOTA
///////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -282,7 +307,8 @@ void setupArduinoOTA() {
// Port defaults to 8266
// ArduinoOTA.setPort(8266);
// No authentication by default
// ArduinoOTA.setPassword("admin123");
if (params[F("device_passwd")].length() > 0)
ArduinoOTA.setPassword(params[F("device_passwd")].c_str());
ArduinoOTA.setHostname(HARDWARE_ID);
ArduinoOTA.begin();
}
Expand Down

0 comments on commit ea0bd27

Please sign in to comment.