B4R Question How to receive the data at node.js

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

  1. pokhraj_d

    pokhraj_d Member

    Hello @Erel,
    I have one issue regarding sending of data from b4r end.
    I am able o connect successfully from B4r and the program connecting successfully.
    Now I want to read the data [String format] at node.js end. But I am not able to resolve the issue and node.js end.

    My b4r program log as follows:

    Code:
    ********************* PROGRAM STARTING ****************
    AppStart
    Connect State: 
    1
    ****************
    AT+CIPSHUT
    SHUT OK
    AT+CIPSHUT
    SHUT OK
    Connect State: 
    2
    ****************
    AT+CIPMUX=
    0
    OK
    AT+CIPMUX=
    0
    OK
    Connect State: 
    3
    ****************
    AT+CSTT=
    "airtelgprs.com"
    OK
    AT+CSTT=
    "airtelgprs.com"
    OK
    Connect State: 
    4
    ****************
    AT+CIPSTATUS
    OK
    STATE: IP START
    AT+CIPSTATUS
    OK
    STATE: IP START
    Connect State: 
    5
    ****************
    AT+CIICR
    AT+CIICR
    ****************
    OK
    OK
    Connect State: 
    6
    ****************
    AT+CIPSTATUS
    OK
    STATE: IP GPRSACT
    AT+CIPSTATUS
    OK
    STATE: IP GPRSACT
    Connect State: 
    7
    ****************
    AT+CIFSR
    100.121.191.128
    Connect State: 
    8
    ****************
    AT+CIPSTATUS
    OK
    STATE: IP STATUS
    AT+CIPSTATUS
    OK
    STATE: IP STATUS
    Connect State: 
    9
    ****************
    AT+CIPSTART=
    "TCP","35.185.167.108","80"
    OK
    AT+CIPSTART=
    "TCP","35.185.167.108","80"
    OK
    ****************
    CONNECT OK
    Connected!!!
    ****************
    AT+CIPSEND
    >
    Sending data
    ****************
    POST / HTTP/
    1.0
    Host: 
    35.185.167.108
    Content-
    Type: applicationtent-Length: 5
    11.12
    ****************
    SEND OK
    HTTP/
    1.1 302 Found  <<<--- Why this Error is coming
    Cache-Control: no-cache
    Content-
    5.167.108/
    Connection: close
    ****************
    CLOSED
    ****************
    Not sure why the below error is coming:
    =============
    HTTP/1.1 302 Found
    Cache-Control: no-cache
    Content-5.167.108/
    Connection: close
    =================

    Code:
    ********************APP Module**************
    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="35.185.167.108"
        
    Private mytemp As String="11.12"
        
    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:
    *************Part of GSM Module************
    Private Sub ReadyToSend
        
    Log("Sending data")
        ServerResponse = 
    True
        astream.Write(
    "POST ").Write("/").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: Keep-Alive").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
    Could you please advice on this please?

    Thanks-
    Pokhraj Das
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Please don't limit your questions to a single member.

    This means that that server tried to redirect the client to a different url. The new url should be included in the response.

    Try to make the request with rHttpUtils2 and ESP8266. rHttpUtils2 supports redirections.
     
  3. pokhraj_d

    pokhraj_d Member

    Hello,
    I am not using the wifi module ESP8266. Instead I am using GSM SIM 800L module. I want to send the to remote cloud server using GSM wirelessly, as all my sensors are at remote location where ESP8266 will not a solution.
    I am using POST method to send the data to the server. It is connecting the server successfully. But not able to send the value to php file.

    Am I doing any syntax mistake at the GSM module? Can anyone advice.
    Below is GSM module code from where I am trying to send the POST request

    Code:
    Private Sub ReadyToSend
        
    'Log("Sending data")
        ServerResponse = True
        astream.Write(
    "POST ").Write("/abc.php").Write("?").Write("temp=").Write(GlobalStore.Slot0).Write(" HTTP/1.1").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/x-www-form-urlencoded").Write(EOL)
        astream.Write(
    "Connection: Keep-Alive").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
    A part of logfile after successful connection:
    =======================================
    AT+CIPSTART="TCP","35.201.217.225","8080"
    OK
    CONNECT OK
    Connected!!!
    AT+CIPSEND
    >
    POST /abc.php?temp=11.12 HTTP/1.1
    Host: 35.201.217.225
    Content-oded
    Connection: Keep-Alive
    Conten
    t-Length: 5
    SEND OK
    CLOSED

    Thanks-
    Pokhraj Das
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    I understand. It will be simpler to remove GSM for now and focus on the http request.

    As I wrote, a response of 302 means that the server wanted to redirect the client.
     
  5. pokhraj_d

    pokhraj_d Member

    Thanks @Erel ..
    I have removed GSM and connect by using ESP8266. Able to connect the same and using rHTTPUtils2 for the request.
    Now what I will do when I will use GSM module. Any pointer? Please advice.

    Also need your advice about mqtt. If I will connect by using GSM to cloudmqtt I am able to connect successfully.
    Now how do I initialize the mqtt client for publish the message to the broker as initialize2 required ("Client.stream", useid, pwd etc).
    How to define "Client.stream" as here at every example ethernet shield has been used. Any particular tweak required or GSM?

    Thanks-
    POkhraj Das
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    What happens? Does it make a second request to the redirected url?
     
  7. embedded

    embedded Member Licensed User

  8. pokhraj_d

    pokhraj_d Member

    @Erel , It is working absolutely fine..... No re-direction happened [302 not coming]....Now working on GSM part...
    @embedded ... Happy Durga Puja buddy....:)

    Thanks-
    Pokhraj Das
     
    Erel likes this.
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