Skip to content
Snippets Groups Projects
Verified Commit f7e96560 authored by Zoe Michaela Dietmar Pfister's avatar Zoe Michaela Dietmar Pfister :gay_pride_flag:
Browse files

WIP: ConnectionManager updates

parent eee83fc3
No related branches found
No related tags found
2 merge requests!39Merge Develop into Main,!23NTP Refactor into dev
...@@ -8,8 +8,8 @@ ...@@ -8,8 +8,8 @@
#include <utility> #include <utility>
ConnectionManager::ConnectionManager(TinyGsm &client, GPRSCredentials credentials) ConnectionManager::ConnectionManager(TinyGsm &modem, GPRSCredentials credentials)
: modem(client), credentials(std::move(credentials)) {} : modem(modem), credentials(std::move(credentials)) {}
void ConnectionManager::restartModem() { void ConnectionManager::restartModem() {
// Restart takes quite some time // Restart takes quite some time
...@@ -24,10 +24,7 @@ void ConnectionManager::restartModem() { ...@@ -24,10 +24,7 @@ void ConnectionManager::restartModem() {
void ConnectionManager::initModem() { void ConnectionManager::initModem() {
esp_log_write(ESP_LOG_DEBUG, TAG_GSM.c_str(), "Initializing modem...\n"); esp_log_write(ESP_LOG_DEBUG, TAG_GSM.c_str(), "Initializing modem...\n");
if (!modem.init()) { if (!modem.init()) {
esp_log_write(ESP_LOG_WARN, TAG_GSM.c_str(), esp_log_write(ESP_LOG_WARN, TAG_GSM.c_str(), "Failed to initialize modem, attempting to continue...\n");
"Failed to initialize modem, attempting to continue by restarting\n");
// might not be the cleanest design
restartModem();
} }
setModemFunctionalityLevel(MINIMAL); setModemFunctionalityLevel(MINIMAL);
} }
...@@ -37,7 +34,7 @@ void ConnectionManager::setModemFunctionalityLevel( ...@@ -37,7 +34,7 @@ void ConnectionManager::setModemFunctionalityLevel(
// functionality is where the highest // functionality is where the highest
// level of power is drawn. Minimum functionality (default) is where the lowest level of power is drawn. // level of power is drawn. Minimum functionality (default) is where the lowest level of power is drawn.
// https://m2msupport.net/m2msupport/atcfun-set-phone-functionality/ // https://m2msupport.net/m2msupport/atcfun-set-phone-functionality/
modem.sendAT(("+CFUN=" + std::to_string(ModemFunctionalityLevel::MINIMAL) + " ").c_str()); modem.sendAT(("+CFUN=" + std::to_string(functionalityLevel) + " ").c_str());
if (modem.waitResponse(10000L) != 1) { if (modem.waitResponse(10000L) != 1) {
DBG(" +CFUN=0 false "); DBG(" +CFUN=0 false ");
} }
...@@ -73,20 +70,15 @@ void ConnectionManager::setNetworkMode(NetworkMode networkMode) { ...@@ -73,20 +70,15 @@ void ConnectionManager::setNetworkMode(NetworkMode networkMode) {
DBG("setNetworkMode false "); DBG("setNetworkMode false ");
throw LTEConnectionException("Failed to set network mode"); throw LTEConnectionException("Failed to set network mode");
} }
delay(200);
} }
void ConnectionManager::setPreferredMode(Mode mode) { void ConnectionManager::setPreferredMode(Mode mode) {
/*AT+CBANDCFG=<mode>,<band>[,<band>…] String res;
* <mode> "CAT-M" "NB-IOT" res = modem.setPreferredMode(mode);
* <band> The value of <band> must is in the band list of getting from AT+CBANDCFG=? if (res != "1") {
* For example, my SIM card carrier "NB-iot" supports B8. I will configure +CBANDCFG= "Nb-iot ",8 DBG("setPreferredMode false ");
*/ return;
modem.sendAT("+CBANDCFG=\"CAT-M\",8 ");
if (modem.waitResponse(10000L) != 1) {
DBG(" +CBANDCFG=\"NB-IOT\" ");
} }
delay(200);
} }
void ConnectionManager::setBand(BandMode bandMode, int band) { void ConnectionManager::setBand(BandMode bandMode, int band) {
/*AT+CBANDCFG=<mode>,<band>[,<band>…] /*AT+CBANDCFG=<mode>,<band>[,<band>…]
...@@ -101,7 +93,6 @@ void ConnectionManager::setBand(BandMode bandMode, int band) { ...@@ -101,7 +93,6 @@ void ConnectionManager::setBand(BandMode bandMode, int band) {
if (modem.waitResponse(10000L) != 1) { if (modem.waitResponse(10000L) != 1) {
DBG(" +CBANDCFG=\"NB-IOT\" "); DBG(" +CBANDCFG=\"NB-IOT\" ");
} }
delay(200);
} }
bool ConnectionManager::gprsConnect() { bool ConnectionManager::gprsConnect() {
return modem.gprsConnect(credentials.apn.c_str(), credentials.user.c_str(), credentials.password.c_str()); return modem.gprsConnect(credentials.apn.c_str(), credentials.user.c_str(), credentials.password.c_str());
...@@ -109,9 +100,9 @@ bool ConnectionManager::gprsConnect() { ...@@ -109,9 +100,9 @@ bool ConnectionManager::gprsConnect() {
bool ConnectionManager::isNetworkConnected() { bool ConnectionManager::isNetworkConnected() {
return modem.isNetworkConnected(); return modem.isNetworkConnected();
} }
std::string ConnectionManager::connect(const std::string &host, int port, RequestInformation requestInformation) { std::string ConnectionManager::connect(int port, RequestInformation requestInformation) {
TinyGsmClient client{modem}; TinyGsmClient client{modem};
if (!client.connect(host.c_str(), port)) { if (!client.connect(requestInformation.host.c_str(), port)) {
throw LTEConnectionException("Failed to connect to host"); throw LTEConnectionException("Failed to connect to host");
} }
......
...@@ -23,9 +23,9 @@ class ConnectionManager { ...@@ -23,9 +23,9 @@ class ConnectionManager {
const GPRSCredentials credentials; const GPRSCredentials credentials;
public: public:
ConnectionManager(TinyGsm &client, GPRSCredentials credentials); ConnectionManager(TinyGsm &modem, GPRSCredentials credentials);
std::string connect(const std::string &host, int port, RequestInformation requestInformation); std::string connect(int port, RequestInformation requestInformation);
void enableGPS(); void enableGPS();
......
...@@ -6,10 +6,17 @@ ...@@ -6,10 +6,17 @@
#define HOST_CENTRAL_MAST_GPRSCREDENTIALS_H #define HOST_CENTRAL_MAST_GPRSCREDENTIALS_H
#include <string> #include <string>
#include <utility>
struct GPRSCredentials { struct GPRSCredentials {
std::string apn; std::string apn;
std::string user; std::string user;
std::string password; std::string password;
GPRSCredentials(std::string apn, std::string user, std::string password) {
this->apn = std::move(apn);
this->user = std::move(user);
this->password = std::move(password);
}
}; };
#endif //HOST_CENTRAL_MAST_GPRSCREDENTIALS_H #endif //HOST_CENTRAL_MAST_GPRSCREDENTIALS_H
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment