Full example of using libcurl with ESP32

User avatar
loboris
Posts: 514
Joined: Wed Dec 21, 2016 7:40 pm

Full example of using libcurl with ESP32

Postby loboris » Sun May 07, 2017 4:12 pm

The example source code can be found on GitHub:
https://github.com/loboris/ESP32_curl_example

Included are examples of using http/https GET & POST, ftp LIST, GET, PUT and sending EMAIL

The example uses wear leveling FAT file system and the latest esp-idf commit has to be used (5. May 2017 or later)

Included libGSM to test libCurl with GSM modems.
For more info on using GSM modules see viewtopic.php?f=17&t=1496


How to build

Configure your esp32 build environment as for other esp-idf examples

Clone the repository

Code: Select all

git clone https://github.com/loboris/ESP32_curl_example.git
Execute menuconfig and configure your Serial flash config and other settings. Included sdkconfig.defaults sets some defaults to be used. Custom partitions table is used!

Navigate to Curl Example Configuration and set your WiFi SSID and password, mail account user name and password, email recipient's mail address.
If using GSM module, configure GSM parameters.

If you want to enable mbedtsl debugging, navigate to Component config → mbedTLS and select Enable mbedTLS debugging

Code: Select all

make menuconfig
Edit testCurl() function in testCurl.c if you want to change some operating parameters.

Make and flash the example.

Code: Select all

make all && make flash
All servers used in the example are real working servers.
You can change them if you want to test the responses from your own server(s).

Example functions
  • print info about used libcurl version and supported features
  • test http GET method; sends some parameters and gets response
  • test http GET method; requests file and saves the file to file system
  • test http GET method; requests large file (~2.4 MB), simulates saving the file to file system
  • test https GET method; connects to https server using SSL, get the response
  • test http POST method; sends 4 parameters including 1 file; gets the response
  • test ftp LIST directory
  • test ftp GET text file; saves the file to the filesystem
  • test ftp GET binary file (JPG) to file system
  • test ftp PUT binary file from file system (uploads previously downloaded file under different name)
  • test sftp DOWNLOAD text file from ssh server; saves the file to the filesystem
  • test sftp UPLOAD jpg file to ssh server
  • test SMTP; sends email with attachment (attaches the jpg file downloaded from ftp server)
The sequence of operation is repeated after 30 second waiting.

If more than 5 consecutive errors are detected, the system is reseted.

While downloading, the files are stored on file system only if they don't already exists. If the file exists, writing to file is simulated. On restart all files on the file system are deleted.

Example output

Code: Select all

I (1760) cpu_start: Pro cpu start user code
I (1814) cpu_start: Starting scheduler on PRO CPU.
I (198) cpu_start: Starting scheduler on APP CPU.
I (212) [cURL Example]: Mounting FAT filesystem
I (215) [cURL Example]: ==============
I (215) [cURL Example]: FATFS mounted.
I (215) [cURL Example]: ==============

I (1219) wifi: wifi firmware version: 384bc4e
I (1219) wifi: config NVS flash: enabled
I (1219) wifi: config nano formating: disabled
I (1227) wifi: Init dynamic tx buffer num: 32
I (1227) wifi: Init dynamic rx buffer num: 32
I (1227) wifi: wifi driver task: 3ffc537c, prio:23, stack:3584
I (1231) wifi: Init static rx buffer num: 16
I (1235) wifi: Init dynamic rx buffer num: 32
I (1239) wifi: Init rx ampdu len mblock:7
I (1242) wifi: Init lldesc rx ampdu entry mblock:4
I (1247) wifi: wifi power manager task: 0x3ffccd24 prio: 21 stack: 2560
I (1253) wifi: wifi timer task: 3ffcddbc, prio:22, stack:3584
I (1275) phy: phy_version: 350, Mar 22 2017, 15:02:06, 1, 0
I (1276) wifi: mode : sta (24:0a:c4:00:97:c0)
I (1277) [cURL Example]: SYSTEM_EVENT_STA_START
I (1280) wifi: sleep disable
I (1400) wifi: n:1 0, o:1 0, ap:255 255, sta:1 0, prof:1
I (2058) wifi: state: init -> auth (b0)
I (2060) wifi: state: auth -> assoc (0)
I (2063) wifi: state: assoc -> run (10)
I (2098) wifi: connected with LoBoInternet, channel 1
I (2099) [cURL Example]: SYSTEM_EVENT_STA_CONNECTED
I (4212) event: ip: 192.168.0.16, mask: 255.255.255.0, gw: 192.168.0.1
I (4212) [cURL Example]: SYSTEM_EVENT_STA_GOT_IP
I (4214) [cURL Example]: got ip:192.168.0.16 ... ready to go!

Removing files on file system...
* removed "/spiflash/postpar.txt"
* removed "/spiflash/tiger.bmp"
* removed "/spiflash/tiger.jpg"

=========
cURL INFO
=========

Curl version info
  version: 7.54.1-DEV - 472577
Host: LUA-RTOS-ESP32
- IP V6 supported
- SSL supported
- LIBZ supported
- NTLM supported
- DEBUG NOT supported
- UNIX sockets NOT supported
Protocols:
- dict
- file
- ftp
- ftps
- gopher
- http
- https
- imap
- imaps
- pop3
- pop3s
- rtsp
- scp
- sftp
- smtp
- smtps
- telnet
- tftp

I (12064) wifi: pm start, type:0

Starting in 1 seconds...   

--------------------------------------------------------
I (16906) [cURL Example]: === PASS 1; restart_cnt=0 ===
--------------------------------------------------------


#### HTTP GET
     Send GET request with parameters

____________ Response BODY: ____________

============
Method: GET
============

--------------------------
Number of uploaded files: 0
    Number of GET params: 2
   Number of POST params: 0
--------------------------

===========
Debug info:
===========

-----------
POST DATA: 
-----------
Array
(
)
-----------
 GET DATA:  
-----------
Array
(
    [par1] => 765
    [par2] => test
)
-----------
FILE DATA: 
-----------
Array
(
)
-----------

=====================================
LoBo test server, 2017/05/07 15:42:19
=====================================

^^^^^^^^^^^^ Response BODY: ^^^^^^^^^^^^


#### HTTP GET FILE
     Get file (~225 KB) from http server and save it to file system
* Download: received 150142
* Download: received 230456 B; time=8.0 s; speed=28.1 KB/sec

____________ Response BODY: ____________
Saved to file /spiflash/tiger.bmp, size=230456
^^^^^^^^^^^^ Response BODY: ^^^^^^^^^^^^


#### HTTPS (SSL) GET
     Send GET request to secure (SSL) server

____________ Response BODY: ____________
This is a test

The quick brown fox jumped over the lazy dogs.
1234567890!@#$%^&*()[]{}-=_+;:'",.<>/?`~\|

^^^^^^^^^^^^ Response BODY: ^^^^^^^^^^^^


#### HTTP POST
     Send POST request with 3 parameters

____________ Response BODY: ____________

============
Method: POST
============

--------------------------
Number of uploaded files: 0
    Number of GET params: 0
   Number of POST params: 3
--------------------------

===========
Debug info:
===========

-----------
POST DATA: 
-----------
Array
(
    [param1] => 1234
    [param2] => esp32
    [param3] => Test from ESP32
)
-----------
 GET DATA:  
-----------
Array
(
)
-----------
FILE DATA: 
-----------
Array
(
)
-----------

=====================================
LoBo test server, 2017/05/07 15:42:46
=====================================

