B4J Tutorial [Server] Data Collection Solution - Device, Desktop and Web reports

Status
Not open for further replies.
This is an example of building a data collection solution. The solution is made of three components:
- (B4J) Server - Manages the data in a SQLite database.
- (B4A) Device client and (B4J) desktop client - Send new data to the server and show reports.

Note that you can also see the reports from any browser.

In this example we want to track animals. The following type is declared in all three projects:
B4X:
Type Animal (Name As String, Age As Double, Location As String, Date As Long)

upload_2014-1-29_16-0-32.png
upload_2014-1-29_16-1-10.png


Animal objects are sent to the server. This is done with RandomAccessFile as explained here:
Send and receive objects

Both the server and the clients are pretty simple (check the code!).
As we are using SQLite database we set the handlers to be single threaded and thus avoid issues with concurrent transactions.

You can make the server accessible over the internet by following the steps described here:
Upload files from your B4A app to your B4J server over the internet

If you run it in the local network then you only need to open the firewall port (51042 in this example) to incoming connections.
 

Attachments

  • DataCollectionServer.zip
    4.7 KB · Views: 2,080
  • DataCollectionDevice.zip
    8 KB · Views: 1,815
  • DataCollectionDesktop.zip
    2.1 KB · Views: 1,080
Last edited:

mariomb

Member
Licensed User
Longtime User
Ciao, ho provato tutto e tutto funziona regolarmente sul pc con emulatore.
Anche dopo aver fatto una modifica in DataCollectionDevice,
trasformando la riga : (link = "http://192.168.123.1:51042")
in (link = "http://" & txtIP.Text & ":" & txtPort.Text) per poter modificare indirizzo ip e porta a piacimento.

Quando però installo apk di DataCollectionDevice sul mio tel (huawei P6 con android 4.2.2)
ricevo il seguente errore : "illegal character in authority at index 26"

da cosa può dipendere? Qualcuno può aiutarmi?
grazie :confused:
 

luke2012

Well-Known Member
Licensed User
Longtime User
Hi @Erel,
I reproduced your solution on a windows pc. Which is the steps to reproduce the b4J server on a Raspberry PI board?
 

desof

Well-Known Member
Licensed User
Longtime User
Hello very good your example and I'm trying to make it run but I get this error:

2015-06-26
CreateTable: CREATE TABLE IF NOT EXISTS [Animals] ([Name] TEXT, [Age] REAL, [Location] TEXT, [Date] TEXT)
2015-06-26 17:21:57.123:INFO::main: Logging initialized @288ms
2015-06-26 17:21:57.217:INFO:eek:ejs.Server:main: jetty-9.1.z-SNAPSHOT
2015-06-26 17:21:57.250:WARN:eek:ejh.MimeTypes:main: java.util.MissingResourceException: Can't find bundle for base name org/eclipse/jetty/http/encoding, locale es_ES
2015-06-26 17:21:57.265:INFO:eek:ejsh.ContextHandler:main: Started o.e.j.s.ServletContextHandler@4f4a7090{/,file:/E:/JAVA/DataCollectionServer/DataCollectionServer/Objects/www,AVAILABLE}
2015-06-26 17:21:57.269:INFO:eek:ejs.AbstractNCSARequestLog:main: Opened E:\JAVA\DataCollectionServer\DataCollectionServer\Objects\logs\b4j-2015_06_26.request.log
2015-06-26 17:21:57.367:INFO:eek:ejs.ServerConnector:main: Started ServerConnector@7c30a502{HTTP/1.1}{0.0.0.0:51042}
2015-06-26 17:21:57.367:INFO:eek:ejs.Server:main: Started @539ms
 

MarkusR

Well-Known Member
Licensed User
Longtime User
@Erel , please can you update DataCollectionDesktop.zip at first page to work with B4J 6.01?
I replaced the message boxes and server ip etc but after start there is no window and i can not open the form designer.
the DataCollectionServer part seems running well.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
i can not open the form designer.
It is based on scene builder so you need to install it (don't do it).

The issue with WebView can be fixed by first showing the form and only then loading the layout: Java 9 and WebView (and GoogleMaps)

Overall this is an old example and not so recommended anymore...
 

MarkusR

Well-Known Member
Licensed User
Longtime User
@Erel, i think my issue was that i can not run 2 b4j projects (server & client) from ide in debug mode.
the second project waits for the debugger for connect. (i used now one in release mode)
i like this example because it is all in one, pc server,pc client and mobile, data grid and database :)

@Others
i found also a nice sql lite db management tool
http://sqlitebrowser.org/
 
Last edited:

AHilton

Active Member
Licensed User
Longtime User
MarkusR, yes you can. I start project1 (the server) in debug mode. I then start project2 (the client) in debug mode a few times (normally on the 3rd time) before it will start. As long as you don't restart the project1, project2 will restart on the first time after that initial try. It's a big pain and time waster but it's what's available to us for now.

I've put in a wish list item for this problem a long time ago but the only response was to run project1 in release mode. That's not a fix.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User

AHilton

Active Member
Licensed User
Longtime User
... please note that the time a feature was requested in not considered at all ...

Thanks for making that clearer, Erel.

The point I was making, MarkusR, is that it's a known issue. Perhaps adding your voice to the appropriate forum, B4J Bugs & Wishlist, would help. In the meantime, you have a few options...

- Run your server in runtime mode and your client in debug
- Run both your server and client in debug but requiring you to start your client several times each time you restart (ie change something on) your server project.
- Develop your server project in a VM and your client project normally. Both in debug mode.
- Develop server and client projects on 2 different machines.

And that's where I'll leave it as this has diverged from the thread topic.
 

karelespinoza

New Member
Licensed User
Longtime User
Hello, I need help I am very new in client-server applications, I have to develop client applications in adndroid and applications in windows, that enter and update information in a database to get reports.
 
Status
Not open for further replies.
Top