B4R Question Not able to connect TCP Server

Discussion in 'B4R Questions' started by pokhraj_d, Oct 5, 2018.

  1. pokhraj_d

    pokhraj_d Member

    Hello All,

    I am not able to connect the TCP cloud server from GSM 800L module.
    While I am connecting manually from putty, it is successfully connected.
    But when I am trying to connect from b4r it is just going till CIFSR. Then nothing is happening.

    From Putty:
    =================
    Code:
    AT+CIPSHUT
    SHUT OK
    AT+CIPMUX=
    0
    OK
    AT+CGATT=
    1
    OK
    AT+CIPMODE=
    0
    OK
    AT+CSTT=
    "airtelgprs.com"
    OK
    AT+CIICR
    OK
    AT+CIFSR
    100.96.67.6
    AT+CIPSTART=
    "TCP","88.99.245.201","80"
    OK

    CONNECT OK
    From B4R:
    ==============
    Code:
    ****************
    AT+CIPSHUT
    ****************
    SHUT OK
    Connect State: 
    2
    ****************
    AT+CIPMUX=
    0
    OK
    Connect State: 
    3
    ****************
    AT+CSTT=
    "airtelgrps.com"
    OK
    Connect State: 
    4
    ****************
    AT+CIPSTATUS
    OK
    STATE: IP START
    Connect State: 
    5
    ****************
    AT+CIICR
    ****************
    OK
    Connect State: 
    6
    ****************
    AT+CIPSTATUS
    OK
    STATE: IP GPRSACT
    Connect State: 
    7
    ****************
    AT+CIFSR
    100.114.52.246
    After that nothing is coming up.
    Can anyone suggest on this?

    Thanks-
    Pokhraj Das
     
  2. pokhraj_d

    pokhraj_d Member

    I am able to connect successfully at the TCP server.
    But I am getting the HTTP request in below format :
    Code:
    Sending data
    ****************
    POST  HTTP/
    1.0
    Host: cryptappz.in
    Content-
    Typeapplication/jsth: 4
    11.7
    ****************
    SEND OK
    ****************
    HTTP/
    1.1 400 Bad Request
    Server: nginx
    Date: Fri, 
    05 Oct 2018 ml
    Content-Length: 
    166
    Connection:
    ****************
     close
    Is this is a correct format?
    My code as below :
    Code:
    ************APP Module********
    #Region Project Attributes
        
    #AutoFlushLogs: True
        
    #CheckArrayBounds: True
        
    #StackBufferSize: 300
    #End Region

    Sub Process_Globals
        
    'These global variables will be declared once when the application starts.
        'Public variables can be accessed from all modules.
        Public Serial1 As Serial
        
    Public APN As String="airtelgprs.com"
        
    Public host As String="cryptappz.in"
        
    Private mytemp As String="11.7"
        
    Private timer1 As Timer
    End Sub

    Private Sub AppStart
        Serial1.Initialize(
    115200)
        
    Log("AppStart")
        timer1.Initialize(
    "timer1_Tick",2000)
        timer1.Enabled=
    True
        GSM.Init(
    10,12)
        GSM.Start
    End Sub

    Private Sub timer1_Tick
        GSM.GetTemp(mytemp)
    End Sub
    Code:
    ************GSM Module***********


    Sub Process_Globals
        
    Private serial As SoftwareSerial
        
    Private bc As ByteConverter
        
    Private astream As AsyncStreams
        
    Private EOL() As Byte = Array As Byte(1310)
        
    Private busy As Boolean
        
    Private state As Int
        
    Private ServerResponse As Boolean
    End Sub

    Public Sub Init(rx As Byte, tx As Byte)
        
    serial.Initialize(9600, rx, tx)
        astream.Initialize(
    serial.Stream, "astream_NewData"Null)
        astream.WaitForMoreDataDelay = 
    100 'make sure that we receive full messages
        busy = False
    End Sub


    Private Sub SendCommand (cmd() As Byte, ResponseExpected As Boolean) As Boolean
        
    If busy Then Return False
        busy = ResponseExpected
        astream.Write(cmd).Write(EOL)
        
    Return True
    End Sub

    Public Sub CheckRegistered
        SendCommand(
    "AT+CREG?"True)
    End Sub

    Private Sub CheckRegisteredResult (buffer() As Byte)
        
    If bc.IndexOf(buffer, "+CREG: 0,1") > -1 Or bc.IndexOf(buffer, "+CREG: 0,5") > -1 Then
            
    Log("Registered")
        
    Else
            
    Log("Not registered")
        
    End If
    End Sub


    Public Sub Start
        state = 
    1
        ServerResponse = 
    False
        Connect
    End Sub

    Private Sub Connect
        
    Log("Connect State: ", state)
        
    Select state
            
    Case 1
                astream.Write(
    "AT+CIPSHUT").Write(EOL)
            
    Case 2
                astream.Write(
    "AT+CIPMUX=0").Write(EOL)
            
    Case 3
                astream.Write(
    "AT+CSTT=""").Write(Main.APN).Write("""").Write(EOL)
            
    Case 4
                astream.Write(
    "AT+CIPSTATUS").Write(EOL)
            
    Case 5
                astream.Write(
    "AT+CIICR").Write(EOL)
            
    Case 6
                astream.Write(
    "AT+CIPSTATUS").Write(EOL)
            
    Case 7
                astream.Write(
    "AT+CIFSR").Write(EOL)
            
    Case 8
                astream.Write(
    "AT+CIPSTATUS").Write(EOL)
            
    Case 9
                astream.Write(
    "AT+CIPSTART=""TCP"",""").Write(Main.Host).Write(""",""80""").Write(EOL)
        
    End Select
    End Sub

    Public Sub GetTemp(mytemp() As Byte)  <<<<---I added This
        GlobalStore.Put(
    0,mytemp)
    End Sub

    Private Sub AfterConnect
        
    Log("Connected!!!")
        astream.Write(
    "AT+CIPSEND").Write(EOL)
    End Sub

    Private Sub ReadyToSend
        
    Log("Sending data")
        ServerResponse = 
    True
        astream.Write(
    "POST ").Write(" HTTP/1.0").Write(EOL)
        astream.Write(
    "Host: ").Write(Main.Host).Write(EOL)
        
    'astream.Write("Authorization: key=").Write(Main.API_KEY).Write(EOL)
        astream.Write("Content-Type: application/json").Write(EOL)
        astream.Write(
    "Connection: close").Write(EOL)
        astream.Write(
    "Content-Length: ").Write(NumberFormat(GlobalStore.Slot0.Length, 00)).Write(EOL)
        astream.Write(EOL)
        astream.Write(GlobalStore.Slot0)
        astream.Write(
    Array As Byte(0x1a))
    End Sub

    Private Sub Error
        
    Log("Error!")
    End Sub


    Sub AStream_NewData (Buffer() As Byte)
        
    Log("****************")
        
    Log(Buffer)
        
    If ServerResponse Then Return
        busy = 
    False
        
    Select True
            
    Case bc.IndexOf(Buffer, "+CREG:") > -1
                CheckRegisteredResult(Buffer)
            
    Case bc.IndexOf(Buffer, "+CIFSR") > -1
                
    Dim i As Int = -1
                
    Dim count As Int = 0
                i = bc.IndexOf(Buffer, 
    ".")
                
    Do While i > -1
                    count = count + 
    1
                    i = bc.IndexOf2(Buffer, 
    ".", i + 1)
                
    Loop
                
    If count = 3 Then
                    state = state + 
    1
                    Connect
                
    Else
                    Error
                
    End If
            
    Case bc.IndexOf(Buffer, "CONNECT OK")  > -1
                AfterConnect
            
    Case bc.IndexOf(Buffer, ">") > -1
                ReadyToSend
            
    Case Else
                
    If bc.IndexOf(Buffer, "OK") > -1 And state < 9 Then
                    state = state + 
    1
                    Connect
                
    End If
        
    End Select
    End Sub
    Please Advice

    Thanks-
    Pokhraj Das
     
  3. tigrot

    tigrot Well-Known Member Licensed User

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice