B4J Question Triggers

aaronk

Well-Known Member
Licensed User
Longtime User
Hi,

I am trying to work out how to do a server based triggers and macros.

I understand I can write a IF statement but I need to do this dynamically, so I can't hard code the IF statement.

For example, lets say in my B4J app I have setup a connection which is a TCP connection listening on port 5432.

A new TCP connection on port 5432 is made, the server accepts that message and the client sends the ASCII message: Bob/1430/abc123

My B4J app then receives this message and splits the message into an array.
0 = Bob
1 = 1430
2 = abc123

Array 0 (Bob) is always unique, but array 1 & 2 can change.

So if I convert Array 1 to a time (14:30) I now need to write Array 2 (abc123) at 14:30 to the log but then trigger it again at 14:30 the next day.

I have come across the CallSubDelayedPlus in the CallSubUtils class. This would work and then work out the time difference etc. But can't work out how to then stop this from triggering if I then later decide I no longer want it to trigger at 14:30.

The problem I am going to have is if my server is reset, the above will stop working until it's set again. I need a way to start it again once the server is started again.

Another trigger that could happen would be:

A new TCP connection on port 5432 is made, the server accepts that message and the client sends the ASCII message: Bob/----/xyz987

When a ASCII message is sent (for Example: RUN/Bob) this would need to trigger all Bob commands which don't have a time set (----).

So if the command RUN/Bob is received it should then log xyz987 in the log only.

I was thinking of storing that trigger in a Map. However there could be over 100,000 - 200,000+ items in the map. (would I have issues having that many in a map?) However, if my server is reset I need to keep these values (just like the previous trigger), so I was thinking of creating a SQL database to store the values and then when the RUN/Bob command is received to use a SQL command to select only the Bob commands from the database and run them rather than using the map.

Anyone got any ideas on how I can do the above, or is the way I suggested (by using a SQL database) the best way ?
 

aaronk

Well-Known Member
Licensed User
Longtime User
Let me try and explain it a little better..

This is just an example to help understand what I am trying to do.

Lets say there is cars out on the road and they will send ASCII messages to my B4J app by TCP.

Each car has a unique ID.
Car 1 unique ID = Bob
Car 2 unique ID = Tom
Car 3 unique ID = Bill

There could 100,000 - 200,000+ cars.

Each car will send a message to the B4J app every 30 seconds.

For Example:
Bob/testing1

Bob = Car 1 unique ID
testing1 = command from the car (this command will change each time the message is sent)

When my B4J app gets this command above, it needs to trigger the rule in my B4J app. (more on setting this rule/trigger below)

My B4A/B4i app will allow the user to set rules/triggers on the B4J app using a ASCII message.

For Example, if the B4J/B4i app sends:
Bob/----/testing1

It needs to be able to store that command in the B4J app.

In the above example:
Bob = Car 1 unique ID
---- = Time (this was not set in the example)
testing1 = Command

How does the server trigger an event?
Each time the car sends the message it will trigger the rules on the B4J app.

When the car sends the message the rule section in the B4J app will need to run and check if the command is in the list.
So, for example if the message received from the car is Bob/testing1 and the command testing1 is the list set by the B4A/B4i app then write the message to the log.

Another Example, if the B4J/B4i app sends:
Bob/1430/testing2

It needs to be able to store that command in the B4J app.

In the above example:
Bob = Car 1 unique ID
1430 = Time (14:30)
testing2 = Command

The second example would need to trigger automatically at 14:30 and would need to log the message testing2.

So, I need help with the storing of these rules/triggers which the B4A/B4i sends. Need them stored so if I reset the app they are still there, and the automatic rules (like the second example) start again at the required time.

I was thinking of storing them in a map, but if the B4J app is reset then the map is cleared, so this is not the best way.

I then thought of using a SQL database to store the commands which the B4A/B4i sends and then use a SQL command every time a car sends the message, but not sure if this is the best way or not. But then I am stuck trying to work out how to start the automatic triggers like in the second example when I start the B4J app.

(Hopefully this makes more sense on what I am trying to do.)
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Instead of a tcp-connection i would use kind of webserver inside the b4j app and call it´s endpoint(s) with b4a to send a command (httputils2),
split the commands into a array and fill a database with the entry.

I´m only in my lunchbreak (not much time) but i think this would be the way i would do it when i have your requirements...

A small webserver will be easier handled by the b4j app i guess than thousands of tcp-connections....

Just my thoughts... No need to change your system if it is working for you.
 
Upvote 0

aaronk

Well-Known Member
Licensed User
Longtime User
Yeah, I have incoming data working fine.

So, using a database to store the commands is the way to go? Then do a SELECT * FROM table WHERE car=Bob and then run through the commands to see if any match the incoming data ?
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…