^^^^^^^^^^^^ Response BODY: ^^^^^^^^^^^^


#### FTP LIST TEST
     List files on FTP server

____________ Response BODY: ____________
-rw-r--r--   1 esp32    esp32group  2427146 May  2 17:29 bigimg.jpg
-rw-r--r--   1 esp32    esp32group  2427146 May  1 16:12 big.jpg
-rw-r--r--   1 root     root          609 May  5 17:50 ftptest.txt
-rw-r--r--   1 esp32    esp32group    97543 May  7 15:40 put_test.jpg
-rw-r--r--   1 esp32    esp32group     4092 May  7 12:43 put_test.txt
drwxr-xr-x   1 esp32    esp32group        0 Apr 26 00:35 test
-rw-r--r--   1 esp32    esp32group      583 May  1 14:54 test.txt
-rw-r--r--   1 esp32    esp32group    97543 Jan 30 19:26 tiger240.jpg
-rw-r--r--   1 esp32    esp32group   230456 Apr 30 10:29 tiger.bmp

^^^^^^^^^^^^ Response BODY: ^^^^^^^^^^^^


#### FTP GET TEXT FILE
     Get small text file from FTP server

____________ Response BODY: ____________
=== Do you speak Latin ?
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Nam rhoncus odio id venenatis volutpat.
Vestibulum dapibus bibendum ullamcorper.
Maecenas finibus elit augue, vel condimentum odio maximus nec.
In hac habitasse platea dictumst.
Vestibulum vel dolor et turpis rutrum finibus ac at nulla.
Vivamus nec neque ac elit blandit pretium vitae maximus ipsum.
Quisque sodales magna vel erat auctor, sed pellentesque nisi rhoncus.
Donec vehicula maximus pretium.
Aliquam eu tincidunt lorem.
Ut placerat, sem eu pharetra mattis, ante lacus fringilla diam, a consequat quam eros eget erat.

^^^^^^^^^^^^ Response BODY: ^^^^^^^^^^^^
     Received file saved to '/spiflash/postpar.txt' file


#### FTP GET JPG FILE
     Get JPG file (~95 KB) from FTP server and save it to file system
* Download: received 97543 B; time=4.5 s; speed=21.0 KB/sec

____________ Response BODY: ____________
Downloaded to file /spiflash/tiger.jpg, size=97543
^^^^^^^^^^^^ Response BODY: ^^^^^^^^^^^^


#### FTP PUT JPG FILE
     Upload received JPG file back to FTP server
* Upload: sent 97543 B; time=2.8 s; speed=34.2 KB/sec

____________ Response BODY: ____________
Uploaded file /spiflash/tiger.jpg, size=97543
^^^^^^^^^^^^ Response BODY: ^^^^^^^^^^^^


#### SFTP DOWNLOAD TEXT FILE
     Download small text file from SFTP (SSH) server

____________ Response BODY: ____________
Welcome,

you are connected to an FTP or SFTP server used for testing purposes by Rebex FTP/SSL or Rebex SFTP sample code.
Only read access is allowed and the FTP download speed is limited to 16KBps.

For infomation about Rebex FTP/SSL, Rebex SFTP and other Rebex .NET components, please visit our website at http://www.rebex.net/

For feedback and support, contact support@rebex.net

Thanks!

^^^^^^^^^^^^ Response BODY: ^^^^^^^^^^^^
     Received file saved to '/spiflash/sftptest.txt' file


#### SFTP UPLOAD JPG FILE
     Upload JPG file to SFTP (SSH) server
* Upload: sent 4096
* Upload: sent 86016
* Upload: sent 97543 B; time=11.9 s; speed=8.0 KB/sec

____________ Response BODY: ____________
Uploaded file /spiflash/tiger.jpg, size=97543
^^^^^^^^^^^^ Response BODY: ^^^^^^^^^^^^


#### SMTP: SEND MAIL
     Send email using 'smtp.gmail.com' mail server

TIME: 10.0 UP: 129001
     OK.

Waiting 30 seconds...    
Partial Example output with verbose mode ON

Code: Select all

#### HTTPS (SSL) GET
     Send GET request to secure (SSL) server
