There is a compatibility problem with EEPROM use and Blynk.Edgent?

Hi Blynkers,

Any of you have been getting troubble using Blynk.Edgent and using EEPROM in your projects.

I have been migrating all my projects to the new Blynk 2.0 pro account.

It was the time to migrate my aquarium doser project, that is the only one that stores some data in EEPROM.

I use Blynk.Edgent in order to allow the end user of my devices to make the commisioning of the device, and at the moment it was working great.

But with this project something very weird is happening.

I can make the commissioning and the device connects to blynk server. But if for some reason the device lost power and restart, the commissioning procedure starts again, and the previous credentials (Wifi settings) are lost.
The end user then, creates a new device on the app, loosing all the data (dosing setup).

I’m thinking that may be there is a compatibility issue betwenn Edgent and Eeprom libraries.

The code is big, then I will post the main parts:

Declarations and Includes:

#define BLYNK_TEMPLATE_ID "TMPL*************"
#define BLYNK_DEVICE_NAME "Dosificadora 4 Ch "
#define BLYNK_FIRMWARE_VERSION        "0.5.03"

#define BLYNK_MAX_SENDBYTES 1000
#define BLYNK_PRINT Serial

#define APP_DEBUG

// Uncomment your board, or configure a custom board in Settings.h
//#define USE_SPARKFUN_BLYNK_BOARD
#define USE_NODE_MCU_BOARD
//#define USE_WITTY_CLOUD_BOARD
//#define USE_WEMOS_D1_MINI

#include "BlynkEdgent.h"

#include <SimpleTimer.h>
#include <SoftwareSerial.h>

#include <TimeLib.h>
#include <WidgetRTC.h>

#include <EEPROM.h>

#define VIRTUAL_PIN_Terminal_Control 0
#define VIRTUAL_PIN_Terminal 1
#define Bomba1 14 // GPIO Pin Bomba 1
#define Bomba2 12 // GPIO Pin Bomba 2
#define Bomba3 13 // GPIO Pin Bomba 3
#define Bomba4 15 // GPIO Pin Bomba 4
#define Setup_Largo_Tabla 2
#define Button_Web 3
#define Configura_Dosis_Canal 10
#define Configura_Dosis_Dosis 11
#define Configura_Dosis_Tiempo 12
#define Configura_Dosis_Agregar 13
#define Configura_Dosis_Borrar 14
#define Setup_Nombre_Bomba_1 20
#define Setup_Nombre_Bomba_2 21
#define Setup_Nombre_Bomba_3 22
#define Setup_Nombre_Bomba_4 23
#define Setup_Calibrar_Bomba_1 30
#define Setup_Calibrar_Bomba_2 31
#define Setup_Calibrar_Bomba_3 32
#define Setup_Calibrar_Bomba_4 33
#define Setup_Calibracion_Bomba_1 40
#define Setup_Calibracion_Bomba_2 41
#define Setup_Calibracion_Bomba_3 42
#define Setup_Calibracion_Bomba_4 43
#define Setup_Notifica_Dosis 44
#define Setup_Notifica_Aditivo 46
#define Setup_Alarma_Aditivo_1 70
#define Setup_Alarma_Aditivo_2 71
#define Setup_Alarma_Aditivo_3 72
#define Setup_Alarma_Aditivo_4 73
#define Panel_Level_Bomba_1 50
#define Panel_Level_Bomba_2 51
#define Panel_Level_Bomba_3 52
#define Panel_Level_Bomba_4 53
#define Panel_Aditivo_Recarga 60
#define Panel_Cantidad_Recarga 61
#define Panel_Ejecuta_Recarga 62
#define Panel_Cantidad_Aditar 63
#define Panel_Ejecuta_Adicion 64


SimpleTimer timer;

WidgetRTC rtc;
WidgetTerminal terminal_Control(VIRTUAL_PIN_Terminal_Control);
WidgetTerminal terminal(VIRTUAL_PIN_Terminal);

const char* host = "Actualiza_Firmware";
int updateWeb = 0;
byte dia;
bool Restart = true;
int latido = 0;
int pulso = 0;
bool Actualizando = false;
bool Notifica_dosis = false;
bool Notifica_aditivo = false;
// Variables para tabla de dosis. [50] guarda valor temporal
byte Flag_Dosis[101];
int Minuto_Dosis[101];
char Dia_Dosis[714];
byte Bomba_Dosis[101];
bool Marca_Dosis[101];
byte Cantidad_Dosis[101];
byte Estado_Dosis[101];

