|Top Previous Next|
The stor object provides access to the non-volatile (EEPROM) memory in which your application can store data that must not be lost when the device is switched off.
The stor.size read-only property tells you the amount of EEPROM memory offered by the stor object. The stor.set is used to write the data to the EEPROM, while the stor.get method is used to read the data from the EEPROM.
Here is a simple example how to save the IP address of your device in the EEPROM:
dim s as string
dim x as byte
s=ddval(net.ip) 'this way it will take less space in the EEPROM (only 4 bytes needed)
x= stor.set(s,0) 'write EEPROM
if x<>len(s) then
'EEPROM write failure- do something about this!
And here is how you read this data back from the EEPROM:
Notice, that with the stor object addresses are counted from 1, not 0. That is, the first memory location has address 1.
Special configuration area
The EEPROM IC of the device is also used to store certain configuration information required by the device. Memory available to your application equals the capacity of the IC minus the size of the special configuration area.
By default, when you access the first byte of the EEPROM you are actually accessing the first memory location above the special configuration area. One property -- stor.base -- returns the size of this offset. On startup, stor.base is equal to the size of the special configuration area, so your program can only access the memory above this area.
You can change the stor.base and access configuration area when you need. For example, you can change the MAC address this way- next time the device boots up it will start using newly set address.