Comments (8)
Are you sending the "Content-Length" parameter in your POST message with the length of the JSON?
from wifiesp.
Yes! This is the code:
...
char server[] = "api.sendgrid.com";
...
Serial.println("Starting connection to server...");
if (client.connect(server, 443)) {
Serial.println("Connected to server");
String data = "{\"personalizations\": [{\"to\": [{\"email\": \"*****.*****@gmail.com\"}]}],\"from\": {\"email\": \"*****@*****.com.br\"},\"subject\": \"Alerta de temperatura\",\"content\": [{\"type\": \"text/plain\", \"value\": \"Temperatura 30,1C\"}]}";
Serial.println(data);
Serial.println(String(data.length()));
client.println("POST /v3/mail/send HTTP/1.1");
client.println("Host: api.sendgrid.com:443");
client.println("Authorization: Bearer SG.******************************************************************");
client.println("Content-Type: application/json");
client.println("Connection: keep-alive");
client.println("Content-Length: " + String(data.length()));
client.println(data);
client.println();
}
There is no error at the Serial Monitor.
This is the debug output (Level 4):
21:58:09.167 -> SEND OK
21:58:09.167 -> > getClientState 3
21:58:09.199 -> ----------------------------------------------
21:58:09.262 -> >> AT+CIPSTATUS21:58:09.262 ->
21:58:09.262 -> +IPD,3,452,3.64.200.27,443:HTTP/1.1 400 Bad Request
21:58:09.326 -> Server: nginx
21:58:09.358 -> Date: Sat, 30 Jul 2022 20:58:09 GMT
21:58:09.390 -> Content-Type: text/html
21:58:09.423 -> Content-Length: 248
21:58:09.423 -> Connection: close
21:58:09.456 -> Strict-Transport-Security: max-age=600; includeSubDomains
21:58:09.519 ->
21:58:09.519 -> <html>
21:58:09.519 -> <head><title>400 The plain HTTP request was sent to HTTPS port</title></head>
21:58:09.616 -> <body>
21:58:09.616 -> <center><h1>400 Bad Request</h1></center>
21:58:09.647 -> <center>The plain HTTP request was sent to HTTPS port</center>
21:58:09.713 -> <hr><center>nginx</center>
21:58:09.744 -> </body>
21:58:09.744 -> </html>
21:58:09.777 -> STATUS:3
21:58:09.777 -> +CIPSTATUS:3,"TCP","3.64.200.27",443,45897,0
I appreciate any help
Thanks
from wifiesp.
I think the problem is that you are making a post to a 443 port. This port is used for HTTPS connections and you are doing a standard HTTP.
In order to use HTTPS, I believe you need to have a certificate installed on your device. It is something that I never did so I can't help you with that.
You said that for a shorter message it works ยฟAre you sure that the only difference is the length of the message?
from wifiesp.
The situation is now a little different after I figured out how to see the full log at level 4.
I've noticed that it doesn't work even with short messages either.
I'll change the title of this issue to "WiFiEsp: Send Post message from Arduino Mega + ESP-01 issue."
from wifiesp.
add an empty line between headers and the data. it is required by the http protocol. your error is "bad request" as you can see.
from wifiesp.
I made some changes:
- Tip from fscheu: client.connectSSL(server, 443);
- Tip from JAndrassy's suggestion: Added an empty line between header and data.
Now the code is:
char server[] = "api.sendgrid.com";
...
if (client.connectSSL(server, 443)) {
Serial.println("Connected to server");
String data = "{\"personalizations\": [{\"to\": [{\"email\": \"********.*****@gmail.com\"}]}],\"from\": {\"email\": \"*******@*****.com.br\"},\"subject\": \"Alerta de temperatura\",\"content\": [{\"type\": \"text/plain\", \"value\": \"Temperatura 30,1C\"}]}";
Serial.println(data);
Serial.println(String(data.length()));
client.println("POST /v3/mail/send HTTP/1.1");
client.println("Host: api.sendgrid.com:443");
client.println("Authorization: Bearer SG.******************************************************************");
client.println("Content-Type: application/json");
client.println("Connection: keep-alive");
client.println("Content-Length: " + String(data.length()));
client.println();
client.println(data);
}
...
And this is the Debug output:
10:22:48.221 -> Starting connection to server...
10:22:48.254 -> [WiFiEsp] Connecting to api.sendgrid.com
10:22:48.286 -> > startClient api.sendgrid.com 443
10:22:48.351 -> ----------------------------------------------
10:22:48.383 -> >> AT+CIPSSLSIZE=4096
10:22:48.416 ->
10:22:48.416 -> OK
10:22:48.416 -> ---------------------------------------------- > 0
10:22:48.480 ->
10:22:48.480 -> ----------------------------------------------
10:22:48.513 -> >> AT+CIPSTART=3,"SSL","api.sendgrid.com",443
10:22:48.842 ->
10:22:48.842 -> ERROR
10:22:48.842 -> ---------------------------------------------- > 1
10:22:48.874 ->
10:22:48.906 -> > getClientState 3
10:22:48.906 -> ,CLOSED
10:22:48.906 ->
10:22:48.939 -> Dirty characters in the serial buffer! > 10
10:22:48.972 -> ----------------------------------------------
10:22:49.004 -> >> AT+CIPSTATUS
10:22:49.035 -> STATUS:4
10:22:49.035 ->
10:22:49.035 -> OK
10:22:49.068 -> No start tag found: 0
10:22:49.068 -> ---------------------------------------------- >
10:22:49.132 ->
10:22:49.132 -> Not connected
10:22:49.165 ->
10:22:49.165 -> Disconnecting from server...
from wifiesp.
it is not able to connect. the site uses TLS 1.2. the AT firmware doesn't support TLS 1.2.
there is a 'fake' AT firmware which supports TLS 1.2
https://github.com/JiriBilek/ESP_ATMod
and it is better with my WiFiEspAT library
from wifiesp.
I just found an article on how to update the ESP-01 firmware...
I'll need to buy an adapter for this...
As soon as I have the adapter and have done the update I will come back here.
Thanks
from wifiesp.
Related Issues (20)
- How can I get data? HOT 5
- consumption time of an API (600ms) HOT 30
- UDP->remotePort() returns incorrect value HOT 3
- UDP link is not valid HOT 4
- REST API Post request to microsoft power bi real time data set HOT 1
- ESP8266 Crashes After UDP Packet Overload HOT 2
- ESP-Now with WiFiEsp library on ESP8266-01 interfaced to Arduino Uno HOT 2
- Connect to Firebase Database using WiFiESP
- The use of Delay() HOT 10
- TIMEOUT in same position every time on large HTTP header HOT 2
- RingBuffer namespace collision with other libraries
- WebClient example doesn't work anymore
- Invalid "ClientSSL " connection directive HOT 5
- DDNS HOT 1
- Problem with the WebClientSSL example
- Can someone help with TMRpcm.h conflict HOT 1
- UDP + WiFiEspServer
- Async web client HOT 6
- Hardware serial tutorial needed !! Help !! HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wifiesp.