Reading from a wireless SD card

General discussion about anything related to Ultibo.
Posts: 36
Joined: Mon Jan 07, 2019 11:57 pm

Reading from a wireless SD card

Postby Poi » Sun Apr 14, 2019 1:15 am

After finding out that booting the Pi Zero W from USB wasn't going to help too much with the hassle of copying files to the sd card and inserting the card each time, I figured out I would try with a wireless SD card. A bit backwards since the Zero W already has wireless connectivity hardware built in, but you know, sometimes you have to do strange things.

So I got one of these and a micro sd to sd adapter. After messing with the settings for a little bit, I got the thing working and the workflow ain't bad at all.

I got my build script that creates the kernel file and then copies it through wifi to the card, which is already connected to the pi, so no more hassle.

It's almost perfect, I say almost because when the new kernel is copied over to the card, Ultibo doesn't seem to understand this happened.

I thought about writing a small unit to periodically monitor the kernel file for changes, it really just boils down to checking if the result of this function, gives me a different timestamp.

Code: Select all


If there is a change I call

Code: Select all


And the whole thing should pick up the new changes, or that's what I thought was going to happen.

What actually happens is that the continual queries to the file age just return the same value. If I cut the power and then turn it back on, then the changes are picked up correctly. So the kernel file is updated, just not in real time it seems.

Is this the expected behaviour of Ultibo? I know it is a bit of a weird scenario, so that is why I am asking.
User avatar
Site Admin
Posts: 2291
Joined: Sat Dec 19, 2015 3:49 am
Location: Australia

Re: Reading from a wireless SD card

Postby Ultibo » Mon Apr 15, 2019 12:04 am

Poi wrote:Is this the expected behaviour of Ultibo? I know it is a bit of a weird scenario, so that is why I am asking.

The Ultibo filesystem caches the directory entries in order to avoid reading them from disk each time you want to look for a file, because FAT is not designed to be a shared filesystem (two hosts accessing it at once) then caching such things is the normal behavior.

Because the wireless SD card is independently making changes to the SD without Ultibo knowing then it keeps returning you the cached directory entry with the old date and time.

The quickest way to get it to reread this information is simply to dismount and remount the volume which you can do in software using something like this:

Code: Select all

   DRIVE_C = 3;

   // Dismount Volume 1 (drive C)
   // Mount Volume 1 as drive C
   FileSysDriver.MountVolume('\Volume1', DRIVE_C);

This makes the assumption that the SD card will be volume 1 and will be drive C, that will be true as long as you only have the SD card plugged in. In a real world usage there are functions in the file system driver to determine which volume drive C is located on and choose the correct one but I'm assuming this will be good enough for development purposes.

We'd also recommend that if you put this in a loop and dismount/mount the volume each time before calling FileAge() that you put at least a delay of 1 or 2 seconds between each iteration to avoid consuming most of the CPU time on this one function. | Make something amazing
Posts: 36
Joined: Mon Jan 07, 2019 11:57 pm

Re: Reading from a wireless SD card

Postby Poi » Mon Apr 15, 2019 10:18 am

This is great!

After going through the documentation of the SD card I found that if you make changes to the card through wifi, the only way for the host to pick up the changes is to unmount and mount again, but I thought you couldn't do that directly from Ultibo.

I'll be sure to try this out.

Return to “Discussion”

Who is online

Users browsing this forum: No registered users and 2 guests