logo elektroda
logo elektroda
X
logo elektroda

[Solved] ESP8266: How to write/read string to/from EEPROM? Data type error

samolot123456747 972 8
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 18792822
    samolot123456747
    Level 3  
    Good day, I wanted to write and read myself a string value to the eeprom in esp8266, but reading:
    
    const char * mqtt_ip_server;
    
    mqtt_ip_server = EEPROM.read(5);
    
    .
    It only shows an error (a write would probably cause one too, which is why I haven't added it here)
    
    nie można przypisać wartości typu "uint8_t" do jednostki typu "const char *"
    


    Not quite sure how to deal with this.

    Please help, thank you in advance
  • ADVERTISEMENT
  • Helpful post
    #2 18792839
    viayner
    Level 43  
    Hello,
    Regardless of the platform the EEPROM like any other memory "accepts" Byte values, if the compiler does not automatically change char to byte then do it manually and when reading restore char.
    Greetings
  • #3 18792842
    samolot123456747
    Level 3  
    Thanks, but how to do it?(this is my first script on an arduino so some legalese would be useful :) )
  • ADVERTISEMENT
  • Helpful post
    #4 18792859
    khoam
    Level 42  
    samolot123456747 wrote:
    It only shows an error (a record would probably cause one too, which is why I haven't added it here)
    .
    You are trying to assign a value of type uint8_t (of size 1 byte) to a const char* pointer (of size 4 bytes).
    Is your colleague's intention to read a text string from the EEPROM? If so, the colleague will find an example at the following link:
    https://mindeon.com/posts/coding-journal/read-write-eeprom/
  • #5 18792886
    samolot123456747
    Level 3  
    What I want to do is to read e.g. 192.168.1.1 or e.g. login, and to write these two elements (to separate variables of course). It seems to me that this link will be ok.

    Added after 57 [minutes]: .

    I have one more question, how to convert string to "const char * ", because I need to use const char *, not string. (It is not possible to use string). It's about conversions when reading, because when writing everything works ok.
  • ADVERTISEMENT
  • #7 18793008
    samolot123456747
    Level 3  
    Thank you very much. Additionally, after uploading the code from the website: https://mindeon.com/posts/coding-journal/read-write-eeprom/ in the writestring function line 4 is the identifier _size. My editor was showing an error, so I changed it to Stringsize and there was no error. Does this now have the right to work(I mean writeestring)?
  • Helpful post
    #8 18793026
    khoam
    Level 42  
    samolot123456747 wrote:
    My editor was showing an error, so I changed to Stringsize and there was no error. Does this now have the right to work(it's about writing)?
    .
    Yes, the error was in the "source" :) .
  • ADVERTISEMENT
  • #9 18793027
    samolot123456747
    Level 3  
    Thank you very much for your help.

Topic summary

The discussion revolves around writing and reading string values to/from EEPROM on the ESP8266. The user encountered a type error when attempting to assign a value read from EEPROM (uint8_t) to a const char* pointer. Responses clarified that EEPROM stores byte values and suggested converting the byte to a string format. A link to an example for reading text strings from EEPROM was provided. The user also inquired about converting a string to const char* and received guidance on using the c_str() method. Additionally, a code error related to an identifier in a provided example was resolved by renaming it, confirming the code's functionality.
Summary generated by the language model.
ADVERTISEMENT