B4J Question Asynchronous Stream with Raspberry PI

YIM bunchhat

Active Member
Licensed User
Longtime User
Hello I try to use this code run on Raspberry Pi I wonder when I connect from my PC also Phone to it, Phone or PC show message Connected but Raspberry don't show connected and when I send data to Raspberry Pi nothing work.
B4X:
'Non-UI application (console / server application)
#Region  Project Attributes
    #CommandLineArgs:
    #MergeLibraries: True
#End Region

Sub Process_Globals
    Private controller As GpioController
       Private Pin5 As GpioPinDigitalOutput
    Dim AStreams As AsyncStreams
    Dim server As ServerSocket
    Dim Socket1 As Socket
End Sub

Sub AppStart (Args() As String)
    controller.Initialize
       Pin5.Initialize(5, True)
    server.Initialize(8899, "Server")
    server.Listen
    Log("MyIp = " & server.GetMyIP)
    StartMessageLoop
End Sub

Sub Server_NewConnection (Successful As Boolean, NewSocket As Socket)
    If Successful Then
        Log("Connected")
        Pin5.Blink(100)
        Socket1 = NewSocket
        AStreams.Initialize(Socket1.InputStream,Socket1.OutputStream, "AStreams")
         'AStreams.InitializePrefix(Socket1.InputStream, False, Socket1.OutputStream, "AStreams")
    Else
        Log(LastException.Message)
    End If
    server.Listen
End Sub

Sub AStreams_NewData (buffer() As Byte)
    Dim msg As String
    msg = BytesToString(buffer, 0, buffer.Length, "UTF8")
    Log(msg)
End Sub

Sub AStreams_Error
    Log(LastException.Message)
End Sub
 

YIM bunchhat

Active Member
Licensed User
Longtime User
Hello, now it work. I find out that it error because I use B4J-Bridge run this code. To make it work must run jar file in raspberry.

1412138222714.jpg
 
Upvote 0

YIM bunchhat

Active Member
Licensed User
Longtime User
No, I never know about what you said because I am new programmer. I will try what you said. Thank you
 
Upvote 0

rwblinn

Well-Known Member
Licensed User
Longtime User
Hi,

interesting post. I also wanted to create a Asynchronous Stream with the RPI.

Could you pls share the full code of your RPi solution and how you connect from PC or SmartPhone to the RPi?

Very much appreciated
 
Upvote 0

YIM bunchhat

Active Member
Licensed User
Longtime User
Hi, Yes I prefer to share what I done. you just copy file Test_Stream.jar into your Raspberry Pi and run then connect to Raspberry Pi by type IP on your android phone > click connect button. I use GPIO3,GPIO4,GPIO5,GPIO6 to test in this case
 

Attachments

  • Phone_GUI_for test.zip
    233.9 KB · Views: 228
  • test_asynchron.zip
    416.1 KB · Views: 229
Upvote 0

rwblinn

Well-Known Member
Licensed User
Longtime User
Great and many thanks --- will test and feedback. Using the RPi is so much fun :)
 
Upvote 0

viriato

Member
Licensed User
Longtime User
Hi,
I am trying your example with B4J_bridge , can you confirm we can use it when bridge is connected ?
I have some issues connecting to the phone , I can't establish a connection , any recommendations
Thanks a lot
 
Upvote 0

YIM bunchhat

Active Member
Licensed User
Longtime User
Hello, I think while we run B4J-bridge it seem program that we compile just visible temporary and when we close B4J everything nothing have in Raspberry Pi. So you should copy .jar file to Raspberry and run it as I show on picture above.

good luck
 
Upvote 0
Top