B4R Question How to receive the data at node.js

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:

B4X:
********************* 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
=================

B4X:
********************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

B4X:
*************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, 0, 0)).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
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Please don't limit your questions to a single member.

HTTP/1.1 302 Found
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.
 
Upvote 0

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

B4X:
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, 0, 0)).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
 
Upvote 0

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
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…