Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
3 changes: 2 additions & 1 deletion examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
#define CONN_TOGGLE_MS 60000

#if !(defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_LORA) || \
defined(BOARD_HAS_NB) || defined(BOARD_HAS_ETHERNET) || defined(BOARD_HAS_CATM1_NBIOT))
defined(BOARD_HAS_NB) || defined(BOARD_HAS_ETHERNET) || defined(BOARD_HAS_CATM1_NBIOT) \
|| defined(BOARD_HAS_CELLULAR))
#error "Please check Arduino Connection Handler supported boards list: https://github.com/arduino-libraries/Arduino_ConnectionHandler/blob/master/README.md"
#endif

Expand Down
31 changes: 31 additions & 0 deletions src/CellularConnectionHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,40 @@ UDP & CellularConnectionHandler::getUDP()
PROTECTED MEMBER FUNCTIONS
******************************************************************************/

#if defined(ARDUINO_OPTA)
CellularExpansion ce;
static void beginOptaCellular() {
static bool first_call = true;

if(first_call) {
first_call = false;
OptaController.registerCustomExpansion(CellularExpansion::getProduct(),
CellularExpansion::makeExpansion,
CellularExpansion::startUp);
OptaController.begin();
delay(500);
for (int i = 0; i < OptaController.getExpansionNum(); i++) {
ce = OptaController.getExpansion(i);
if(ce) {
ce.ctrlModem(true);
delay(100);
break;
}
}
}
else {
OptaController.update();
}
}
#endif

NetworkConnectionState CellularConnectionHandler::update_handleInit()
{
#if defined(ARDUINO_OPTA) && defined(BOARD_HAS_CELLULAR)
beginOptaCellular();
#else
_cellular.begin();
#endif
_cellular.setDebugStream(Serial);
if (String(_pin).length() > 0 && !_cellular.unlockSIM(_pin)) {
Debug.print(DBG_ERROR, F("SIM not present or wrong PIN"));
Expand Down
8 changes: 7 additions & 1 deletion src/CellularConnectionHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

#if defined(ARDUINO_PORTENTA_C33) || defined(ARDUINO_PORTENTA_H7_M7)
#include <Arduino_Cellular.h>
#elif defined(ARDUINO_OPTA)
#include <Arduino_OptaCellular.h>
#endif

#ifndef BOARD_HAS_CELLULAR
Expand Down Expand Up @@ -57,8 +59,12 @@ class CellularConnectionHandler : public ConnectionHandler
const char * _apn;
const char * _login;
const char * _pass;


#if defined(ARDUINO_OPTA)
ArduinoCellular &_cellular = CellularExpansion::getCellular();
#else
ArduinoCellular _cellular;
#endif
TinyGsmClient _gsm_client = _cellular.getNetworkClient();
};

Expand Down
1 change: 1 addition & 0 deletions src/ConnectionHandlerDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
#if defined(ARDUINO_OPTA)
#define BOARD_HAS_WIFI
#define BOARD_HAS_ETHERNET
#define BOARD_HAS_CELLULAR
#define NETWORK_HARDWARE_ERROR WL_NO_SHIELD
#define NETWORK_IDLE_STATUS WL_IDLE_STATUS
#define NETWORK_CONNECTED WL_CONNECTED
Expand Down
Loading