-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Help with HTTPS #784
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
When there is no character to be read, client.read() returns -1, which is then converted to a character by Serial.write. This results in a character with ASCII code of 255, which may look like ÿ depending on the terminal. You might want to check if There may be other issues, but this one is the most obvious. Edit: perhaps you are not getting the reply because the server is expecting two more characters?
And then you send just |
Ah ok, i should have known that. But i did have the client.available() check before and then it just hangs never getting back a response. Trying again now adding this code after the Serial.println("Receiving response") then it just sits forever printing out dots:
|
What happens if you change Content-Length header to match the real size of content? |
your header lineending need to be \r\n look in the http RFC for more info |
Something like this?
Still just dots and no response comes back. |
You still seem to be missing an empty line after the headers (see the |
Ok, rearranging to be more closely like the original example:
but still just dots and no response. |
Now i've tried running tcpmon on a local computer with a local non-ssl http port being forwarded to www.btopenzone.com port 8443 as SSL, and then changing the esp sketch to use WiFiClient instead of WiFiClientSecure and to use the tcpmon host address, but the rest of the sketch unchanged. |
Correct, if the same POST request works with WiFiClient then it's likely a bug in WiFiClientSecure. |
at every print you send a tcp package some servers dont like this. you also shut have "\r\n\r\n" before postData or the server will interpreter it as invalidate request. |
Getting a bit further...i think there might be a bug in WifiClientSecure - it looks like after sending the request client.available() is always returning 0 even when a response has come back, but doing client.readStringUntil('\n') does return the first line, and then client.available() starts working properly. You can see this by modifying the HTTPSRequest sample to have a while loop printing client.available() before and after the client.readStringUntil call. So accounting for that i can get the https POST to work ok, yipee! Unfortunately it still doesn't work for what i want, which is trying to have the ESP logon to a FON Wifi network. Not really for this git issue but i wonder if it needs to have two connections, one for the https connection which is kept open and another to do the other http requests on - can the esp do multiple client connections? |
yes up to 5 TCP and 4 UDP connections at one time.
|
Ok thanks for confirming that. Doing some debugging with netstat on a pc i don't think it uses multiple connections anyway. Not sure how it works, in case anyone has any suggestions here's what happens: There are lots of FON access points named (in the UK) BTWifi-with-FON that are open with no security. So you connect to them and then if you try to use a browser then you can't connect to anything until you go to a FON web page with a form where you have to logon with a userid password, and then after that you're connected and all internet access works normally (for a short while after which you need to reenter the userid/password again). I traced the web page form and it just does a POST with the userid/password so now i can replicate the logon with a curl command instead of using the web page form: curl --data "username=qaz123%40btinternet.com&password=abc123&xhtmlLogon=https://www.btopenzone.com:8443/tbbLogon" https://www.btopenzone.com:8443/tbbLogon So i was hoping to replicate that on an ESP and do the https post and then be able to make other http connections to publish data. The https post seems to work fine and the headers and response the esp gets back look the same as what the curl command gets, but then further WifiClient requests on the ESP don't work and just fail to connect. I thought it might just be using the mac address against the userid/password or somehting like that but i guess there must be more to it. Any ideas? |
for me this looks like the FON access points runs a transparent proxy. |
It started working! Don't know what i did, just tidied the code up a bit i thought, but now it works ok. Very pleased. Thanks for all the help. Would be good to get the WifiClientSecure.available bug fixed though so i'll leave this open for that. |
Thanks for the fix, i can confirm it does fix it for me. |
Attempt to read data from SSL engine inside WiFiClientSecure::available() if RX buffer is empty. Fix #784.
Torntrousers, I would love to try out HTTPS request from ESP, could you tell me where can I download the WiFiClientSecure lib please? Thank you. |
You should install the staging version of the ESP8266-Arduino libraries using this URL for board manager in preferences: |
Thanks gicho, actually I already have HTTP working with ESP-12E board using this URL for board manager in preferences: http://arduino.esp8266.com/versions/1.6.5-1160-gef26c5f/package_esp8266com_index.json. Updated the ESP8266WIFI lib and the compiler is recognizing the WiFiClientSecure.h now. I ran the example above, it connected, certificate matches but the return file config.htm has 0 Bytes (File /config.htm 0 Bytes). Web Browser (https://raw.githubusercontent.com/sticilface/ESPmanager/Strings/examples/Settingsmanager-example/data/config.htm) return differently. Any idea? Thank you in advance. |
may its the same problem then here: its most likely the TLS fragment size that is to big. |
@Links2004 @gicho @torntrousers Can someone tell me if I can make HTTPS GET requests using ESP-01? Or is it only possible on the models with more memory? |
You can all esp8266 has the same ram size, only the flash is different.
|
Is there a fix for this ? I'm trying to connect to the below URL and getting the -1 as output or at times an empty string is passed to serial output. |
@sreeramtkd Yes ESP-01 works with SSL over http. Use the WifiClientSecure library here: WiFiClientSecure |
@electronicsguy I'm using the latest library but unfortunately I can't get esp8266 to pull https dataconnecting to Sree
|
@sreeramtkd Well the library does have some restrictions as @igrr has mentioned in the documentation for it. (like encryption type, max. certificate size, etc). But you need to post your code with a minimal example for others to check. |
Here is the code from library #include <ESP8266WiFi.h> const char* ssid = ""; const char* host = "api.apifier.com"; // Use web browser to view and copy void setup() { if (client.verify(fingerprint, host)) { |
also FYI i'm using an ESP8266 12-F module |
@sreeramtkd apifier works for me using HTTPSRedirect. Please check it out: This is what I get as the expected output: |
Hi, I'm trying to use the ESP-01 module+Mega conect to TX/RX 18 and 19 Pin but it doesn't work with ESP8266Wifi library. |
Hi, Going through various related posts I could get my Wemos to send and accept https requests. Chhers to the community for that !! :). I'd used the similar code as shared by @sreeramtkd above. For purpose of testing I'd used a free webhost(Heliohost) and used a LetsEncrypt SSL certificate and it worked smoothly. My end goal was to implement the same functionality on my local network where my Wemos/ESPs would communicate with a server running Nginx and communicate over https. I could setup the Nginx with a self signed certificate as instructed here. I did not wish to have any sorts of Internet connectivity from my local network, because of which I could not use the same LetsEncrypt certificate again. After setting up the Nginx, the Wemos is unable to connect to the server on port 443 using Https but can communicate with it over port 80. It gives a plain "connection failed". I could have moved ahead had the error been related to certifate, wrong fingerprint or something which happens after connection is established. But a refusal to connect keeps me hanging. Tried to skim through the source code but its probably over my limited knowledge. I have verified port 443 (for Https) to be open and accessible by browser clients on the network. Some inputs on troubleshooting please.
|
Hi #include <ESP8266WiFi.h> const char* ssid = "-----------"; const char* host = "35.187.233.153"; void setup() Serial.printf("Connecting to %s ", ssid); void loop() Serial.printf("\n[Connecting to %s ... ", host);
client.print("POST "); client.print("Connection: close\r\n");
} |
@AbdelsalamHaa - Would be nice to see the error / issue in specific, Use any of the available online client testing services to see if you are getting proper response from the server mentioned in code. https://www.hurl.it/ Or Postman Echo. This should allow you to debug issues. |
@sreeramtkd thanks for ur responds , I have actually found the problem which was in my request message format . |
AbdelsalamHaa, would you mind sharing your final code? Or does your Jan 27 post include final? Thanks, |
I'm in the same situation but with an Arduino UNO and ESP-01 with SoftwareSerial. |
@edugargon If you have a esp8266, what are you using Arduino for? Unless you need analog inputs, the arduino is unnecessary. |
You said, if I'm using Arduino, it's because I need analog inputs. |
I have the same problem right now. |
AFAIK this problem is not related to this repository. You can sort it out by flashing an AT firmware (from Espressif repository) to your ESP8266 board and use an Arduino library to communicate over serial (e.g. WifiEsp library). |
I'm trying to use the new https support but can't get it to work so wonder if someone could see what the problem is (sorry if this is leaping ahead, i know the https code hasn't been released yet). I've built the latest git code from today (1f8c14d) and started with the HTTPSRequest sample. That works ok (though does always seem to get a wdt reset after closing the connection), so i then changed it to do a GET to https://www.btopenzone.com:8443, and that worked ok too, so then updated it to try to do a POST to http://www.btopenzone.com:8443/tbbLogon but that doesn't work and all i get back is a stream of ÿ characters.
This is the code i have, can anyone see a problem?
As an alternative test this does work and returns an html page:
curl --data "username=qaz123%40btinternet.com&password=abc123&xhtmlLogon=https://www.btopenzone.com:8443/tbbLogon" https://www.btopenzone.com:8443/tbbLogon
The text was updated successfully, but these errors were encountered: