EEPROM.get not returning previously commited data?

becauseICan
Posts: 1
Joined: Fri Sep 13, 2024 7:44 am

EEPROM.get not returning previously commited data?

Postby becauseICan » Fri Sep 13, 2024 8:06 am

*UPDATE* I noticed I had a formatting error in debug Serial output, I've updated the test code to use only char arrays. But issue is still there. Now it's just more evident, that no data is returned in the call to EEPROM.get.*UPDATE*
I'm working in Arduino IDE, writing code for a generic 8266-12F module, and also testing with a Wemos D1 R1.
The issue I have, is that it appears as if the EEPROM.get method doesn't return the value set in the data buffer, even after EEPROM.commit is called, and returns a True result.

Below test code outputs the following on Serial:
Struct is 256 bytes in size
Test value set to 'Initial String'
Commit returned True
Value in EEPROM for _eepromVals was: ''
Raw dump of EEPROM internal cache up to first null char:
���?Initial String

Test value set to 'Second String'
Commit returned True
Value in EEPROM for _eepromVals was: ''
Raw dump of EEPROM internal cache up to first null char:
���?Second String
Last line is a dump of the content in data buffer. It does look like the value indeed is stored in the buffer. Yet the value returned in the data structure retrieved with EEPROM.get, doesn't change.

Anyone have any idea, why the updated values in the data buffer is not returned when calling EEPROM.get?
  1. #include <EEPROM.h>
  2. #include <memory>
  3.  
  4. const static uint8_t g_seedValueLength = 17;
  5. const static uint8_t g_colorCodeValueLength = 8;
  6. const static uint8_t g_ipAddressLength = 16;
  7. const static uint8_t g_serverPortNumberLength = 6;
  8. const static uint8_t g_mqttUserNameLength = 61;
  9. const static uint8_t g_mqttPasswordLength = 61;
  10. const static uint8_t g_confStructMemoryAlloc = 256;    // must be large enough to hold the entire struct, and must be divisible by 4
  11.  
  12. struct  G_CONF_T {
  13.   char firmware_seeded[ g_seedValueLength ];
  14.   char ring_1_background[ g_colorCodeValueLength ];
  15.   char ring_2_background[ g_colorCodeValueLength ];
  16.   char ring_3_background[ g_colorCodeValueLength ];
  17.   char ring_4_background[ g_colorCodeValueLength ];
  18.   char ring_1_section_marks[ g_colorCodeValueLength ];
  19.   char second_hand_color[ g_colorCodeValueLength ];
  20.   char minute_hand_color[ g_colorCodeValueLength ] ;
  21.   char hour_hand_color[ g_colorCodeValueLength ];
  22.   char months_color[ g_colorCodeValueLength ];
  23.   char days_color[ g_colorCodeValueLength ];
  24.   char date_background[ g_colorCodeValueLength ];
  25.   uint16_t ltr_min;
  26.   uint16_t ltr_max;
  27.   uint8_t led_brightness_min;
  28.   uint8_t led_brightness_max;
  29.   uint8_t timezone;
  30.   uint8_t clockmode;
  31.   uint8_t mqtt_enabled;
  32.   char mqtt_server[ g_ipAddressLength ];
  33.   uint16_t mqtt_server_port;
  34.   char mqtt_username[ g_mqttUserNameLength ];
  35.   char mqtt_password[ g_mqttPasswordLength ];
  36.   G_CONF_T() {
  37.     firmware_seeded[ 0 ] = '\0';
  38.     ring_1_background[ 0 ] = '\0';
  39.     ring_2_background[ 0 ] = '\0';
  40.     ring_3_background[ 0 ] = '\0';
  41.     ring_4_background[ 0 ] = '\0';
  42.     ring_1_section_marks[ 0 ] = '\0';
  43.     second_hand_color[ 0 ] = '\0';
  44.     minute_hand_color[ 0 ] = '\0';
  45.     hour_hand_color[ 0 ] = '\0';
  46.     months_color[ 0 ] = '\0';
  47.     days_color[ 0 ] = '\0';
  48.     date_background[ 0 ] = '\0';
  49.     ltr_min = 0;
  50.     ltr_max = 0;
  51.     led_brightness_min = 0;
  52.     led_brightness_max = 0;
  53.     timezone = 1;
  54.     clockmode = 1;
  55.     mqtt_enabled = true;
  56.     mqtt_server[ 0 ] = '\0';
  57.     mqtt_server_port = 0;
  58.     mqtt_username[ 0 ] = '\0';
  59.     mqtt_password[ 0 ] = '\0';
  60.   }
  61. };
  62.  
  63. char _testStrings[ 5 ][ g_seedValueLength ] = {
  64.   "Initial String", "Second String", "String Three", " 4th String", "String 5"
  65. };
  66.  
  67. long _mils;
  68. uint8_t _testStringIndex = 0;
  69. const long _waitFor = 10000;
  70. bool _res;
  71. G_CONF_T _val;
  72. uint8_t *dataPtr;
  73.  
  74.  
  75. void setup() {
  76.   Serial.begin( 19200 );
  77.   Serial.setDebugOutput( false );
  78.   while ( !Serial && millis() < 500 )
  79.     yield();
  80.   Serial.println();
  81.  
  82.   EEPROM.begin( g_confStructMemoryAlloc + 4 );
  83.  
  84.   dataPtr = EEPROM.getDataPtr();
  85.    
  86.   _mils = millis();
  87.   Serial.printf( "Struct is %u bytes in size\n", sizeof( _val ) );
  88. }
  89.  
  90. void loop() {
  91.   char _newVal[ g_seedValueLength ];
  92.  
  93.   strcpy( _newVal, _testStrings[ _testStringIndex ] );
  94.   G_CONF_T _eepromVals;
  95.  
  96.   strcpy( _val.firmware_seeded, _newVal );
  97.  
  98.   Serial.printf( "Test value set to '%s'\n", _val.firmware_seeded );
  99.  
  100.   EEPROM.put( 0, _val );
  101.   _res = EEPROM.commit();
  102.   Serial.printf( "Commit returned %s\n", ( _res ) ? "True" : "False" );
  103.  
  104.   _eepromVals = EEPROM.get( 0, _eepromVals );
  105.   Serial.printf( "Value in EEPROM for _eepromVals was: '%s'\n", _eepromVals.firmware_seeded );
  106.  
  107.   // dump data buffer to Serial
  108.   Serial.printf( "Raw dump of EEPROM internal cache up to first null char:\n%s\n", &dataPtr );
  109.  
  110.   while ( _mils + _waitFor > millis() )
  111.     yield();
  112.  
  113.   _mils = millis();
  114.  
  115.   _testStringIndex++;
  116.  
  117.   Serial.println();
  118.  
  119. }

Who is online

Users browsing this forum: No registered users and 17 guests