I'm stumped with sending data to a remote server , I'm able to send a post request but not sure how to add data which is then received by the server.
I've went through the datasheet http://www.jarzebski.pl/datasheets/SIM900_https-121018-1.00.pdf
tried
# usual at+sapbr=1,1 set up
+HTTPINIT
+HTTPPARA = “CID”,1
+HTTPPARA="URL","IP-ADDRESS:PORT"
+httpdata=100,10000
# Where do I add the post data ?
+httpaction=1
which sends the http post request. But how do I add data - I've tried adding it to the url ?key=val but no joy - any help here will be appreciated
httpdata=100,10000 means that SIM800 should expect 100 bytes within 10 seconds.
This is how I accomplished this using the HTTP client:
AT+HTTPINIT
AT+HTTPPARA="CID",1
AT+HTTPPARA="URL","http://url.com/endPoint"
AT+HTTPPARA="CONTENT","application/json"
AT+HTTPDATA=40,10000
At this point, the SIM800 should respond with "DOWNLOAD". Which means it's expecting your data. Send in your data; in my case:
{"location_id": 238, "fill_percent": 90}
Wait 10 seconds to send the rest of the commands. Then:
AT+HTTPACTION=1
AT+HTTPREAD
AT+HTTPTERM
That did it for me. Hope it helps.
This is where I got the information from: http://www.raviyp.com/embedded/194-sim900-gprs-http-at-commands
In the backend, using Python Flask, this is the code I used
#app.route('/reportTrashLevel', methods=['POST'])
def report_trash_level():
data = request.get_json()
database.insert_trash_level(data)
return Response(status=200)
I managed to get it to do what I need, this code-snippet will likely help others
AT+CGATT=1 # enter GPRS configuration mode
AT+CIPMUX=0 # Disable multi IP connection mode. Single IP cnxn only
AT+CSTT="APN","USER","PASS"
AT+CIICR # bring up wireless connection with GPRS and CSD
AT+CIFSR # ip up - gprs working
AT+CIPSHUT # Exit GPRS configuration mode
# Now do a post request to remote server api in json format.
# Change IP_ADDR|DOMAIN for the IP or domain name of your server.
# Change 2000 to its port
AT+CIPSTART="TCP","IP_ADDR|DOMAIN","2000"
AT+CIPSEND=119 # Num of char in tcp/ip data, \r & \n count as 1 char
POST /post HTTP/1.1
Host: **.**.***.***
Content-Type: application/json
Content-Length:23
{"postkey":"postvalue"}
Hope this helps the next person stuck on it.
Related
I sent a HTTP Raw request default with a host and port which I'm certain that I could connect using my windows 10 device.(Tested with Test-NetConnection and sent data via Ubuntu App, echo "DEMO Message" | nc mYHOST 6021)
However, when I sent the request in Jmeter , I get below errors.
Sampler result is as per the below.
Thread Name:Thread Group 1-1
Sample Start:2021-09-17 15:55:08 IST
Load time:9300
Connect Time:0
Latency:0
Size in bytes:921
Sent bytes:0
Headers size in bytes:0
Body size in bytes:921
Sample Count:1
Error Count:1
Data type ("text"|"bin"|""):text
Response code:500
Response message:java.net.SocketTimeoutException: Timeout exceeded while reading from socket
SampleResult fields:
ContentType:
DataEncoding: null
Response is as per the below.
java.net.SocketTimeoutException: Timeout exceeded while reading from socket
java.net.SocketTimeoutException: Timeout exceeded while reading from socket
at kg.apc.io.SocketChannelWithTimeouts.read(SocketChannelWithTimeouts.java:133)
at kg.apc.jmeter.samplers.HTTPRawSampler.readResponse(HTTPRawSampler.java:64)
at kg.apc.jmeter.samplers.HTTPRawSampler.processIO(HTTPRawSampler.java:163)
at kg.apc.jmeter.samplers.AbstractIPSampler.sample(AbstractIPSampler.java:112)
at kg.apc.jmeter.samplers.HTTPRawSampler.sample(HTTPRawSampler.java:42)
at org.apache.jmeter.threads.JMeterThread.doSampling(JMeterThread.java:630)
at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:558)
at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:489)
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:256)
at java.base/java.lang.Thread.run(Thread.java:830)
This demo host and port is working though and I used exact same in my real request too.
Similar issues come when I use JSR223 Sampler with below code.
def client = new Socket('DemoHostname', 9000);
client.setSoTimeout(2000);
client << "Hello ";
client.withStreams { input, output ->
def reader = input.newReader()
def response = reader.readLine()
log.info('Response = ' + response)
}
client.close()
Also with TCP Sampler of Jmter.
So based on the suggestion, I sent it as a Http request to websocket of Logstash.
Good thing is add the record get added, but Jmter http request is running in an endless state. Seems since logstash communicate via TCP it's unable to provide a http response.
What are you trying to achieve by sending HELLO TEST to echo.websocket.org?
If you want to send a HTTP Request there, you need to do something like:
GET / HTTP/1.1
Host: echo.websocket.org
Connection: close
Demo:
If you need to load test a WebSocket server - you're using the wrong plugin, you should go for JMeter WebSocket Samplers instead and consider using more "alive" endpoint as this echo.websocket.org doesn't seem to be working anymore.
I have a Telit HE910 cellular modem communicating over UART to AVR. I am issuing the AT command for HTTP GET to a server. According to the modem datasheet, I should get three carrots (<<<) and then the data stream from the server. I get the three carrots but no data. The HTTP response code is 200 (ok) with a content length of 0. On the server side, I am logging the request so I can verify the GET request is hitting the server. So on both the server and the modem, I get OK's but no data. I can perform a GET request to the server from another web page and it works fine. Does anyone have any ideas of what could cause this?
PHP page is just echoing strings out on the request. For example
<php?
header('Content-type: text/plain');
echo 'Test';
?>
AVR / Modem code
sprintf(buf, "#HTTPCFG=0,\"%s\",80,0,,,0,120,1", host);
AT_ASSERT(AT_OK == AT_SendCommand(buf, response));
sprintf(buf, "#HTTPQRY=%d,%d,%s%c",
get_profile(),
0,
page,
CR);
AT_ASSERT(AT_OK == AT_SendCommand(buf, response));
sprintf(buf, "AT#HTTPRCV=0%c", CR);
UART0_TxString(buf);
c = UART0_RxChar();
response[0]=c;
i=0;
while((c=UART0_RxChar()) != CR)
{
response[i++]=c;
}
UART1_Flush();
UART1_Printf("received: %s\n", response);
Response in Terminal
received:
<<<
HTTP POST Complete
There should be data behind the <<< according to datasheet
Okay, it turns out that nothing was wrong with the C code on the AVR. I found a test server for HTTP GET request and tested the module successfully on a that site. So the underlying issue is with the PHP file in responding to the HTTP GET request.
I'm trying to use the Telit GE910 cell module to make HTTP requests over the cell network. I've connected it via a FTDI board to my computer's USB port and am sending it AT commands via the terminal. I'm using the AT commands to successfully open a socket in command mode and send the HTTP request.
AT#SD=1,0,80,"google.com",0,0,1
OK
�AT#SSEND=1
> HE�AD� /� HTT�P/1.1
OK
SRING: 1
I don't understand why these � are turning up. When making requests for google.com this is fine but anything hosted on Heroku gives me a 505 error.
HTTP/1.1 505 HTTP Version Not Supported
Connection: close
Server: Cowboy
Date: Tue, 26 Apr 2016 20:39:34 GMT
Content-Length: 0
I've read in one or two forums that this 505 response is specific to Heroku and has to do with incorrect spacing in the HTTP request. I suspect the unrecognized characters are creating the problem. What is going on? They consistently turn up before 'A', 'space', and 'P'; there may be other letters also but those are the ones that I've seen.
Ok, I have figured out (I think) why I was getting a 505 response. Then I started getting a 400, but I figured that out too!
In the application note for socket dials from Nimbelink (which is a vendor that uses the Telit cell modules--I have one of their modules which has the Telit GE910 on it) it says that after you enter your HTTP request (e.g. GET / HTTP/1.1) you're meant to hit ctrl+j twice to signal the end of the request.
Well, I started doing all of my serial communication in CoolTerm so that I could see the HEX I was sending. (My hope was I could catch the � characters--I didn't, in fact they don't turn up in CoolTerm.) ctrl+j results in a single line feed (HEX: 0A). According to HTTP documentation, to signal the end of a line you're meant to use carriage return line feed (HEX: 0D 0A). (Heroku also says it has to be formatted like this.) This is what I send when I hit enter. So if I end GET / HTTP/1.1 with enter twice, the request gets though. Though even a HEAD / HTTP/1.1 request to heroku.com comes back as a 400. But that's up next:
According to RFC (which I found out here) HTTP 1.1 requires a Host. So if I do the whole thing with the right line endings
GET / HTTP/1.1
Host: heroku.com
it works! It also works for posting to my server.
AT+CSTT="live.vodafone.com"$0D$0A OK
AT+CIPSHUT$0D$0A SHUT OK
AT+CIPMUX=0$0D$0A OK
AT+CLPORT="TCP",80$0D$0A OK
AT+CIICR$0D$0A OK
AT+CIPSTART="TCP","http://ph.mydomain.in",80$0D$0A OK CONNECT OK
AT+CIPSEND$0D$0A
GET /phreading.aspx?value=092016040804550815 HTTP/1.1$0D$0A
Host: http://www.ph.mydomain.in$0D$0A$0D$0A
$1A
than i get following error.
Please help me to solve this problem. and tell me the right sequence to send data on server correctly.
Try to use AT+HTTPPARA command to send your get request. Its much easier than using the CIPSEND method.
Connect to GPRS
AT+CGATT?
AT+SAPBR=3,1,"CONTYPE","GPRS"
AT+SAPBR=3,1,"APN","live.vodafone.com"
AT+SAPBR=3,1,"USER","APN_USERNAME" // adapt it to yours
AT+SAPBR=3,1,"PWD","APN_PASSWORD" // adapt it to yours
AT+SAPBR=1,1
SEND DATA USING HTTP GET
AT+HTTPINIT
AT+HTTPPARA="CID",1
AT+HTTPPARA="URL","www.ph.mydomain.in//phreading.aspx?value=092016040804550815"
AT+HTTPACTION=0 // sends HTTP GET
AT+HTTPTERM // terminate HTTP request
AT+SAPBR=0,1 // disconnect gprs if required
Hope this helps..
Using SIM 900 :
AT+HTTPINIT
AT+HTTPPARA="CID",1
AT+HTTPPARA="URL","www.onewebsite.fr"
AT+HTTPDATA=lengthofpostdata, 10000
sending data
AT+HTTPACTION=1
AT_HTTPREAD=0, lengthofreceiveddata
Up to that point everything works OK
Then i send a new request :
AT+HTTPPARA="CID",1
AT+HTTPPARA="URL","www.onewebsite.fr"
AT+HTTPDATA=lengthofpostdata, 10000
sending data
AT+HTTPACTION=1
Then I received the message : +HTTPACTION=1,601,0
Any idea ?
601 is some custom implemented Error code, as an example
This is a "magic" status code that we use to signal that something wrong happened with the request that was so bad that we didn't even got a response back from the server. In this case the request timed out (more than 30 seconds to return any bytes).
source
Here is the list of standard HTTP Status codes
At times you would get this error if you are sending requests too often as well! try to increase the delay between the two requests!
. +HTTPACTION:0,601,0
The above AT response code (601) for HTTP session start indicates that
there is a network error. Then make sure that the PDP context is setup
properly.
source
I faced this problem and the solution is to open the bearer again before the second request.
Use
AT+SAPBR=1,1https://stackoverflow.com/questions
Some steps I have found to work:
Use the Adafruit FONA library if possible
Before every HTTP request check whether GPRS is enabled
If GPRS is enabled, check whether you have been assigned an IP Address
If 2 and 3 are true, proceed to make the HTTP request. If not, try to reconnect to GPRS until 2 and 3 are true