Skip to content

Commit

Permalink
Add support Client as reference in ESP_SSLClient2 class constructor.
Browse files Browse the repository at this point in the history
  • Loading branch information
mobizt committed Aug 16, 2023
1 parent ce6df21 commit 959243e
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 26 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,18 @@ This library is fully compatible and able to work with [ESP-Mail-Client](https:/
## Basic Usage
```cpp
#include <Arduino.h>
#if defined(ESP32) || defined(PICO_RP2040)
#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W)
#include <WiFi.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
#elif __has_include(<WiFiNINA.h>)
#include <WiFiNINA.h>
#elif __has_include(<WiFi101.h>)
#include <WiFi101.h>
#elif __has_include(<WiFiS3.h>)
#include <WiFiS3.h>
#endif

#include <ESP_SSLClient.h>

ESP_SSLClient ssl_client;
Expand Down
37 changes: 18 additions & 19 deletions examples/gsm/gsm.ino
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ const char apn[] = "YourAPN";
const char gprsUser[] = "";
const char gprsPass[] = "";


#include <TinyGsmClient.h>

#include <ESP_SSLClient.h>
Expand Down Expand Up @@ -124,24 +123,6 @@ void setup()
DBG(" setNetworkMode faill");
return;
}

// ignore server ssl certificate verification
ssl_client.setInsecure();

// Set the receive and transmit buffers size in bytes for memory allocation (512 to 16384).
ssl_client.setBufferSizes(1024 /* rx */, 512 /* tx */);

/** Call setDebugLevel(level) to set the debug
* esp_ssl_debug_none = 0
* esp_ssl_debug_error = 1
* esp_ssl_debug_warn = 2
* esp_ssl_debug_info = 3
* esp_ssl_debug_dump = 4
*/
ssl_client.setDebugLevel(1);

// assign the basic client
ssl_client.setClient(&basic_client);
}

void loop()
Expand Down Expand Up @@ -217,6 +198,24 @@ void loop()
}
#endif

// ignore server ssl certificate verification
ssl_client.setInsecure();

// Set the receive and transmit buffers size in bytes for memory allocation (512 to 16384).
ssl_client.setBufferSizes(1024 /* rx */, 512 /* tx */);

/** Call setDebugLevel(level) to set the debug
* esp_ssl_debug_none = 0
* esp_ssl_debug_error = 1
* esp_ssl_debug_warn = 2
* esp_ssl_debug_info = 3
* esp_ssl_debug_dump = 4
*/
ssl_client.setDebugLevel(1);

// assign the basic client
ssl_client.setClient(&basic_client);

Serial.println("---------------------------------");
Serial.print("Connecting to server...");

Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ESP_SSLClient",
"version": "2.1.3",
"version": "2.1.4",
"keywords": "communication, REST, esp32, esp8266, arduino",
"description": "This library provided the Secure Layer Networking (SSL/TLS) TCP Client for ESP8266, ESP32 and Raspberry Pi RP2040, Teensy, SAMD, AVR and other Arduino devices (except for avr) that support external networking interfaces e.g., WiFiClient, EthernetClient and GSMClient.",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name=ESP_SSLClient

version=2.1.3
version=2.1.4

author=Mobizt

Expand Down
37 changes: 33 additions & 4 deletions src/ESP_SSLClient.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
*
* The ESP SSL Client Class, ESP_SSLClient.h v2.1.3
* The ESP SSL Client Class, ESP_SSLClient.h v2.1.4
*
* Created August 13, 2023
* Created August 16, 2023
*
* The MIT License (MIT)
* Copyright (c) 2023 K. Suwatchai (Mobizt)
Expand Down Expand Up @@ -38,13 +38,42 @@
#if defined(USE_EMBED_SSL_ENGINE) || defined(USE_LIB_SSL_ENGINE)
#include "client/BSSL_TCP_Client.h"
class ESP_SSLClient : public BSSL_TCP_Client
{
public:
ESP_SSLClient(){};
~ESP_SSLClient(){};
};

class ESP_SSLClient2 : public BSSL_TCP_Client
{
public:
ESP_SSLClient2(Client &client, bool enableSSL = true) : _base_client(client)
{
setClient(&_base_client, enableSSL);
};
~ESP_SSLClient2(){};

private:
Client &_base_client;
};

#else
class ESP_SSLClient
#endif
{
public:
ESP_SSLClient(){};
~ESP_SSLClient(){};
};

#endif
class ESP_SSLClient2
{
public:
ESP_SSLClient2(Client &client, bool enableSSL = true) : _base_client(client){};
~ESP_SSLClient2(){};

private:
Client &_base_client;
};
#endif

#endif

0 comments on commit 959243e

Please sign in to comment.