Skip to content
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

Added createClient() methods to Sim7000 and Sim7000SSL (#623) #631

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/TinyGsmClientSIM7000.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ class TinyGsmSim7000 : public TinyGsmSim70xx<TinyGsmSim7000>,
init(&modem, mux);
}

virtual ~GsmClientSim7000() {
stop();
at->sockets[mux] = nullptr;
}

bool init(TinyGsmSim7000* modem, uint8_t mux = 0) {
this->at = modem;
sock_available = 0;
Expand All @@ -56,6 +61,19 @@ class TinyGsmSim7000 : public TinyGsmSim70xx<TinyGsmSim7000>,
}

public:

GsmClientSim7000* createClient() {
for (uint8_t idx = 0; idx < TINY_GSM_MUX_COUNT; idx++) {
if (!sockets[idx]) {
GsmClientSim7000* client = new GsmClientSim7000();
client->init(this, idx);
return client;
}
}
DBG(GF("ERROR: Cannot create client, TINYGSM_MUX_COUNT ["), TINY_GSM_MUX_COUNT, GF("] exceeded."));
return nullptr;
}

virtual int connect(const char* host, uint16_t port, int timeout_s) {
stop();
TINY_GSM_YIELD();
Expand Down
19 changes: 19 additions & 0 deletions src/TinyGsmClientSIM7000SSL.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ class TinyGsmSim7000SSL
init(&modem, mux);
}

virtual ~GsmClientSim7000SSL() {
stop();
at->sockets[mux] = nullptr;
}

bool init(TinyGsmSim7000SSL* modem, uint8_t mux = 0) {
this->at = modem;
sock_available = 0;
Expand Down Expand Up @@ -122,6 +127,20 @@ class TinyGsmSim7000SSL
certificates() {
memset(sockets, 0, sizeof(sockets));
}

GsmClientSim7000SSL* createClient(bool ssl = false) {
for (uint8_t idx = 0; idx < TINY_GSM_MUX_COUNT; idx++) {
if (!sockets[idx]) {
GsmClientSim7000SSL* client = ssl
? new GsmClientSecureSIM7000SSL()
: new GsmClientSim7000SSL();
client->init(this, idx);
return client;
}
}
DBG(GF("ERROR: Cannot create client, TINYGSM_MUX_COUNT ["), TINY_GSM_MUX_COUNT, GF("] exceeded."));
return nullptr;
}

/*
* Basic functions
Expand Down