InqPortal – Help on Admin Files Tab

The Files tab should not come as a surprise. As much as possible, it was modeled off the Windows File Explorer. The main file table gives filename, size and timestamp. This timestamp is not when the file is created on the InqPortal, but when it was last changed on the uploading computer. This way you can easily do a simple visual comparison of timestamps. Above the files table, you’ll find a thin, pale green, progress bar giving a visual qualitative percentage of disk space usage of the files. Above the progress bar, to the left is the total file usage in bytes while at the right is the total size of the hard disk.

Files Tab Hosting a Typical Website

Uploading File

Files can be added by Drag and Drop from your choice of operating system’s file manager. Shown above, a right mouse click will also give you a context, popup menu that will allow you to add files. While the files are being loaded, the status field will display File Upload and the progress bar will march across the screen (in orange) to show you how much more time is required.

Files Being Uploaded

Other Context Popup Menu Options

At the moment, it is not possible to Drag and Drop folders. To create and load sub folders, you can use Add folder… option and then fill it with files by dragging and dropping or by using the Add files… option. You can Delete… selections of files and/or folders. And finally, you can Open… the selected file in another browser page. If it is an html file, it will browse to the page as if you typed it in browser’s Url box. If it is some other file, it will still display it as best it can… images, JavaScript and style sheet files can be displayed. If it can’t adequately display it, the tab will offer to download the file for you.

Understanding OTA

Over the Air (OTA) is the method of uploading your binary file using your InqPortal web server. This allows you to update your application without actually having to plug it up to your development machine. It can be in the attic, in a tree or on the other side of the world. It is important to understand how this works. Depending on the settings you select in the Arduino IDE menu option Tools/Flash Size: it will partition the flash memory into two partitions of equal size. Call them A and B. For the NodeMCU (in the following example) we have set it to make two partitions of 512KB. It also creates a file system partition of 3MB. You must use the Arduino IDE to compile and upload your InqPortal application the first time. It will place it in Partition A. However, after that you can upload it via OTA. The second time you will be using the program in Partition A to do the uploading. It will put the application in Partition B. It will then set an application start pointer and then reboot. When the ESP8266 comes up it will start running the application in Partition B. The next time, the B program will put the new version in Partition A and reset the start pointer and reboot. Back and forth they go. You do not have to load the same program, but as you can see, you must load another InqPortal program so that it will have the OTA code for the next OTA upload.

Setting the Arduino IDE to Designate the OTA Settings

OTA’ing

The doing is far easier than the theory. In the Arduino IDE, you will be using the menu item Sketch / Export compiled Binary (Ctrl+Alt+S). This will compile the binary and place it in your development machine’s project folder. This can easily be found using the Arduino IDE menu item Sketch / Show Sketch Folder (Ctrl+K). Now, simply use InqPortal‘s Drag and Drop as you would for any other file. InqPortal will detect the binary file and show you the OTA Upgrade status and the red progress bar will march across the window.

OTA Binary Program File Being Uploaded

Understanding Defragmentation

This will be an oversimplification so we can keep this under a book length. Flash memory as you might know acts considerably different than a real spinning magnetic based hard disk. A file written to the flash memory can’t be overwritten. It first has to be erased. Erasure steps can only be done on full 4 kilobyte sectors. Not portions of sectors. Also, every erase action wears the flash media a little, so it is desirable to minimize how often you erase the flash. Thus when you change an old file and upload it again, you are actually putting it in a new place. The old file is marked used. It’s still there, but is ignored by the file system. This old space is now fragmented space. Eventually you will run out of new space and must defragment the operating system. InqPortal will tell you when you have run out of new space and ask you to do the defragmentation. During defragmentation, each sector is erased and all files are moved to the beginning of the disk and you are left with all the remaining space at the end being freshly erased and ready for new files.

As you might imagine, to maximize flash memory life, it is best to wait till InqPortal notifies you it’s time. This is called wear leveling and it will prolong the life of the flash memory. If you just defragment the disk before it is necessary, the sectors at the beginning will get erased more often than the ones at the end. Although we have not studied how SPIFFs or LittleFS works, neither of them claim to do wear leveling. They use some automated defragment and erase methodology that can suddenly occur and cause an unexpected pause when it might be undesirable. Although InqPortal forces you to manually do this defragmentation, it increases flash memory life by using wear leveling AND it will never unexpectedly do an automatic defragment and erase step during critical running operations. You will only be asked to defragment the disk when you are already in an upgrading phase changing files on the disk.

Defragmenting

Like OTA’ing, the doing is far easier than the theory. Simply select the InqPortal Admin’s menu item Defragment Disk. InqPortal will show you the Defrag Disk status and a blue progress bar will march across the window.

Although you can defragment the disk at any time, if you feel you want to prolong the flash life, you might want to wait for InqPortal to notify you it is required (see previous paragraph). A full defragmentation of a brand new 3MB disk will take around 40 seconds. Another odd characteristic of flash memory is that with age (not time, but number of erase cycles) it will take longer to do a defragmentation. Toward the end of life, the defragmentation is predicted to take over 2 minutes.

File System Being Defragmented