Writing data in a .csv file not working

You have all the right pieces, but not necessarily in the right order. Try like this:

image

If I have three tags containing 1, 2 and 3, when I read the csv file I get:

"1","2","3"

as expected

2 Likes

The tag naming looks dodgy Arthur - a Tag should start with a Character and ideally logical for ease of retrieving the data. So for example instead of W_val.txt, it should simply be W_val. If you are recording many W_vals, create the Tag names in sequence. For Example W_val1, W-val2 etc

2 Likes

Although I have corrected how you save to TinyDb, saving to TinyDb seems like overkill - you could just stream to a CSV file. If the App is later going to be used to display the data in some way, it can read from the CSV file.

1 Like

How to stream values directly into a CSV file:

Last_Version_V5csv_with_on_off_buttons.aia (208.8 KB)

This will only work if the TinyDB contains lists in it.

According to the error, the TinyDB contains such a tag that contains a value which is 0.

Possibilities why this could happen :

  1. You've somewhere added something to the same TinyDB in number format (0).
  2. You've multiple TinyDB s with the same namespace, in one of which you have added a non-list value. Try changing the namespace of the TinyDB to a unique name to avoid this problem.

I can clearly see the  problem no. 1  in your blocks, under the Clock_Receive.Timer event.

There, data2 is a list containing items, and you are adding items of that list to the TinyDB, and those items are not lists, rather they are numeric values.


Tim's post will surely solve the problem, according to me.

Hi ChrisWard, I tested with your App but I got nothing back in my storage after a run.
Even if I give access to the App to my storage I got nothing more. So, I tried to change the "FileScope" to "Legacy" as I could read in similar topics from the forum but not better.
I also add an extension made by someone (found here :Error 908: The permission WRITE_EXTERNAL_STORAGE / bug) which may help in this situation but still nothing...

Remove the direct download link from your post.

Those are only allowed for the extension developer.

Rather post a link to the topic or the website.

Hi TMAI2, I aslo tried your proposition. The first error message seem to be cleaned with it but I get this one after :

So I input the extansion I speak about in my last response and got this time the following message even if I gave all permission to my App about the storage in my phone :

Oh ok, good to know, thanks

Could you create it in your ASD ?

If yes, try deleting the file in the Shared storage, then moving the file from ASD to the Shared storage using some extension.

What is the ASD ?

Application Specific Directory

It is located at

/storage/emulated/0/Android/data/<package_name>/files

Sorry, I tried to understand and search what you are explaining to me but I am lost (this is the first time I do programmation and work with a computer and I am a bit lost).

From what I understand, the following error come from the fact that the path does not exist :

image

So your proposition is to create a place or a path in my storage for the App :

Is that right ?

Which is how I showed it in my post above

Saving the file to just /myfile.csv (with the single slash) will save the file to your default read/write storage area.

On earlier android versions this may be to /storage/emulated/0 but on later versions Android 10+ (API 29+) it will be to the ASD - /storage/emulated/0/Android/data/<package_name>/files.
Earlier versions can use the ASD but you would need to target it with a path.

It is all very complicated...here is a good resource on what is happening:

I would always recommend you work to the dictates of the latest API, and keep things simple by using the default storage location.

Yes.

Next, use a File Extension to move it to the File Path you want keep the file.

Yes indeed, I use your blocks and have the following error :

I guess so this is why @SHUBHAMR69 explain to me to creat the place/path. Where can I find the File Extension you are speaking about ?

Show your current relevant blocks please

And please advise of the Android version you are using to test, and are you testing with companion or when compiled?

1 Like

Here is the block (which is fully copied from yours) :

image

I ame testing when compilided. What do you mean by "And please advise of the Android version you are using to test" ?

What is the android version of the device you are using?

Android 6,7,8,8,1,9,10,11,12 ?