int millis_anterior = 0;
int millis_actual = 0;
int delta_millis = 0;
int Conteo_Dec_Segundos[5] = { 0 , 0 , 0 , 0 };
byte GPIO_Bomba[5] = { 14 , 12 , 13 , 15 };
int Alarma_aditivo[5] = { 0 , 0 , 0 , 0 };
//byte GPIO_Bomba[5] = { 16 , 0 , 4 , 5 };
byte Calibracion_bomba[5] = { 0 , 0 , 0 , 0 };
byte Dosis_activa_bomba[5] = { 255 , 255 , 255 , 255 };

String bitacora="";
String Resumen = "";
int retardo_mail = 0;
int Acumula_Bomba[5] = { 0 , 0 , 0 , 0 };
bool mail_bitacora_2 = false;
bool mail_bitacora_3 = false;



int Aditivo_Restante[5] = {0,0,0,0};
int Cantidad_Recarga = 0;
byte Aditivo_Recarga = 0;


char Dia_semana[7] = {'L','M','X','J','V','S','D'};
String Bomba[5];
int Largo_Tabla = 0;
int raw_index = 0;
int Tabla_Blynk = 0;

bool Adita_Manual = false;
int Adicion_Manual = 0;
byte Bomba_manual = 0;

bool Calibracion = false;
byte Bomba_Calibra = 0;
bool conectado = false;

The Setup and loop:

void setup() {
 
  Serial.begin(115200); // See the connection status in Serial Monitor

  Serial.println("Iniciando App");
  delay(100);

  BlynkEdgent.begin();

  for ( int i = 0 ; i < 4 ; i++ )
  {
    pinMode(GPIO_Bomba[i], OUTPUT);
    digitalWrite(GPIO_Bomba[i], LOW);
  }

  for (int i = 0 ; i <= 101 ; i++)
  {
    Marca_Dosis[i] = false;
    Estado_Dosis[i] = 0;
  }

  EEPROM.begin(1212);
  View_Rom();
  Actualiza_Tabla();
  Actualiza_Aditivos(); 
  setSyncInterval(5*60); // Sync interval in seconds (5 minutes)
  millis_anterior = millis();
  millis_actual = millis_anterior;
  timer.setInterval(100, Verifica_doser); //ejecuta cada 100 ms
  timer.setInterval(1000*60*60*3,verifica_aditivos); // ejecuta cada 3 horas
  timer.setInterval(60000, comandos);

}

void loop() {

  BlynkEdgent.run();
  timer.run();

  millis_actual = millis();
  yield();
  delta_millis = millis_actual - millis_anterior;
  if ( abs(delta_millis) > 100 )
   {
    millis_anterior = millis_actual;
    Conteo_Dec_Segundos[0]++;
    Conteo_Dec_Segundos[1]++;
    Conteo_Dec_Segundos[2]++;
    Conteo_Dec_Segundos[3]++;
    retardo_mail++;
   }
}

I just realized that some EEPROM actions are made by Edgent on the ConfigStore:

#include <EEPROM.h>
#define EEPROM_CONFIG_START 0

void config_load()
{
  memset(&configStore, 0, sizeof(configStore));
  EEPROM.get(EEPROM_CONFIG_START, configStore);
  if (configStore.magic != configDefault.magic) {
    DEBUG_PRINT("Using default config.");
    configStore = configDefault;
    return;
  }
}

bool config_save()
{
  EEPROM.put(EEPROM_CONFIG_START, configStore);
  EEPROM.commit();
  DEBUG_PRINT("Configuration stored to flash");
  return true;
}

bool config_init()
{
  EEPROM.begin(sizeof(ConfigStore));
  config_load();
  return true;
}

Maybe there is some collision with my own use of the memory.

I’d guess so.
You’ll probably need to add extra space with something like this…

EEPROM.begin(sizeof(ConfigStore+x));

where x is the amount of extra space, then ensure that you write your data into the extended part of the EEPROM.

Pete.

Yes Pete, I’m testing this change on the ConfigStore.h:

bool config_init()
{
  EEPROM.begin(2048 + sizeof(ConfigStore));
  config_load();
  return true;
}

And, I deleted the EEPROM.begin on my setup.

I’ll will post my results.

Hi,

It was a good brain exercise to post this issue. During the writing I was thinking in probable causes and I finally found the problem.

Changing in ConfigStore.h the following lines:

#define EEPROM_CONFIG_START 2048 // changed by collision with device app

and

EEPROM.begin(2048 + sizeof(ConfigStore)); //changed to give space for eeprom data in device app

solved the problem.

Thanks @PeteKnight

I have fixed it as above but still get the error that wifi configuration cannot be saved when restarting. please help me!

My code https://raw.githubusercontent.com/minhvn09/k-meter/main/blynk2.0-eeprom-test.ino

It would probably help if you posted the actual code you are running, rather than a version of the code that you’ve hackled around before posting.

Pete.

1 Like