B4J Question GPS - tcp connection

kreativa

Member
Licensed User
Longtime User
Hi,
I need a help!
I have a gps tracker communicating with a servlet wrote in b4j on my webserver. the tracker connect to server platform using TCP protocol.

I'tried to use AsyncStreams and y can create a connection but the gps returns my many symbols after the keep alive message.
this is the strings received from the tracker:
*HQ,4209513891,V1,124648,A,4500.0996,N,00738.2832,E,023.30,088,150616,BFFFFBFF,222,10,0,0,6#
$B

Q8�FSE s�0P������ � �

$B Q8�GE � s� ������ � �

$B Q8�GE s�hh����� � �

$B Q8�G(E P s�0 ������ � �

$B Q8�G8E ` s�v������� � �

$B Q8�GHE @ s�V������ � �

$B Q8�GXE P s�1@������ � �

$B Q8�HE s�d����� � �

$B Q8�H#E 0 s� q4����� � �



I tried with async in prefix mode but servlet tells "Prefix mode only works if both sides of the connection follow the prefix mode"
Can someone help me?
 

kreativa

Member
Licensed User
Longtime User
B4X:
Sub Process_Globals
     Dim AStreams As AsyncStreams
    Dim Server As ServerSocket
    Dim Socket1 As Socket
End Sub

Sub AppStart (Args() As String)

        Server.Initialize(8888, "Server")
        Server.Listen
        Log("MyIp = " & Server.GetMyIP)
  StartMessageLoop
  
End Sub

Sub Server_NewConnection (Successful As Boolean, NewSocket As Socket)
    Log("New connection")
    If Successful Then
        Log("Connected")
        Socket1 = NewSocket
     '   AStreams.InitializePrefix(Socket1.InputStream, False, Socket1.OutputStream, "AStreams")
        AStreams.Initialize(Socket1.InputStream,  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
 
Upvote 0

kreativa

Member
Licensed User
Longtime User
Ok,
but why the first message is standard format (i can read the imei of the gps and some other information).
Is it possible that the charset of the first string is different from the other?
 
Upvote 0

kreativa

Member
Licensed User
Longtime User
Solved!
I used byteconverter.hexfrombytes directly on buffer byte array!!

Thanks another time Erel
 
Upvote 0

Bladimir Carrillo

Member
Licensed User
Longtime User
I have a gps tracker communicating with a servlet wrote in b4j on my webserver. the tracker connect to server platform using TCP protocol.

Dear Kreativa, could you please share your code to comunicate with GPS Tracker ?

I have purchased a clone (chinese) device GPS Tracker type TK103B and have some problems to use it, please let me say to you what I have done:

- First basic configurations and test Ok(begin, centernum, timezone, check, smslink)

- When I configure APN, the result is Ok.
My location is Ecuador, the APN configuration I am using is ...

SMS Command:
B4X:
APN123456 internet.movistar.com.ec movistar movistar

Response:
B4X:
APN,CONFIG OK

- Testing connection to server, I can not access to the device from server.
I am trying to connect from server (IP:121.201.110.210 Port: 8989) http://secumore1818.com/

SMS Command:
B4X:
adminip123456 121.201.110.210 8989

Response:
B4X:
ADMINIP,CONFIG OK

SMS Command:
B4X:
GPRS123456 1

Response:
B4X:
GPRS,CONFIG OK

- After that configurations, do not have any more responses to sending sms commands (smslink, check).

I will appreciate any sugestion.

Thank you in advance for your help.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…