File component issue (Using Bluetooth, TinyDB to control a Plant watering system)

Hi Peter

Wondering if you could help. Been awhile since I have been on the site. Wrote a couple of simple apps back then for a couple of Bluetooth applications. It's my first time using "File". Trying to create a programable timer using comma delimited user inputted data, Save and Get on an Android 9. using Internal storage. The data is being stored like this: I entered "11, 22, 33, 44" and it saved like this ",1122,33,44," . Any idea what I am doing wrong?

blocks (1).pdf (188.1 KB)

Thanks for the help

Your description and blocks don't say much about the problem. Try to explain in more detail what the problem is. Maybe you can use TinyDb instead of a file?

Thank you for the quick response Patryk. Here goes.

I am trying to create a cellphone operated timer using bluetooth to control a water pump. The Bluetooth app will control the AC motor using a DSD 2 Channel relay board. The communications portion to the relay part of the app I have already completed. The Start/Stop button accomplishes the interface for that.

I have limited knowledge with respect to file programming using phone app software. The last time I had to deal with them is back in the Visual Basic 5 days almost a half a century ago. :wink: Yep, i'm old!

The next portion of the app involves the user to enter their own pump on and off (On/Off) time. On for just a few seconds then off. They will specify an amount of time to allow the water to soak into the soil before repeating the on/off time again (Duration). They will enter the (On/Off) cycles up to 7 different times as well as the (Duration to wait between (On/Off) cycles. The Timer would use these values and follow in sequence the (On/Off) and (Duration) cycles. Once the information has been inputted the user can then save these (On/Off) and (Duration) times in a file that they can then call up when they need to use these same cycle times again. The reason for the different files with programmable (On/Off) and (Duration) times are because of different size pots require different watering times and there are different timings for Feeding verses Flushing of the plants.The other issue is that the user needs to be able to recall these (On/Off) and (Duration) cycle times for future use. They also may have to readjust their initial setting and re-save the file.

The other part of this app involves when to start the cycling. The user will be able to specify the time in a 24 hour period at which to start the watering cycle. I thought I would use the Timepicker component for that.

The screen image I sent previously is what my screen will look like. And the programing block I sent is as far as I have gotten. The issue I described previously is why I have contacted you for assistance. It's obvious I have no Idea what I am doing! I have never used TinyDB or File before. I want to keep the files on the phone if possible.I am using a Galaxy J3 Achieve with version 9 software. Also I am using the MIT AI2 Companion interface to debug the code. I hope this gives you enough info.

Thank you for your help.

There are three main ways to save data for the future.
File - method you want to use. Creates a file in the phone memory. The file may remain even when you delete the application (not in android 11). Only you can access the data.
TinyDb - saves data in the application memory. The data will remain after the application is closed. Data will be lost after uninstalling the application. Only you can access the data.
Online database - you can use, for example, google sheets to save data. The data will remain there forever, until you delete it. More household members may have access to the data.

I noticed that you are adding each data separately to the file. You would have to first form all data for writing, separating them, for example, with commas, and then save them once, overwriting the previous data. In your case, it is better to use the save file command than append to file.

TinyDB is perfect for saving named data in a phone with no fuss and no worries about marshalling it into proper formats for file storage.


@jwilliams10026 I would totally use the TinyDb rather than the file in this case, makes things wayyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy less complicated, as @ABG has said. Also, your UI is so slick... how long did it take you to make and plan out? Nice work.

Thanks Alexander

I've been working on the app for 2 days so far. I've done a couple Bluetooth apps before so I just borrowed that code. new graphics was nothing. The watering system itself took almost a month. Osmosis system, 2-50 Gal tanks for watering, 5 tents, Separate fertilizer tank, 100-6" watering rings, manifolds, pump, bladder, valves, plumbing . . . . .you get the picture.This is actually part of a bigger project. A totally automated grow system for my sister who is a grower. Waters, fertilizes, measures Ph, humidity, light, temperature, flushes her grow. Eventually I will set it up using Wifi. The basic system does 100 plants with expandability up to 1000.

Here is an earlier view of part of the system.

I have placed control valves in parallel with all the shut-off valves to automate.


Thank you Patryk

I have no experience with TinyDB is the "tag" the same as "file name"?, Also, are you saying I need to combine all the data into one string using comma delimiting before saving to file? If thats the case I should probably create an array for the information right. Can I do that with text box components? I need an index number or something right? or is there another way to do it?

In tinyDb, you save the data under a tag. Tag is any string, equivalent to a file name in component file. You can use text blocks such as "join" to format the data.
See an example:

Data from text field1 is connected with a comma with data from text field 2. Then the data created in this way is saved to TinyDb under the tag "name tag". You can also create a separate tag for each text box.

To read both data from TinyDb and enter them into text boxes, you create blocks like this:

First, we create a data list by dividing the recorded data at the comma. Then we add data with the appropriate index from the created list to the text field.
Of course, this is just an example. There are many ways to write and read.

@jwilliams10026 The tag is basically the namespace of what you want to store. It is how the system finds things. Like putting 100 under Coins. You can store multiple things as a list of data, like a list containing the water amount in the tank, and the fertilizer amount in the other tank (tag=Tanks), and under another tag a list of the nutrient %'s (tag= nutrients), or you can store items as separate things. You can also use / to make subcategories, like this ↓

Edit: Using / to make subcategories only works with FB (Firebase). It will create a flat string otherwise in the tinydb.

Off-topic- You must be pretty good at plumbing to attempt a project like that. Props for making it this far!

I am starting to understand pretty simple. How do I get the 3 node in the "join" component?

You will find it in pink text blocks.
Here are the descriptions of the "text" blocks:

"List" blocks here:

TinyDb here:

I thought so but my version of MIT App Inventor only has the 2 node "join".

Use the mutator (small blue square on the block) to add more sockets


Cool! I didn't know you could do that. See you can teach an old dog new tricks! :grin: So should I just keep adding nodes for all 14 settings and make it one big record with ","s between to make it easier to parse when I place the info back into the text boxes when I get the info back out?

1 Like

Awesome because different plant require different nutrients, temps, humidities etc. this info is very helpful thank you!

Thanks my dad taught me back in the 50's! yep still old! :joy:

1 Like

You can combine all 14 data and create one tag. You can also create 7 tags, in one tag store "on / off" and "duration" from one line. Or you can use two tags, one holds all on / off data, the other all duration. Full freedom.