Skip to content

Commit

Permalink
Revert "Revert "Factory setting mode (#140)" (#146)" (#155)
Browse files Browse the repository at this point in the history
This reverts commit 90f874b.
  • Loading branch information
dmohns authored Dec 20, 2023
1 parent 8e5dd55 commit 198d3c5
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 22 deletions.
172 changes: 152 additions & 20 deletions firmware/src/keypad.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

// OpenSmartMeter libraries
#include "led_buzzer.hpp"
#include "time_management.hpp"
#include "token_management.hpp"

#define STAR_KEY -1
#define HASH_KEY -2
Expand All @@ -29,6 +31,146 @@ byte colPins[COLS] = {PA7, PA6, PA5, PC13};
Keypad customKeypad =
Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

void FactorySetting() {
lcd.clear();
lcd.setCursor(0, 0);
data_count = 0;
lcd_count = 8;
dt = 0;
switch (setting_mode) {
case 1:
lcd.println(
"001:Reinitialisation 011:Configuration 021:Change password");
setting_mode = 2;
break;

case 2: // Reinitialize values
if (sts_data == "001") {
fault = 0;
billing = 0.0;
true_power = 0.0;
ENERGY = 0.0;
freq = 0.0;
curr = 0.0;
powerFactor = 0.0;
mains_input_value = 0.0;

InvalidTokenCount = 0;
TokenCount = 1;
UsedTokens = 0;
PAYGEnabled = true;
ActiveUntil = 0;
TokenEntryLockedUntil = 0;
nbDisconnections = 0;
StoreActivationVariables();

topup = 0.0;
topupnew = 0;

warntime = 0;
warn_now = 0;

timeInitializationRtc = 0;
hours = 0;
minutes = 0;
seconds = 0;
rtcday = 0;
nw_month_cnt = 0;
rtcmonth = 0;
rtcnewmonth = 0;
billing_date = 0;

thingsboard_check = 0;

lastmonth_KWH = 0.0;
initializeTime();

lcdtime_now = 0;
prev_lcdtime = 0;
cnt = 0;
lcd_count = 0;
data_count = 0;
dt = 0;
parameters = 0;
token_used = 0;

sts_eeprom_fetched = 0;
token_eeprom_location = 20;
eeprom_location_cnt = 40;

sts_value = 0;
sts_mode = 0;

lcd.println("Values reinitialize");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
setting_mode = 0;
}

if (sts_data == "011") { // Configure mode
lcd.println("112:STS 122:Energy-based 132:Timed-based");
setting_mode = 3;
}

if (sts_data == "021") { // Change Password
lcd.println("Old password: ");
setting_mode = 4;
}
break;

case 3:
if (sts_data == "112") {
Mode_select = 1; // For STS Mode (Energy-based)
lcd.println("configured to STS Mode");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
}

if (sts_data == "122") {
Mode_select = 2; // For OpenPaygo Energy-based
lcd.println("configured to OPaygo Energy-based Mode");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
}

if (sts_data == "132") {
Mode_select = 3; // For OpenPaygo Time-based
lcd.println("configured to OPaygo Time-based Mode");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
}
setting_mode = 0;
break;

case 4: // Enter new password
if (sts_data == password) {
lcd.println("New password: ");
setting_mode = 5;
}
break;

case 5: // confirm new password
new_password = sts_data;
lcd.println("confirm new password: ");
setting_mode = 6;
break;

case 6: // Password Changed
if (sts_data == new_password) {
password = new_password;
lcd.println("password changed ");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
setting_mode = 0;
}
break;
}
}
// For STS

void STS_keypad() {
Expand All @@ -44,9 +186,11 @@ void STS_keypad() {
lcd.setCursor(0, 0);
sts_mode = 1;
if (customKeypad.getState() == HOLD) {
lcd.println("Password: ");
lcd.println("Enter Password to start factory setting: ");
setting_mode = 1;
} else {
lcd.print("TOKEN: ");
setting_mode = 0;
}
}

Expand Down Expand Up @@ -96,25 +240,13 @@ void STS_keypad() {
}
}

if (data_count < 19 && data_count > 3) {
if (sts_data == password) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("MODE: ");
data_count = 0;
lcd_count = 8;
dt = 0;
}
if (sts_data == "112") {
Mode_select = 1; // For STS Mode (Energy-based)
}

if (sts_data == "122") {
Mode_select = 2; // For OpenPaygo Energy-based
}

if (sts_data == "132") {
Mode_select = 3; // For OpenPaygo Time-based
if (data_count < 19 && data_count >= 3) {
if (setting_mode == 1) {
if (sts_data == password) {
FactorySetting();
}
} else if (setting_mode > 1) {
FactorySetting();
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions firmware/src/mem_operation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ uint32_t ActiveUntil = 0;
uint32_t TokenEntryLockedUntil = 0;
uint8_t nbDisconnections = 0;

int InvalidTokenCount = 0;

void LoadActivationVariables() {
TokenCount =
mem.readInt(TokenCount_eeprom_location); // We load TokenCount (&
Expand Down
2 changes: 0 additions & 2 deletions firmware/src/opaygo_token.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ extern "C" {
# define TOKEN_LENGTH 9
#endif

int InvalidTokenCount = 0;

bool TokenEntryAllowed() {
if (TokenEntryLockedUntil > GetTimeInSeconds()) {
return false;
Expand Down
3 changes: 3 additions & 0 deletions firmware/src/token_management.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ byte dt = 0;
byte parameters = 0;
byte token_used = 0;
String password = "1234";
String new_password = "1234";

// for meter
unsigned long sts_eeprom_fetched = 0;
Expand All @@ -28,6 +29,8 @@ unsigned long eeprom_location_cnt = 40;
unsigned long sts_value = 0;
unsigned long sts_mode = 0;
unsigned long Mode_select = 0;
unsigned long setting_mode =
0; // when the value is 1 we are in Factory Setting Mode

void check_tokenused() {
token_eeprom_location = mem.readLong(eeprom_location_cnt);
Expand Down

0 comments on commit 198d3c5

Please sign in to comment.