Issues writing to Spotter SD card

Hello, we are currently on the step of writing to the Spotter SD card in the Bristlemouth Dev-Kit Guide (5) and we are having some issues. We want to send a file from the computer to the SD card in the Spotter. I just want to clarify exactly how we would go about doing that. Would we use the bm-fprintf line?

Thank you

Hi Samkit,

If you have a file on your computer that you want to copy to the SD card once, it’s easiest to simply remove the SD card from Spotter, copy the file, then put the SD card back in the Spotter.

If, on the other hand, you want to write code that runs on the dev kit, and you want that code to write to a log file on the Spotter’s SD card, your code should call the function bm_fprintf. This is what is shown in Guide 5.

You can use that function like this:

bm_fprintf(BM_ALL_NODES, "your_chosen_filename.log", "The content to append to the file\n");

Hope that helps!

Hello, thank you for the feedback. Is there any way to copy a file onto the SD card through code? As in, without having to remove the SD card. Currently I am under the impression that the bm_fprintf code shown in guide 5 is to append to a file already on the SD card.

Thank you,
Samkit Bothra

There is a way to copy files from your computer to the SD card without removing the SD card from Spotter. Start by connecting a USB cable between your computer and Spotter, and connect to the Spotter serial terminal.

When you type the help command into the Spotter serial terminal, you will see many options. One group of commands near the top of the list starts with sd. One option within that group is listed like this:

  • usbrw - make the SD card available over usb as READ and WRITE

So, you can enter the command sd usbrw, and then wait several seconds. Eventually, the SD card will be mounted as a drive on your computer, and you can copy files as normal. This connection is slower and less robust than natively mounting the SD card in your computer, but it can be convenient.

You will need to reset the Spotter when you are finished to cause it to mount the SD card again.

Hope that helps.

If code running on your Dev Kit calls bm_fprintf with a filename that does not yet exist, the file will be created.

Okay, that makes sense, thank you. I had one last question. We are able to write information to the SD card using your help but whenever we write we see, “37056t |” before every entry. The number always changes but we wanted to know if there was a way to modify the “bm_fprintf” line so it would not add that? We were looking through the files provided on GitHub but have been struggling to find anything.

Thank you,
Samkit Bothra

Thank you! No, there’s no way to do that right now, but we should definitely add that. We have the capability to optionally print the timestamp line header in the the bridge app for some Spotter core log files, but that is not an option with the current implementation of bm_fprintf.

So, currently, you’ll need to post-process those logs to strip out the timestamp header.

I’ve written up this github issue that anyone could work on to begin adding this feature: Enable writing files with bm_fprintf without inserted timestamp log line headers · Issue #154 · bristlemouth/bm_protocol · GitHub

It will also require work in Spotter firmware to support the new feature, but if we get the Bristlemouth side done first, that can be super quick.

Thank you for bringing this issue to light. Since we are trying to remove the timestamp, is there a function that just prints a buffer of any length to a bristlemouth file? We think that you’re adding the timestamp before calling the function somewhere in the code. We were looking through the modules and files given to us of the Bristlemouth code and could not find the function that just prints a buffer itself at the end of the call. Is it possible for us to find that function and call it in our own code?

Thank you,
Samkit Bothra

The bm_fprintf function is the one you’re looking for, but until that feature I mentioned above gets implemented, the timestamp will always be added. It’s the Spotter that has all the SD card code, not Bristlemouth.

In order to understand why, one needs to grasp what the separate components of this distributed system are doing.

  • On your dev kit, your code calls bm_printf which sends a Bristlemouth publish message on the Bristlemouth network here. There’s no timestamp added to the buffer at this point.
  • All the nodes on the Bristlemouth network receive this message, but most ignore it.
  • The Spotter subscribes to this particular type of message. It acts on newly received messages by adding the timestamp and writing to the SD card.

So in order to write a buffer to a file on the SD card without timestamps, we need firmware changes in both Bristlemouth and in Spotter.

  • The message that gets published on the Bristlemouth network needs additional information indicating that you don’t want the timestamp added.
  • The Spotter then will have the information it needs to know whether or not the user wants the timestamps added.

Hope that helps!

@samkitbothra this feature request has been worked on, merged into the bristlemouth development branch and is slated for next release! Please see the following pull request for implementation.
Cheers!

1 Like

The requested feature adding the ability of Bristlemouth dev kits to write to files in the bm folder of a Spotter SD card has been released in v0.12.0.

Announcement: Firmware v0.12.0 Released

Thanks for continuing to help us to make Bristlemouth the best it can be!