Android Question Database or Loop-Up table

Declan

Well-Known Member
Licensed User
Longtime User
I have a number of Arduino based sensors (48 in total) that talk to my Android device using USBSerial.
All OK and data comes in and send data to the sensors as expected.
I now wish to implement either a database or a lookup table to store certain parameters for the sensors.
This would reside on my Android device so connection to a remote database or lookup table is not required.

My questions are:
What would be a better choice - database or lookup table?
Are there any example apps for a complete novice like myself?

Many thanks
 

Declan

Well-Known Member
Licensed User
Longtime User
@eurojam, Many thanks.
Having looked at the KeyValueStore class, I am confused as to whether I will be able to setup as follows:
The 48 sensors that I have, each have 2 parameters that I can change within them (sent from the Android device via USBSerial)
These parameters are "grouped" into a Description.
Similar to a Database having: Table ("Description") and Fields ("Sensor1Parameter1 / Sensor1Parameter2" / "Sensor2Parameter1 / Sensor2Parameter2" through to Sensor 48).

Could I have 10 "Description" "Tables" each with 96 Fields.

Using KeyValueStore, could I have 10 named arrays that would each have 96 fields to the array?

Hope this makes sense.
 
Upvote 0

Declan

Well-Known Member
Licensed User
Longtime User
Thanks Erel,
So I could have 10 custom types, each with the required 96 fields?
For instance:
B4X:
    If FirstTime Then
        kvs.Initialize(File.DirDefaultExternal, "datastore0")
        kvs.Initialize(File.DirDefaultExternal, "datastore1")
        kvs.Initialize(File.DirDefaultExternal, "datastore2")
        kvs.Initialize(File.DirDefaultExternal, "datastore3")
        kvs.Initialize(File.DirDefaultExternal, "datastore4")
        kvs.Initialize(File.DirDefaultExternal, "datastore5")
        kvs.Initialize(File.DirDefaultExternal, "datastore6")
        kvs.Initialize(File.DirDefaultExternal, "datastore7")
        kvs.Initialize(File.DirDefaultExternal, "datastore8")
        kvs.Initialize(File.DirDefaultExternal, "datastore9")
    End If

Working on the assumption that the above "datastoreX" is a Table, how would I write the 96 parameters to each table?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I think it will Not work. You Are initialize the Same kvs 10 times instead one kvs and Store 10 maps in it...
You should learn how the kvs works and What you can Do With it
 
Upvote 0

eurojam

Well-Known Member
Licensed User
Longtime User
Manfred and Erel are meaning something like this construction (more or less...):
B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
   Type sensor (id As Long, param1 As String, param2 As String, param3 As Int, and_so_on As String )
   Dim sensormap As Map

End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    sensormap.Initialize
    For i = 1 To 48
        Dim s As sensor
        s.Initialize
        s.id = i
        s.param1="Sensor" & i
        s.param2="Eurojams best sensor ever"
        s.param3=123
       
        sensormap.Put(s.id, s)
       
    Next

End Sub
 
Upvote 0

Declan

Well-Known Member
Licensed User
Longtime User
Thanks for the responses.
I am now using the DBUtils example and editing it for my app.
I have an error which I have posted in a different thread.
 
Upvote 0
Top