Skip to content

Best Practices

In this section we present some best practices that should be taken into account while using the eManager.

How to write files in an eManager

The eManager has flash memory to store the data in files permanently.

When required to write data to a file, it is important to consider the concept of atomicity.

Otherwise, an unexpected power outage while writing files may cause data loss or file corruption.

Atomicity is the property that ensures that an operation has been carried out or not, and therefore, in the event of a system failure, it cannot be left halfway. An operation is said to be atomic when it is impossible for any other part of a system to find intermediate steps.

The concept of atomicity is especially important in cases where the content of an existing file is replaced (truncated). In such cases, we can enforce atomicity by using temporary files. The data will first be written to a temporary file and when it is complete, the data will be moved to the final file. To do this, the mv atomic operation is used, as it ensures that the entire content of the temporary file will be written to the final file without any data loss.

On the other hand, in the event that it is necessary to add data to a file (append), in the worst case, in the event that there is a shutdown of the equipment, we will only lose the last recorded data. We can minimize this by using the sync command, which writes the data that is still in memory to flash.

Finally, it should be noted that if it is required to save a lot of data to files, it is better to use a database like mysql, which already manages these concepts.

You can find a Node-RED flow example, working with files atomicity here.