B4R Question [SOLVED]Asyncstream with B4RSerializer vs SendEventToServer with Strings

rwblinn

Well-Known Member
Licensed User
Longtime User
Hi,

while working on a B4R experiment to monitor the state of REED switches connected to a NodeMCU.
If the state changes, data is send to a B4J server and stored in a MongoDB which is accessed via Browser (via WebSockets with port; shown in jQuery datatable).

To send data from the B4R client to the B4J server, two options (or may be more) either using asyncstreams with the new B4RSerializer (server is listening server.listen) or WebSocket send event (server is running server.start).

It not clear which is the best way to use? Any advice appreciated.

' Taken from the B4RSerializer example.
' If using asyncstreams then two ports are required else the Browser clients can not connect
B4X:
astream.Write(ser.ConvertArrayToBytes(Array("STATECHANGE", "REED Switch 1", State)))

' Taken from ArduinoWebSockets Example
' One port required; data must be strings
B4X:
websocket.SendEventToServer("Switch_StateChanged", Array As String("flag", "statechange", "switch", "reed 1", "state", State))
 
Last edited:

rwblinn

Well-Known Member
Licensed User
Longtime User
SOLVED by using SendEventToServer. Will share soon the experiment - but here a screenshot of the working solution.
 

Attachments

  • upload_2016-10-31_15-39-23.png
    upload_2016-10-31_15-39-23.png
    327.1 KB · Views: 383
Upvote 0
Top