Arduino ESP8266 does not receive all data from HTTP server - nginx

I am using arduino and esp8266 to interact with my HTTP server(Nginx+flask). I have already successful sent the request to server, however, while I checked the message esp8266 received, the esp8266 did not get all data from server.
The supposed result should be:
+IPD,179:HTTP/1.1 200 OK
Server: nginx/1.1.19
Date: Sat, 02 Jan 2010 00:11:02 GMT
Content-Type: application/json
Content-Length: 25
Connection: keep-alive
{
"status": "SUCCESS"
}
and currently the result I got is:
+IPD,179:HTTP/1.1 200 OK
Server: nginx/1.1.19
Date: Sat,
The stream I sent to the ESP8266 module:
AT+CWMODE=1
AT+CWJAP="Telstra1357_2.4G","adelaide12345"
AT+CIPMUX=0
AT+CIPSTART="TCP","192.168.0.6",80
AT+CIPSEND=217 POST /data/push/ HTTP/1.1
Host: 192.168.0.6
User-Agent: Sensor Station
Content-Type: application/json
Content-Length: 89
{"device_id":0,"data":[{"label":"Light","reading":606}, {"label":"Motion","reading":497}]} `
I have tried to use timeout/delay to wait for more data, but it didnt work.
Anyone has same problem?

I had similar prolems! For me it helped checking the baud rate. I connected the ESP8266 with SoftwareSerial but the ESP worked on 115200 which is too high for SoftwareSerial. I changed the baud rate with AT+UART_DEF=9600,8,1,0,0 to 9600 and then it worked fine! You need to check your firmware to get the right AT- command.
Check your power supply (external power is most suitable) and send an CLOSE-command. It might help!

Related

Arduino Esp8266 Response Timeout

I'm trying to test sending HTTP requests from my Arduino. I decided to use Free RESTful web service - http://services.groupkt.com. But something goes wrong and I don't understand what.
GET request:
GET /country/get/all HTTP/1.1
Host: 45.79.172.152
Connection: keep-alive
Serial Monitor:
AT+CIPMUX=0
OK
AT+CIPSTART="TCP","45.79.172.152",80
CONNECT
OK
AT+CIPSEND=74
OK
>
busy s...
Recv 74 bytes
SEND OK
+IPD,493:HTTP/1.1 408 Request Timeout
Date: Thu, 07 Jun 2018 16:10:59 GMT
Server: Apache/2.4.25 (Debian)
Content-Length: 307
Connection: close
Content-Type: text/html; charset=iso-8859-1
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>408 Request Timeout</title>
</head><body>
<h1>Request Timeout</h1>
<p>Server timeout waiting for the HTTP request from the client.</p>
<hr>
<address>Apache/2.4.25 (Debian) Server at services.groupkt.com Port 80</address>
</body></html>
CLOSED
What I'm doing wrong?
HTTP is not like Telnet. You can't enter a HTTP request line by line in Serial Monitor.
HTTP requests are meant to be sent by a program and the timeout to receive the
complete request on servers is one or two seconds. Write a sketch the sends the request.

UPNP M-SEARCH response does not yield a HTTP GET request. Why?

I am trying to create a MediaServer UPNP program in order to stream video from my phones camera to my PC.
I used Intel device spy to send an M-SEARCH request and used Wireshark to capture the network packets.
Here is the M-SEARCH packet
(Src: 192.168.1.28, Dst: 239.255.255.250; Src Port: 50852, Dst Port: 1900, time 2.09)
M-SEARCH * HTTP/1.1
ST: upnp:rootdevice
MAN: "ssdp:discover"
MX: 5
HOST: 239.255.255.250:1900
Here is the UDP reply
(Src: 192.168.1.23, Dst: 192.168.1.28; Src Port: 53359, Dst Port: 50852)
HTTP/1.1 200 OK
CACHE-CONTROL: max-age=1810
DATE: Wed, 1 Feb 2017 02:07:36 GMT
EXT:
LOCATION: http://192.168.1.23:49156/details.xml
SERVER: Linux/2.x.x, UPnP/1.0, pvConnect UPnP SDK/1.0, TwonkyMedia UPnP SDK/1.1
ST: upnp:rootdevice
USN: uuid:3d64febc-ae6a-4584-853a-85368ca80800::upnp:rootdevice
Content-Length: 0
I do not get a following HTTP GET request to 192.168.1.23. I compared it to other UPNP device responses that worked and could see no difference.
I tried different source ports but with no sucess. Any ideas?
#simonc, Thank you. I did have a \r\n at the end of my message, but I added another one (to the NOTIFY message as well) and now I can see my device.

POST api Rest with AT Commands - SIM800

I'm having problems sending post parameters over a SIM800 module using AT. For while I'm using FTDI and mac screen application terminal.
Here is my command sequence:
AT+HTTPINIT
AT+HTTPPARA="CID",1
AT+HTTPPARA="URL","myhost/deviceRegister"
AT+HTTPPARA="CONTENT","application/json"
AT+HTTPDATA=94,120000
OK
DOWNLOAD
POST deviceRegister HTTP/1.1
Host: myhost
Content-Length:13
{"IMEI":"aa"}
AT+HTTPACTION=1
AT+HTTPREAD
Until here, everything looks fine, but when I log my post request in my server what I have is this:
+HTTPREAD: 259
POST deviceRegister HTTP/1.1
Host: myhost
Accept: */*
Connection: Keep-Alive
Content-Type: application/json
User-Agent: SIMCOM_MODULE
Content-Length: 94
{"IMEI":"aa"}gister HTTP/1.1
OK
It looks like it is posting to the body without \n
Why my post body has headers parameters ?
That s what i tried on my sim900 modem
{"myvar1="myvalue1","myvar2"="myvalue2"} is my json object
AT+CGATT?
AT+SAPBR=3,1,"CONTYPE","GPRS"
AT+SAPBR=3,1,"APN","mynetworkprovider.com"
AT+SAPBR=3,1,"USER","mylogin"
AT+SAPBR=3,1,"PWD","mypassword"
AT+SAPBR=1,1
AT+HTTPINIT
AT+HTTPPARA="CID",1
AT+HTTPPARA="URL","http://myserveraddress/comm.php"
AT+HTTPPARA="CONTENT","application/json"
AT+HTTPDATA=137,5000 **=>SIM response : DOWNLOAD**
Content-Length: 414
{"myvar1="myvalue1","myvar2"="myvalue2"}
AT+HTTPACTION=1
AT+HTTPREAD =>should respond 200 http ok status
hth
I m not an expert but on my sim900 modem i tried this and it works for me
AT commands to initialize Modem for data transfert
and
AT+HTTPINIT
AT+HTTPPARA="CID",1
AT+HTTPPARA="URL","myhost/deviceRegister"
AT+HTTPPARA="CONTENT","application/json"
AT+HTTPDATA=94,120000
OK
DOWNLOAD
Content-Length:13
{"IMEI":"aa"}
AT+HTTPACTION=1
AT+HTTPREAD
Hope this help

What's wrong with this HTTP request?

I am sending the following HTTP request:
POST /input/8dZ8bgapvjfYzmwWno6W.txt HTTP/1.1
Host: data.sparkfun.com
Phant-Private-Key: pz5ga4pkydHgpEb8v608
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 7
temp=44
In my code, I am sending it using UART tx requests to the xbee module, for which the translates to:
POST /input/8dZ8bgapvjfYzmwWno6Wr.txt HTTP/1.1\r\n
Host: data.sparkfun.com\r\n
Phant-Private-Key: pz5ga4pkydHgpEb8v608\r\n
Connection: close\r\n
Content-Type: application/x-www-form-urlencoded\r\n
Content-Length: 7\r\n
\r\n
temp=44
This is to communicate to the phant dataserver at data.sparkfun.com, and it responds with the following data:
HTTP/1.0 400 Bad request
Cache-Control: no-cache
Connection: close
Content-Type: text/html
<html><body><h1>400 Bad request</h1>
Your browser sent an invalid request.
</body></html>
I found the answer:
The packet is correct.
While configuring the Xbee Wifi module using XCTU, I had to give the correct port numbers of the server and client Xbee, which were wrong.
Server was 80, client was any port I think.

403 Forbidden from xively api SIM900 shield

I use SIM900 shield with arduino UNO. I try to make conection with xively server. I follow the instructions from: http://arduino.cc/en/Tutorial/GSMExamplesXivelyClient?from=Tutorial.GSMExamplesPachubeClient
This example is for other GSM shield, but it show me how should look like conection with xively. I've made such code:
gsm.SimpleWrite("PUT /v2/feeds/");
gsm.SimpleWrite(1055165076);
gsm.SimpleWriteln(".csv HTTP/1.1");
gsm.SimpleWrite("Host: api.xively.com\n");
gsm.SimpleWrite("X-ApiKey: ");
gsm.SimpleWriteln("j2AlGTCLxJzArQhL7dqrLYG6BtJd5aI8LoJmc7ha0mgsPWPD");
//gsm.SimpleWrite("User-Agent: ");
//gsm.SimpleWrite(arduino);
gsm.SimpleWrite("Content-Length: ");
gsm.SimpleWriteln(10);
gsm.SimpleWrite("Content-Type: text/csv\n");
gsm.SimpleWriteln("Connection: close");
gsm.SimpleWriteln("");
gsm.SimpleWrite("sensor1,");
gsm.SimpleWriteln(16);
gsm.SimpleWrite(end_c);
By this code I would like to send sensor1 value : 16.
After execution of this code xively server make my some answer:
HTTP/1.1 403 Forbidden
Date: Mon, 25 Nov 2013 08:19:27 GMT
Content-Type: text/plain; charset=utf-8
Transfer-Encoding: chunkd
oncin ls
4
Yud o aetencesr emsin oacs hsrsuc
On web https://xively.com/dev/docs/api/communicating/http/http_status_codes/ i found that error mean:
403 Forbidden Xively understands your request, but refuses to fulfil it. An accompanying error message should explain why.(NOTE: in the V2 API, this is the error returned when the API rate limit is exceeded.)
If I change for example API-KEY, server give me 404 error. I'm trying to solve this problem for several days. Maybe someone has an idea what is wrong?
Try to add "Accept: */*"
I believe your Content-Length should be 11 (including newline).

Resources