* timeout on name lookup is not supported
*   Trying 198.128.229.135...
* TCP_NODELAY set
* Connected to www-eng-x.llnl.gov (198.128.229.135) port 443 (#0)
* Error reading ca cert file /certs/ca-certificates.crt - mbedTLS: (-0x3E00) PK - Read/write of file failed
* mbedTLS: Connecting to www-eng-x.llnl.gov:443
* mbedTLS: Set min SSL version to TLS 1.0
* mbedTLS: Handshake complete, cipher is TLS-ECDHE-RSA-WITH-AES-256-GCM-SHA384
* Dumping cert info:
* cert. version     : 3
* serial number     : 03:67:A7:12:0F:F5:61:60:7E:8D:13:EC:55:4F:49:69:1D:61
* issuer name       : C=US, O=Let's Encrypt, CN=Let's Encrypt Authority X3
* subject name      : CN=www-br.llnl.gov
* issued  on        : 2017-04-01 06:44:00
* expires on        : 2017-06-30 06:44:00
* signed using      : RSA with SHA-256
* RSA key size      : 2048 bits
* basic constraints : CA=false
* subject alt name  : www-br.llnl.gov, www-br.ucllnl.org, www-eng-x.llnl.gov
* key usage         : Digital Signature, Key Encipherment
* ext key usage     : TLS Web Server Authentication, TLS Web Client Authentication

* SSL connected
> GET /documents/a_document.txt HTTP/1.1
Host: www-eng-x.llnl.gov
Accept: */*
Accept-Encoding: deflate, gzip

< HTTP/1.1 200 OK
* Download: received 17
< Date: Sun, 07 May 2017 16:38:04 GMT
< Server: Apache
< Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
< Last-Modified: Thu, 20 Apr 1995 07:00:00 GMT
< ETag: "6e-2d61af3ba7c00"
< Accept-Ranges: bytes
< Content-Length: 110
< Connection: close
< Content-Type: text/plain; charset=UTF-8
< 
* Download: received 110
* Closing connection 0

____________ Response BODY: ____________
This is a test

The quick brown fox jumped over the lazy dogs.
1234567890!@#$%^&*()[]{}-=_+;:'",.<>/?`~\|

^^^^^^^^^^^^ Response BODY: ^^^^^^^^^^^^

#### FTP GET JPG FILE
     Get JPG file (~95 KB) from FTP server and save it to file system
* timeout on name lookup is not supported
*   Trying 82.196.4.208...
* TCP_NODELAY set
* Connected to loboris.eu (82.196.4.208) port 21 (#0)
< 220 LoBo FTP Server
> AUTH SSL
< 500 AUTH not understood
> AUTH TLS
< 500 AUTH not understood
> USER esp32
< 331 Password required for esp32
> PASS esp32user
< 230 Anonymous access granted, restrictions apply
> PWD
< 257 "/" is the current directory
* Entry path is '/'
> PASV
* Connect data stream passively
* ftp_perform ends with SECONDARY: 0
< 227 Entering Passive Mode (82,196,4,208,192,21).
*   Trying 82.196.4.208...
* TCP_NODELAY set
* Connecting to 82.196.4.208 (82.196.4.208) port 49173
* Connected to loboris.eu (82.196.4.208) port 21 (#0)
> TYPE I
< 200 Type set to I
> SIZE tiger240.jpg
< 213 97543
> RETR tiger240.jpg
< 150 Opening BINARY mode data connection for tiger240.jpg (97543 bytes)
* Maxdownload = -1
* Getting file with size: 97543
* Remembering we are in dir ""
< 226 Transfer complete
> QUIT
< 221 Goodbye.
* Closing connection 0
* Download: received 97543 B; time=3.8 s; speed=24.8 KB/sec

____________ Response BODY: ____________
Downloaded to file /spiflash/tiger.jpg, size=97543
^^^^^^^^^^^^ Response BODY: ^^^^^^^^^^^^

#### SFTP DOWNLOAD TEXT FILE
     Download small text file from SFTP (SSH) server
* timeout on name lookup is not supported
*   Trying 195.144.107.198...
* TCP_NODELAY set
* Connected to test.rebex.net (195.144.107.198) port 22 (#0)
* SSH MD5 fingerprint: 0361c498f1ff7d239751071388b8c555
* SSH authentication methods available: password,keyboard-interactive,publickey
* Initialized password authentication
* Authentication complete
* Closing connection 0

____________ Response BODY: ____________
Welcome,

you are connected to an FTP or SFTP server used for testing purposes by Rebex FTP/SSL or Rebex SFTP sample code.
Only read access is allowed and the FTP download speed is limited to 16KBps.

For infomation about Rebex FTP/SSL, Rebex SFTP and other Rebex .NET components, please visit our website at http://www.rebex.net/

For feedback and support, contact support@rebex.net

Thanks!

^^^^^^^^^^^^ Response BODY: ^^^^^^^^^^^^
     Received file saved to '/spiflash/sftptest.txt' file


#### SFTP UPLOAD JPG FILE
     Upload JPG file to SFTP (SSH) server
* timeout on name lookup is not supported
*   Trying 199.71.215.197...
* TCP_NODELAY set
* Connected to demo.wftpserver.com (199.71.215.197) port 2222 (#0)
* SSH MD5 fingerprint: 8c8cbe606d6a2a97008c203e15d36f74
* SSH authentication methods available: publickey,password
* Initialized password authentication
* Authentication complete
* Upload: sent 36864
* We are completely uploaded and fine
* Closing connection 0
* Upload: sent 97543 B; time=11.2 s; speed=8.5 KB/sec

____________ Response BODY: ____________
Uploaded file /spiflash/tiger.jpg, size=97543
^^^^^^^^^^^^ Response BODY: ^^^^^^^^^^^^


#### SMTP: SEND MAIL
     Send email using 'smtp.gmail.com' mail server
* Rebuilt URL to: smtps://smtp.gmail.com:465/
* timeout on name lookup is not supported
*   Trying 74.125.133.109...
* TCP_NODELAY set
* Connected to smtp.gmail.com (74.125.133.109) port 465 (#0)
* Error reading ca cert file /certs/ca-certificates.crt - mbedTLS: (-0x3E00) PK - Read/write of file failed
* mbedTLS: Connecting to smtp.gmail.com:465
* mbedTLS: Set min SSL version to TLS 1.0
* mbedTLS: Handshake complete, cipher is TLS-ECDHE-RSA-WITH-AES-128-GCM-SHA256
* Dumping cert info:
* cert. version     : 3
* serial number     : 14:8E:07:6E:DC:42:D9:21
* issuer name       : C=US, O=Google Inc, CN=Google Internet Authority G2
* subject name      : C=US, ST=California, L=Mountain View, O=Google Inc, CN=smtp.gmail.com
* issued  on        : 2017-04-27 09:09:38
* expires on        : 2017-07-20 08:31:00
* signed using      : RSA with SHA-256
* RSA key size      : 2048 bits
* basic constraints : CA=false
* subject alt name  : smtp.gmail.com
* ext key usage     : TLS Web Server Authentication, TLS Web Client Authentication

* SSL connected
< 220 smtp.gmail.com ESMTP t85sm10281633wmt.23 - gsmtp
> EHLO localhost
< 250-smtp.gmail.com at your service, [109.60.11.156]
< 250-SIZE 35882577
< 250-8BITMIME
< 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH
< 250-ENHANCEDSTATUSCODES
< 250-PIPELINING
< 250-CHUNKING
< 250 SMTPUTF8
> AUTH LOGIN
< 334 VXNlcm5hbWU6
> <!!hidden - user name!!>
< 334 UGFzc3dvcmQ6
> <!!hidden - password!!>=
< 235 2.7.0 Accepted
> MAIL FROM:<loboris@gmail.com>
< 250 2.1.0 OK t85sm10281633wmt.23 - gsmtp
> RCPT TO:<loboris@gmail.com>
< 250 2.1.5 OK t85sm10281633wmt.23 - gsmtp
> DATA
< 354  Go ahead t85sm10281633wmt.23 - gsmtp

< 250 2.0.0 OK 1494175105 t85sm10281633wmt.23 - gsmtp
> QUIT
< 221 2.0.0 closing connection t85sm10281633wmt.23 - gsmtp
* Closing connection 0
TIME: 5.0 UP: 120055
     OK.
Last edited by loboris on Mon Jun 19, 2017 5:08 pm, edited 6 times in total.

Johannes
Posts: 1
Joined: Tue May 09, 2017 9:18 am

Re: Full example of using libcurl with ESP3232

Postby Johannes » Wed May 10, 2017 8:15 am

Thanks for the code.
I tried compiling but i get errors:

Code: Select all

ESP32/ESP32_curl_example/components/curl/lib/curl_setup.h:41:25: fatal error: curl_config.h: 
No such file or directory compilation terminated.
make[1]: *** [/home/johannes/Projekte/ESP32/esp-idf/make/component_wrapper.mk:177: lib/http_digest.o] Fehler 1
There is a file named "curl_config.h.cmake" but it seems that xtensa-esp32-elf has trouble processing .cmake files.

Is there something i am missing?

Info:
OS Arch Linux (up to date 10.05.2017)
xtensa-esp32-elf-linux64-1.22.0-61-gab8375a-5.2.0
esp-idf cloned at 09.05.2017

Best Regards

User avatar
loboris
Posts: 514
Joined: Wed Dec 21, 2016 7:40 pm

Re: Full example of using libcurl with ESP3232

Postby loboris » Thu May 11, 2017 8:05 pm

I'm sorry, somehow curl_config.h was in .gitignore and was not pushed to GitHub repository.

The repository is updated now and you should be able to build without problem.

gregstewart90
Posts: 59
Joined: Thu Jan 19, 2017 5:17 pm

Re: Full example of using libcurl with ESP3232

Postby gregstewart90 » Thu May 11, 2017 9:38 pm

This is great stuff! I'm trying to connect to a server at 192.168.1.20. It is a Ubiquiti ethernet radio. In your example, you create a connection to the (http://loboris.eu/ESP32/test.php) domain. The output you get if verbose is enabled is

Code: Select all

* timeout on name lookup is not supported
*   Trying 82.196.4.208...
* TCP_NODELAY set
* Connected to loboris.eu (82.196.4.208) port 80 (#0)
> POST /ESP32/test.php HTTP/1.1
When I try to connect to 192.168.1.20 (int res = Curl_POST("https://192.168.1.20/", hdrbuf, bodybuf, 1024, 4096);), I get back

Code: Select all

* timeout on name lookup is not supported
*   Trying 192.168.1.20...
* TCP_NODELAY set
* Connected to 192.168.1.20 (192.168.1.20) port 443 (#0)
* Error reading ca cert file /certs/ca-certificates.crt - mbedTLS: (-0x3E00) PK - Read/write of file failed
* mbedTLS: Connecting to 192.168.1.20:443
* mbedTLS: Set min SSL version to TLS 1.0
The code then hangs.

I tried uncommenting the following line, but then it said it couldn't find ca-bundle.crt.

Code: Select all

	// ==== Provide CA Certs from different file than default ====
	curl_easy_setopt(handle, CURLOPT_CAINFO, "ca-bundle.crt");
	// ===========================================================
Any ideas on how to make this work? If needed, I can use ngnok to allow someone to try connecting to this server.

User avatar
loboris
Posts: 514
Joined: Wed Dec 21, 2016 7:40 pm

Re: Full example of using libcurl with ESP3232

Postby loboris » Fri May 12, 2017 8:44 am

@gregstewart90

When using SSL curl tries to get certificate from file. Default is set to /certs/ca-certificates.crt in curl_config.h.
You can set differetn path to the certificate file with

Code: Select all

curl_easy_setopt(handle, CURLOPT_CAINFO, "ca-bundle.crt");
.
The certificate can also be loaded from memory buffer, but this is not implemented in this example. Look at the curl example https://curl.haxx.se/libcurl/c/cacertinmem.html.

When the certificate is not found, the bahavior depends on CURLOPT_SSL_VERIFYHOST and CURLOPT_SSL_VERIFYPEER which in this example are both set to 0:
This option determines whether curl verifies the authenticity of the peer's certificate. A value of 1 means curl verifies; 0 (zero) means it doesn't.

When negotiating a TLS or SSL connection, the server sends a certificate indicating its identity. Curl verifies whether the certificate is authentic, i.e. that you can trust that the server is who the certificate says it is. This trust is based on a chain of digital signatures, rooted in certification authority (CA) certificates you supply. curl uses a default bundle of CA certificates (the path for that is determined at build time) and you can specify alternate certificates with the CURLOPT_CAINFO option or the CURLOPT_CAPATH option.

When CURLOPT_SSL_VERIFYPEER is enabled, and the verification fails to prove that the certificate is authentic, the connection fails. When the option is zero, the peer certificate verification succeeds regardless.

Authenticating the certificate is not enough to be sure about the server. You typically also want to ensure that the server is the server you mean to be talking to. Use CURLOPT_SSL_VERIFYHOST for that. The check that the host name in the certificate is valid for the host name you're connecting to is done independently of the CURLOPT_SSL_VERIFYPEER option.

WARNING: disabling verification of the certificate allows bad guys to man-in-the-middle the communication without you knowing it. Disabling verification makes the communication insecure. Just having encryption on a transfer is not enough as you cannot be sure that you are communicating with the correct end-point.
, so the connection to your host should succeed regardless of certificate is found or not.
The connection to the included example https server always succedees, and I've tried with many other servers, for example https://google.com.

The function should not hang, the curl timeout in the example is set to 20 seconds, so the function should return after 20 s with error if the connection is not successful.

gregstewart90
Posts: 59
Joined: Thu Jan 19, 2017 5:17 pm

Re: Full example of using libcurl with ESP3232

Postby gregstewart90 » Fri May 12, 2017 4:20 pm

@loboris

Have you done any https post requests or just get requests? Would that make a difference???

I think I might have found something. When I run the code on my mac, it works just fine. When I run it on the ESP32, it hangs (even after 20 seconds). I did verbose on both, and I found a difference in the TLS setting.

MAC:

Code: Select all

*   Trying 192.168.1.20...
* Connected to 192.168.1.20 (192.168.1.20) port 443 (#0)
* TLS 1.2 connection using TLS_DHE_RSA_WITH_AES_256_CBC_SHA256
* Server certificate: UBNT-68:72:51:60:4D:4F
ESP32:

Code: Select all

* timeout on name lookup is not supported
*   Trying 192.168.1.20...
* TCP_NODELAY set
* Connected to 192.168.1.20 (192.168.1.20) port 443 (#0)
* Error reading ca cert file /etc/ssl/certs/ca-certificates.crt - mbedTLS: (-0x3E00) PK - Read/write of file failed
* mbedTLS: Connecting to 192.168.1.20:443
* mbedTLS: Set min SSL version to TLS 1.0

Code I am running:

Code: Select all

	printf("Beginning Login Test**\n");
	curl_version_info_data *data = curl_version_info(CURLVERSION_NOW);
	printf("Curl version info");
	printf("version: %s - %d", data->version, data->version_num);

	CURLcode ret;
	CURL *hnd;

	hnd = curl_easy_init();
	curl_easy_setopt(hnd, CURLOPT_URL, "https://192.168.1.20/");
	curl_easy_setopt(hnd, CURLOPT_NOPROGRESS, 1L);
	curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L);
	curl_easy_setopt(hnd, CURLOPT_FOLLOWLOCATION, 1L);
	curl_easy_setopt(hnd, CURLOPT_USERAGENT, "curl/7.50.3");
	curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L);
	curl_easy_setopt(hnd, CURLOPT_SSL_VERIFYPEER, 0);
	curl_easy_setopt(hnd, CURLOPT_SSL_VERIFYHOST, 0L);
	curl_easy_setopt(hnd, CURLOPT_COOKIEFILE, "");
	curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L);

//	CURLcode rv=curl_easy_setopt(hnd, CURLOPT_SSL_CTX_FUNCTION, *sslctx_function);
	printf("Before Perform\n");
	ret = curl_easy_perform(hnd);
	printf("After Perform\n");
I tried the certificate being loaded from memory approach on the ESP32, but the OpenSSL library that comes with the ESP32 lacks several components needed to compile.

I'm not sure if I should try and save the cert somewhere no the esp32 or even how to do that.

Thoughts?

EDIT:

I added
curl_easy_setopt(hnd, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_0);
to my code, and the TLS warning went away. Same results. It works on the mac and hangs indefinitely on the ESP32. I disabled the watch dog timer because it was getting triggered.

It appears that the hang may not be within libcurl but with mbedTLS. The following is the output. It stays at connecting indefinitely.

Code: Select all

* timeout on name lookup is not supported
*   Trying 192.168.1.20...
* TCP_NODELAY set
* Connected to 192.168.1.20 (192.168.1.20) port 443 (#0)
* Error reading ca cert file /etc/ssl/certs/ca-certificates.crt - mbedTLS: (-0x3E00) PK - Read/write of file failed
* mbedTLS: Connecting to 192.168.1.20:443
EDIT:
I took a look at the https example on the esp-idf. It uses an external .pem file for certification. In the root directory, a component.mk file is created containing
COMPONENT_EMBED_TXTFILES := server_root_cert.pem. In the root directory, we also have the server_root_cert.pem file. Can I make that work with curl_easy_setopt(handle, CURLOPT_CAINFO, "ca-bundle.crt");
The .pem file is accessed with
extern const uint8_t server_root_cert_pem_start[] asm("_binary_server_root_cert_pem_start");
extern const uint8_t server_root_cert_pem_end[] asm("_binary_server_root_cert_pem_end");
Any ideas on how to make this work or should I approach it a different way? I also use the NVS a lot for storing variables.

User avatar
loboris
Posts: 514
Joined: Wed Dec 21, 2016 7:40 pm

Re: Full example of using libcurl with ESP3232

Postby loboris » Mon May 15, 2017 10:26 pm

Example is updated:
  • Added libssh2 library and enabled curl scp/sftp protocol
  • Added example of using sftp upload/download from ssh server
  • Some small bug fixes

User avatar
loboris
Posts: 514
Joined: Wed Dec 21, 2016 7:40 pm

Re: Full example of using libcurl with ESP3232

Postby loboris » Tue May 16, 2017 12:28 pm

@gregstewart90

I have added the option to enable mbedtls debuging, maybe it could help you to solve your problem.

To enable:
- execute make menuconfig and under Component config → mbedTLS select Enable mbedTLS debugging
- Edit curl_config.h, set MBEDTLS_DEBUG_LEVEL to the debug level you want to use
- Build with mbedtls debugging enabled and flash...

gregstewart90
Posts: 59
Joined: Thu Jan 19, 2017 5:17 pm

Re: Full example of using libcurl with ESP3232

Postby gregstewart90 » Tue May 16, 2017 9:34 pm

Thanks for enabling that. Below is my output

Code: Select all

* timeout on name lookup is not supported
*   Trying 192.168.1.25...
* TCP_NODELAY set
* Connected to 192.168.1.25 (192.168.1.25) port 443 (#0)
* Error reading ca cert file /certs/ca-certificates.crt - mbedTLS: (-0x3E00) PK - Read/write of file failed
* mbedTLS: Connecting to 192.168.1.25:443
* mbedTLS: Set min SSL version to TLS 1.0
W (6432) mbedtls: ssl_tls.c:4425 x509_verify_cert() returned -9984 (-0x2700)
I also tried it with a GET without success.

Code: Select all

     Send GET request to secure (SSL) server
* timeout on name lookup is not supported
*   Trying 192.168.1.25...
* TCP_NODELAY set
* Connected to 192.168.1.25 (192.168.1.25) port 443 (#0)
* Error reading ca cert file /certs/ca-certificates.crt - mbedTLS: (-0x3E00) PK - Read/write of file failed
* mbedTLS: Connecting to 192.168.1.25:443
* mbedTLS: Set min SSL version to TLS 1.0
W (5926) mbedtls: ssl_tls.c:4425 x509_verify_cert() returned -9984 (-0x2700)
Are you able to POST to a https address?

User avatar
loboris
Posts: 514
Joined: Wed Dec 21, 2016 7:40 pm

Re: Full example of using libcurl with ESP3232

Postby loboris » Wed May 17, 2017 12:55 am

@gregstewart90

I have tried POST request to https server, there was no problem.
I have small php script on my server which returns status of the post (or get) request, you can try it.
In testCurl.c set:

Code: Select all

static char Post_testURL[] = "https://amp.dhz.hr/test/test.php";
Here is the full output with verbose=1 and mbedtls debug level set to 2:

Code: Select all

#### HTTP POST
     Send POST request with 3 parameters
* timeout on name lookup is not supported
*   Trying 161.53.81.17...
* TCP_NODELAY set
* Connected to amp.dhz.hr (161.53.81.17) port 443 (#0)
* Error reading ca cert file /certs/ca-certificates.crt - mbedTLS: (-0x3E00) PK - Read/write of file failed
* mbedTLS: Connecting to amp.dhz.hr:443
* mbedTLS: Set min SSL version to TLS 1.0
I (181900) mbedtls: ssl_tls.c:6306 => handshake

I (181905) mbedtls: ssl_cli.c:3254 client state: 0

I (181911) mbedtls: ssl_tls.c:2430 => flush output

I (181917) mbedtls: ssl_tls.c:2442 <= flush output

I (181922) mbedtls: ssl_cli.c:3254 client state: 1

I (181928) mbedtls: ssl_tls.c:2430 => flush output

I (181933) mbedtls: ssl_tls.c:2442 <= flush output

I (181939) mbedtls: ssl_cli.c:719 => write client hello

I (181946) mbedtls: ssl_tls.c:2715 => write record

I (181951) mbedtls: ssl_tls.c:2430 => flush output

I (181957) mbedtls: ssl_tls.c:2449 message length: 399, out_left: 399

I (181964) mbedtls: ssl_tls.c:2455 ssl->f_send() returned 399 (-0xfffffe71)

I (181972) mbedtls: ssl_tls.c:2474 <= flush output

I (181977) mbedtls: ssl_tls.c:2864 <= write record

I (181983) mbedtls: ssl_cli.c:1051 <= write client hello

I (181989) mbedtls: ssl_cli.c:3254 client state: 2

I (181995) mbedtls: ssl_tls.c:2430 => flush output

I (182000) mbedtls: ssl_tls.c:2442 <= flush output

I (182006) mbedtls: ssl_cli.c:1403 => parse server hello

I (182012) mbedtls: ssl_tls.c:3738 => read record

I (182018) mbedtls: ssl_tls.c:2222 => fetch input

I (182023) mbedtls: ssl_tls.c:2380 in_left: 0, nb_want: 5

I (182030) mbedtls: ssl_tls.c:2404 in_left: 0, nb_want: 5

I (182036) mbedtls: ssl_tls.c:2405 ssl->f_recv(_timeout)() returned 5 (-0xfffffffb)

I (182044) mbedtls: ssl_tls.c:2417 <= fetch input

I (182050) mbedtls: ssl_tls.c:2222 => fetch input

I (182055) mbedtls: ssl_tls.c:2380 in_left: 5, nb_want: 7

I (182062) mbedtls: ssl_tls.c:2404 in_left: 5, nb_want: 7

I (182068) mbedtls: ssl_tls.c:2405 ssl->f_recv(_timeout)() returned 2 (-0xfffffffe)

I (182076) mbedtls: ssl_tls.c:2417 <= fetch input

I (182082) mbedtls: ssl_tls.c:3930 got an alert message, type: [1:112]

I (182089) mbedtls: ssl_tls.c:2222 => fetch input

I (182095) mbedtls: ssl_tls.c:2380 in_left: 0, nb_want: 5

I (182101) mbedtls: ssl_tls.c:2404 in_left: 0, nb_want: 5

I (182107) mbedtls: ssl_tls.c:2405 ssl->f_recv(_timeout)() returned 5 (-0xfffffffb)

I (182116) mbedtls: ssl_tls.c:2417 <= fetch input

I (182121) mbedtls: ssl_tls.c:2222 => fetch input

I (182127) mbedtls: ssl_tls.c:2380 in_left: 5, nb_want: 98

I (182133) mbedtls: ssl_tls.c:2404 in_left: 5, nb_want: 98

I (182140) mbedtls: ssl_tls.c:2405 ssl->f_recv(_timeout)() returned 93 (-0xffffffa3)

I (182148) mbedtls: ssl_tls.c:2417 <= fetch input

I (182154) mbedtls: ssl_tls.c:3975 <= read record

I (182159) mbedtls: ssl_cli.c:1664 server hello, total extension length: 17

I (182167) mbedtls: ssl_cli.c:1852 <= parse server hello

I (182173) mbedtls: ssl_cli.c:3254 client state: 3

I (182179) mbedtls: ssl_tls.c:2430 => flush output

I (182185) mbedtls: ssl_tls.c:2442 <= flush output

I (182190) mbedtls: ssl_tls.c:4194 => parse certificate

I (182196) mbedtls: ssl_tls.c:3738 => read record

I (182202) mbedtls: ssl_tls.c:2222 => fetch input

I (182207) mbedtls: ssl_tls.c:2380 in_left: 0, nb_want: 5

I (182214) mbedtls: ssl_tls.c:2404 in_left: 0, nb_want: 5

I (182220) mbedtls: ssl_tls.c:2405 ssl->f_recv(_timeout)() returned 5 (-0xfffffffb)

I (182228) mbedtls: ssl_tls.c:2417 <= fetch input

I (182234) mbedtls: ssl_tls.c:2222 => fetch input

I (182240) mbedtls: ssl_tls.c:2380 in_left: 5, nb_want: 711

I (182246) mbedtls: ssl_tls.c:2404 in_left: 5, nb_want: 711

I (182252) mbedtls: ssl_tls.c:2405 ssl->f_recv(_timeout)() returned 706 (-0xfffffd3e)

I (182261) mbedtls: ssl_tls.c:2417 <= fetch input

I (182267) mbedtls: ssl_tls.c:3975 <= read record

W (182273) mbedtls: ssl_tls.c:4425 x509_verify_cert() returned -9984 (-0x2700)

I (182280) mbedtls: ssl_tls.c:4461 <= parse certificate

I (182286) mbedtls: ssl_cli.c:3254 client state: 4

I (182292) mbedtls: ssl_tls.c:2430 => flush output

I (182298) mbedtls: ssl_tls.c:2442 <= flush output

I (182303) mbedtls: ssl_cli.c:2191 => parse server key exchange

I (182310) mbedtls: ssl_tls.c:3738 => read record

I (182316) mbedtls: ssl_tls.c:2222 => fetch input

I (182321) mbedtls: ssl_tls.c:2380 in_left: 0, nb_want: 5

I (182328) mbedtls: ssl_tls.c:2404 in_left: 0, nb_want: 5

I (182334) mbedtls: ssl_tls.c:2405 ssl->f_recv(_timeout)() returned 5 (-0xfffffffb)

I (182342) mbedtls: ssl_tls.c:2417 <= fetch input

I (182348) mbedtls: ssl_tls.c:2222 => fetch input

I (182353) mbedtls: ssl_tls.c:2380 in_left: 5, nb_want: 338

I (182360) mbedtls: ssl_tls.c:2404 in_left: 5, nb_want: 338

I (182366) mbedtls: ssl_tls.c:2405 ssl->f_recv(_timeout)() returned 333 (-0xfffffeb3)

I (182375) mbedtls: ssl_tls.c:2417 <= fetch input

I (182380) mbedtls: ssl_tls.c:3975 <= read record

I (182386) mbedtls: ssl_cli.c:1912 ECDH curve: secp256r1

I (182392) mbedtls: ssl_cli.c:2134 Server used SignatureAlgorithm 1

I (182399) mbedtls: ssl_cli.c:2135 Server used HashAlgorithm 6

I (182504) mbedtls: ssl_cli.c:2509 <= parse server key exchange

I (182504) mbedtls: ssl_cli.c:3254 client state: 5

I (182505) mbedtls: ssl_tls.c:2430 => flush output

I (182511) mbedtls: ssl_tls.c:2442 <= flush output

I (182516) mbedtls: ssl_cli.c:2547 => parse certificate request

I (182523) mbedtls: ssl_tls.c:3738 => read record

I (182529) mbedtls: ssl_tls.c:2222 => fetch input

I (182534) mbedtls: ssl_tls.c:2380 in_left: 0, nb_want: 5

I (182541) mbedtls: ssl_tls.c:2404 in_left: 0, nb_want: 5

I (182547) mbedtls: ssl_tls.c:2405 ssl->f_recv(_timeout)() returned 5 (-0xfffffffb)

I (182555) mbedtls: ssl_tls.c:2417 <= fetch input

I (182561) mbedtls: ssl_tls.c:2222 => fetch input

I (182566) mbedtls: ssl_tls.c:2380 in_left: 5, nb_want: 9

I (182573) mbedtls: ssl_tls.c:2404 in_left: 5, nb_want: 9

I (182579) mbedtls: ssl_tls.c:2405 ssl->f_recv(_timeout)() returned 4 (-0xfffffffc)

I (182587) mbedtls: ssl_tls.c:2417 <= fetch input

I (182593) mbedtls: ssl_tls.c:3975 <= read record

I (182599) mbedtls: ssl_cli.c:2656 <= parse certificate request

I (182605) mbedtls: ssl_cli.c:3254 client state: 6

I (182611) mbedtls: ssl_tls.c:2430 => flush output

I (182617) mbedtls: ssl_tls.c:2442 <= flush output

I (182622) mbedtls: ssl_cli.c:2669 => parse server hello done

I (182629) mbedtls: ssl_cli.c:2701 <= parse server hello done

I (182635) mbedtls: ssl_cli.c:3254 client state: 7

I (182641) mbedtls: ssl_tls.c:2430 => flush output

I (182647) mbedtls: ssl_tls.c:2442 <= flush output

I (182652) mbedtls: ssl_tls.c:4078 => write certificate

I (182658) mbedtls: ssl_tls.c:4095 <= skip write certificate

I (182665) mbedtls: ssl_cli.c:3254 client state: 8

I (182671) mbedtls: ssl_tls.c:2430 => flush output

I (182676) mbedtls: ssl_tls.c:2442 <= flush output

I (182682) mbedtls: ssl_cli.c:2712 => write client key exchange

I (183412) mbedtls: ssl_tls.c:2715 => write record

I (183412) mbedtls: ssl_tls.c:2430 => flush output

I (183413) mbedtls: ssl_tls.c:2449 message length: 75, out_left: 75

I (183420) mbedtls: ssl_tls.c:2455 ssl->f_send() returned 75 (-0xffffffb5)

I (183427) mbedtls: ssl_tls.c:2474 <= flush output

I (183433) mbedtls: ssl_tls.c:2864 <= write record

I (183439) mbedtls: ssl_cli.c:2957 <= write client key exchange

I (183445) mbedtls: ssl_cli.c:3254 client state: 9

I (183451) mbedtls: ssl_tls.c:2430 => flush output

I (183457) mbedtls: ssl_tls.c:2442 <= flush output

I (183462) mbedtls: ssl_cli.c:3004 => write certificate verify

I (183469) mbedtls: ssl_tls.c:503 => derive keys

I (183482) mbedtls: ssl_tls.c:959 <= derive keys

I (183483) mbedtls: ssl_cli.c:3025 <= skip write certificate verify

I (183487) mbedtls: ssl_cli.c:3254 client state: 10

I (183493) mbedtls: ssl_tls.c:2430 => flush output

I (183498) mbedtls: ssl_tls.c:2442 <= flush output

I (183504) mbedtls: ssl_tls.c:4477 => write change cipher spec

I (183511) mbedtls: ssl_tls.c:2715 => write record

I (183516) mbedtls: ssl_tls.c:2430 => flush output

I (183522) mbedtls: ssl_tls.c:2449 message length: 6, out_left: 6

I (183529) mbedtls: ssl_tls.c:2455 ssl->f_send() returned 6 (-0xfffffffa)

I (183537) mbedtls: ssl_tls.c:2474 <= flush output

I (183542) mbedtls: ssl_tls.c:2864 <= write record

I (183548) mbedtls: ssl_tls.c:4491 <= write change cipher spec

I (183555) mbedtls: ssl_cli.c:3254 client state: 11

I (183560) mbedtls: ssl_tls.c:2430 => flush output

I (183566) mbedtls: ssl_tls.c:2442 <= flush output

I (183572) mbedtls: ssl_tls.c:5002 => write finished

I (183577) mbedtls: ssl_tls.c:4876 => calc  finished tls sha384

I (183586) mbedtls: ssl_tls.c:4906 <= calc  finished

I (183590) mbedtls: ssl_tls.c:2715 => write record

I (183596) mbedtls: ssl_tls.c:1260 => encrypt buf

I (183601) mbedtls: ssl_tls.c:1574 <= encrypt buf

I (183607) mbedtls: ssl_tls.c:2430 => flush output

I (183612) mbedtls: ssl_tls.c:2449 message length: 45, out_left: 45

I (183620) mbedtls: ssl_tls.c:2455 ssl->f_send() returned 45 (-0xffffffd3)

I (183627) mbedtls: ssl_tls.c:2474 <= flush output

I (183633) mbedtls: ssl_tls.c:2864 <= write record

I (183638) mbedtls: ssl_tls.c:5111 <= write finished

I (183644) mbedtls: ssl_cli.c:3254 client state: 12

I (183650) mbedtls: ssl_tls.c:2430 => flush output

I (183656) mbedtls: ssl_tls.c:2442 <= flush output

I (183661) mbedtls: ssl_tls.c:4500 => parse change cipher spec

I (183668) mbedtls: ssl_tls.c:3738 => read record

I (183674) mbedtls: ssl_tls.c:2222 => fetch input

I (183679) mbedtls: ssl_tls.c:2380 in_left: 0, nb_want: 5

I (183686) mbedtls: ssl_tls.c:2404 in_left: 0, nb_want: 5

I (183692) mbedtls: ssl_tls.c:2405 ssl->f_recv(_timeout)() returned 5 (-0xfffffffb)

I (183700) mbedtls: ssl_tls.c:2417 <= fetch input

I (183706) mbedtls: ssl_tls.c:2222 => fetch input

I (183711) mbedtls: ssl_tls.c:2380 in_left: 5, nb_want: 6

I (183718) mbedtls: ssl_tls.c:2404 in_left: 5, nb_want: 6

I (183724) mbedtls: ssl_tls.c:2405 ssl->f_recv(_timeout)() returned 1 (-0xffffffff)

I (183732) mbedtls: ssl_tls.c:2417 <= fetch input

I (183738) mbedtls: ssl_tls.c:3975 <= read record

I (183743) mbedtls: ssl_tls.c:4570 <= parse change cipher spec

I (183750) mbedtls: ssl_cli.c:3254 client state: 13

I (183756) mbedtls: ssl_tls.c:2430 => flush output

I (183761) mbedtls: ssl_tls.c:2442 <= flush output

I (183767) mbedtls: ssl_tls.c:5128 => parse finished

I (183773) mbedtls: ssl_tls.c:4876 => calc  finished tls sha384

I (183781) mbedtls: ssl_tls.c:4906 <= calc  finished

I (183785) mbedtls: ssl_tls.c:3738 => read record

I (183791) mbedtls: ssl_tls.c:2222 => fetch input

I (183797) mbedtls: ssl_tls.c:2380 in_left: 0, nb_want: 5

I (183803) mbedtls: ssl_tls.c:2404 in_left: 0, nb_want: 5

I (183809) mbedtls: ssl_tls.c:2405 ssl->f_recv(_timeout)() returned 5 (-0xfffffffb)

I (183817) mbedtls: ssl_tls.c:2417 <= fetch input

I (183823) mbedtls: ssl_tls.c:2222 => fetch input

I (183829) mbedtls: ssl_tls.c:2380 in_left: 5, nb_want: 45

I (183835) mbedtls: ssl_tls.c:2404 in_left: 5, nb_want: 45

I (183841) mbedtls: ssl_tls.c:2405 ssl->f_recv(_timeout)() returned 40 (-0xffffffd8)

I (183850) mbedtls: ssl_tls.c:2417 <= fetch input

I (183855) mbedtls: ssl_tls.c:1590 => decrypt buf

I (183861) mbedtls: ssl_tls.c:2065 <= decrypt buf

I (183867) mbedtls: ssl_tls.c:3975 <= read record

I (183872) mbedtls: ssl_tls.c:5190 <= parse finished

I (183878) mbedtls: ssl_cli.c:3254 client state: 14

I (183884) mbedtls: ssl_tls.c:2430 => flush output

I (183889) mbedtls: ssl_tls.c:2442 <= flush output

I (183895) mbedtls: ssl_cli.c:3365 handshake: done

I (183901) mbedtls: ssl_cli.c:3254 client state: 15

I (183906) mbedtls: ssl_tls.c:2430 => flush output

I (183912) mbedtls: ssl_tls.c:2442 <= flush output

I (183918) mbedtls: ssl_tls.c:6316 <= handshake

* mbedTLS: Handshake complete, cipher is TLS-ECDHE-RSA-WITH-AES-256-GCM-SHA384
* Dumping cert info:
* cert. version     : 3
* serial number     : 8B:FB:43:39:DA:90:74:77
* issuer name       : CN=lubuntu
* subject name      : CN=lubuntu
* issued  on        : 2013-11-04 10:22:26
* expires on        : 2023-11-02 10:22:26
* signed using      : RSA with SHA1
* RSA key size      : 2048 bits
* basic constraints : CA=false

* SSL connected
I (183966) mbedtls: ssl_tls.c:6825 => write

I (183967) mbedtls: ssl_tls.c:2715 => write record

I (183973) mbedtls: ssl_tls.c:1260 => encrypt buf

I (183979) mbedtls: ssl_tls.c:1574 <= encrypt buf

I (183984) mbedtls: ssl_tls.c:2430 => flush output

I (183989) mbedtls: ssl_tls.c:2449 message length: 254, out_left: 254

I (183997) mbedtls: ssl_tls.c:2455 ssl->f_send() returned 254 (-0xffffff02)

I (184004) mbedtls: ssl_tls.c:2474 <= flush output

I (184010) mbedtls: ssl_tls.c:2864 <= write record

I (184016) mbedtls: ssl_tls.c:6853 <= write

> POST /test/test.php HTTP/1.1
Host: amp.dhz.hr
Accept: */*
Accept-Encoding: deflate, gzip
Content-Length: 1107
Expect: 100-continue
Content-Type: multipart/form-data; boundary=------------------------d5219d78b6000df3

I (184042) mbedtls: ssl_tls.c:6484 => read

I (184046) mbedtls: ssl_tls.c:3738 => read record

I (184052) mbedtls: ssl_tls.c:2222 => fetch input

I (184057) mbedtls: ssl_tls.c:2380 in_left: 0, nb_want: 5

I (184064) mbedtls: ssl_tls.c:2404 in_left: 0, nb_want: 5

I (184070) mbedtls: ssl_tls.c:2405 ssl->f_recv(_timeout)() returned 5 (-0xfffffffb)

I (184078) mbedtls: ssl_tls.c:2417 <= fetch input

I (184084) mbedtls: ssl_tls.c:2222 => fetch input

I (184089) mbedtls: ssl_tls.c:2380 in_left: 5, nb_want: 54

I (184096) mbedtls: ssl_tls.c:2404 in_left: 5, nb_want: 54

I (184102) mbedtls: ssl_tls.c:2405 ssl->f_recv(_timeout)() returned 49 (-0xffffffcf)

I (184111) mbedtls: ssl_tls.c:2417 <= fetch input

I (184116) mbedtls: ssl_tls.c:1590 => decrypt buf

I (184122) mbedtls: ssl_tls.c:2065 <= decrypt buf

I (184127) mbedtls: ssl_tls.c:3975 <= read record

I (184133) mbedtls: ssl_tls.c:6724 <= read

< HTTP/1.1 100 Continue
I (184141) mbedtls: ssl_tls.c:6825 => write

I (184145) mbedtls: ssl_tls.c:2715 => write record

I (184151) mbedtls: ssl_tls.c:1260 => encrypt buf

I (184157) mbedtls: ssl_tls.c:1574 <= encrypt buf

I (184162) mbedtls: ssl_tls.c:2430 => flush output

I (184167) mbedtls: ssl_tls.c:2449 message length: 479, out_left: 479

I (184175) mbedtls: ssl_tls.c:2455 ssl->f_send() returned 479 (-0xfffffe21)

I (184183) mbedtls: ssl_tls.c:2474 <= flush output

I (184188) mbedtls: ssl_tls.c:2864 <= write record

I (184194) mbedtls: ssl_tls.c:6853 <= write

I (184200) mbedtls: ssl_tls.c:6825 => write

I (184204) mbedtls: ssl_tls.c:2715 => write record

I (184210) mbedtls: ssl_tls.c:1260 => encrypt buf

I (184216) mbedtls: ssl_tls.c:1574 <= encrypt buf

I (184221) mbedtls: ssl_tls.c:2430 => flush output

I (184226) mbedtls: ssl_tls.c:2449 message length: 638, out_left: 638

I (184234) mbedtls: ssl_tls.c:2455 ssl->f_send() returned 638 (-0xfffffd82)

I (184241) mbedtls: ssl_tls.c:2474 <= flush output

I (184247) mbedtls: ssl_tls.c:2864 <= write record

I (184253) mbedtls: ssl_tls.c:6853 <= write

I (184258) mbedtls: ssl_tls.c:6825 => write

I (184263) mbedtls: ssl_tls.c:2715 => write record

I (184268) mbedtls: ssl_tls.c:1260 => encrypt buf

I (184274) mbedtls: ssl_tls.c:1574 <= encrypt buf

I (184280) mbedtls: ssl_tls.c:2430 => flush output

I (184285) mbedtls: ssl_tls.c:2449 message length: 77, out_left: 77

I (184293) mbedtls: ssl_tls.c:2455 ssl->f_send() returned 77 (-0xffffffb3)

I (184300) mbedtls: ssl_tls.c:2474 <= flush output

I (184306) mbedtls: ssl_tls.c:2864 <= write record

I (184311) mbedtls: ssl_tls.c:6853 <= write

I (184317) mbedtls: ssl_tls.c:6484 => read

I (184321) mbedtls: ssl_tls.c:3738 => read record

I (184327) mbedtls: ssl_tls.c:2222 => fetch input

I (184332) mbedtls: ssl_tls.c:2380 in_left: 0, nb_want: 5

I (184339) mbedtls: ssl_tls.c:2404 in_left: 0, nb_want: 5

I (184345) mbedtls: ssl_tls.c:2405 ssl->f_recv(_timeout)() returned 5 (-0xfffffffb)

I (184353) mbedtls: ssl_tls.c:2417 <= fetch input

I (184359) mbedtls: ssl_tls.c:2222 => fetch input

I (184365) mbedtls: ssl_tls.c:2380 in_left: 5, nb_want: 246

I (184372) mbedtls: ssl_tls.c:2404 in_left: 5, nb_want: 246

I (184377) mbedtls: ssl_tls.c:2405 ssl->f_recv(_timeout)() returned 241 (-0xffffff0f)

I (184386) mbedtls: ssl_tls.c:2417 <= fetch input

I (184392) mbedtls: ssl_tls.c:1590 => decrypt buf

I (184398) mbedtls: ssl_tls.c:2065 <= decrypt buf

I (184403) mbedtls: ssl_tls.c:3975 <= read record

I (184408) mbedtls: ssl_tls.c:6724 <= read

< HTTP/1.1 200 OK
< Date: Wed, 17 May 2017 00:44:35 GMT
< Server: Apache/2.4.7 (Ubuntu)
< X-Powered-By: PHP/5.5.9-1ubuntu4.20
< Vary: Accept-Encoding
< Content-Encoding: gzip
< Content-Length: 310
< Content-Type: text/html
< 
I (184435) mbedtls: ssl_tls.c:6484 => read

I (184439) mbedtls: ssl_tls.c:3738 => read record

I (184445) mbedtls: ssl_tls.c:2222 => fetch input

I (184450) mbedtls: ssl_tls.c:2380 in_left: 0, nb_want: 5

I (184457) mbedtls: ssl_tls.c:2404 in_left: 0, nb_want: 5

I (184463) mbedtls: ssl_tls.c:2405 ssl->f_recv(_timeout)() returned 5 (-0xfffffffb)

I (184471) mbedtls: ssl_tls.c:2417 <= fetch input

I (184477) mbedtls: ssl_tls.c:2222 => fetch input

I (184483) mbedtls: ssl_tls.c:2380 in_left: 5, nb_want: 331

I (184489) mbedtls: ssl_tls.c:2404 in_left: 5, nb_want: 331

I (184495) mbedtls: ssl_tls.c:2405 ssl->f_recv(_timeout)() returned 326 (-0xfffffeba)

I (184504) mbedtls: ssl_tls.c:2417 <= fetch input

I (184510) mbedtls: ssl_tls.c:1590 => decrypt buf

I (184516) mbedtls: ssl_tls.c:2065 <= decrypt buf

I (184521) mbedtls: ssl_tls.c:3975 <= read record

I (184526) mbedtls: ssl_tls.c:6724 <= read

I (184533) mbedtls: ssl_tls.c:6484 => read

I (184536) mbedtls: ssl_tls.c:3738 => read record

I (184542) mbedtls: ssl_tls.c:2222 => fetch input

I (184547) mbedtls: ssl_tls.c:2380 in_left: 0, nb_want: 5

I (184554) mbedtls: ssl_tls.c:2404 in_left: 0, nb_want: 5

I (184560) mbedtls: ssl_tls.c:2405 ssl->f_recv(_timeout)() returned 5 (-0xfffffffb)

I (184568) mbedtls: ssl_tls.c:2417 <= fetch input

I (184574) mbedtls: ssl_tls.c:2222 => fetch input

I (184579) mbedtls: ssl_tls.c:2380 in_left: 5, nb_want: 37

I (184586) mbedtls: ssl_tls.c:2404 in_left: 5, nb_want: 37

I (184592) mbedtls: ssl_tls.c:2405 ssl->f_recv(_timeout)() returned 32 (-0xffffffe0)

I (184601) mbedtls: ssl_tls.c:2417 <= fetch input

I (184606) mbedtls: ssl_tls.c:1590 => decrypt buf

I (184612) mbedtls: ssl_tls.c:2065 <= decrypt buf

I (184617) mbedtls: ssl_tls.c:3975 <= read record

I (184623) mbedtls: ssl_tls.c:6724 <= read

* Closing connection 0

____________ Response BODY: ____________

============
Method: POST
============

--------------------------
Number of uploaded files: 1
    Number of GET params: 0
   Number of POST params: 3
--------------------------

===========
Debug info:
===========

-----------
POST DATA: 
-----------
Array
(
    [param1] => 1234
    [param2] => esp32
    [param3] => Test from ESP32
)
-----------
 GET DATA:  
-----------
Array
(
)
-----------
FILE DATA: 
-----------
Array
(
    [file] => Array
        (
            [name] => postpar.txt
            [type] => text/plain
            [tmp_name] => /tmp/phpjFUPo6
            [error] => 0
            [size] => 609
        )

)
-----------

=====================================
LoBo test server, 2017/05/17 02:44:36
=====================================

^^^^^^^^^^^^ Response BODY: ^^^^^^^^^^^^

Who is online

Users browsing this forum: No registered users and 4 guests