B4J Question Web App, how to exchange data between Main & class instance

madru

Active Member
Licensed User
Longtime User
Hi guys,

I need some help and guidance ……

I have done a Raspberry Console App for a client of mine some time ago, this App collects and receives data from different drill and CNC machines. The received data got prepared and displayed on a remote App.
My client tasked me now to get rid of the ‘Display App’ in favor of a Web based App.

I studied Erels examples and began with some coding….based on the 'Guess My Number - WebSocketsr' example

I have done most of the code now but in a really bad way where the ‘Web class’ is reading the data from Main via a timer :(

I couldn’t figure out how to get the data from Main (where all the collection is happening) ‘into’ the web class as CallSubDelayed does not work.

Can somebody explain how to do correctly?
 

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
The timer approach is not completly incorrect but don't make it read from main. Just store it in a database and call it from the webclass that way you will have a truly async environment.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The correct term, and it is important to understand it, is class instance. Not Class.

The question is how to get a reference to the right class instance. There could be million class instances running at the same time. Each client is managed by its own instance.
Do you want to send to all of them? To a few? How will you distinguish between the clients?

The way to do it, and it is demonstrated in some of the examples, is with a concurrent map that holds all the live connections.
 
Upvote 0

madru

Active Member
Licensed User
Longtime User
Hi Erel, changed to class instance .....

oops, you raise valid points here, I haven't thought about them :(
before it was easy all done via MQTT.....

the amount of concurrent clients is 10 max, and each of them should get the data and should be able to control the 4 I/O ports of the RPi

I will have a look at the chat example

THX
 
Upvote 0

hatzisn

Well-Known Member
Licensed User
Longtime User
I have never touched an RPi but if I was you and it can be done I would go the outside server way. We don't you post the data to an on-line DB accessible wherever your client is through the Internet and not possibly only in local network.
 
Upvote 0
Top