Skip to content

Commit

Permalink
Merge pull request #104 from pennam/catM1
Browse files Browse the repository at this point in the history
Add CatM1ConnectionHandler to support Portenta CAT.M1/NB IoT GNSS Shield
  • Loading branch information
pennam authored Nov 27, 2023
2 parents bda78b7 + f6c1b06 commit 63872a1
Show file tree
Hide file tree
Showing 6 changed files with 193 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/compile-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ jobs:
platform-name: arduino:samd
- fqbn: "arduino:mbed:envie_m7"
platform-name: arduino:mbed
- fqbn: "arduino:mbed_portenta:envie_m7"
platform-name: arduino:mbed_portenta
- fqbn: "esp8266:esp8266:huzzah"
platform-name: esp8266:esp8266
- fqbn: "esp32:esp32:esp32"
Expand Down
2 changes: 2 additions & 0 deletions examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ GSMConnectionHandler conMan(SECRET_APN, SECRET_PIN, SECRET_GSM_USER, SECRET_GSM_
NBConnectionHandler conMan(SECRET_PIN);
#elif defined(BOARD_HAS_LORA)
LoRaConnectionHandler conMan(SECRET_APP_EUI, SECRET_APP_KEY);
#elif defined(BOARD_HAS_CATM1_NBIOT)
CatM1ConnectionHandler conMan(SECRET_APN, SECRET_PIN, SECRET_GSM_USER, SECRET_GSM_PASS);
#endif

void setup() {
Expand Down
1 change: 1 addition & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ GSMConnectionHandler KEYWORD1
NBConnectionHandler KEYWORD1
LoRaConnectionHandler KEYWORD1
EthernetConnectionHandler KEYWORD1
CatM1ConnectionHandler KEYWORD1

####################################################
# Methods and Functions (KEYWORD2)
Expand Down
99 changes: 99 additions & 0 deletions src/Arduino_CatM1ConnectionHandler.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
This file is part of ArduinoIoTCloud.
Copyright 2019 ARDUINO SA (http://www.arduino.cc/)
This software is released under the GNU General Public License version 3,
which covers the main part of arduino-cli.
The terms of this license can be found at:
https://www.gnu.org/licenses/gpl-3.0.en.html
You can be released from the requirements of the above licenses by purchasing
a commercial license. Buying such a license is mandatory if you want to modify or
otherwise use the software for commercial activities involving the Arduino
software without disclosing the source code of your own applications. To purchase
a commercial license, send an email to [email protected].
*/

/******************************************************************************
INCLUDE
******************************************************************************/

#include "Arduino_CatM1ConnectionHandler.h"

#ifdef BOARD_HAS_CATM1_NBIOT /* Only compile if the board has CatM1 BN-IoT */

/******************************************************************************
CTOR/DTOR
******************************************************************************/

CatM1ConnectionHandler::CatM1ConnectionHandler(const char * pin, const char * apn, const char * login, const char * pass, RadioAccessTechnologyType rat, uint32_t band, bool const keep_alive)
: ConnectionHandler{keep_alive, NetworkAdapter::GSM}
, _pin(pin)
, _apn(apn)
, _login(login)
, _pass(pass)
, _rat(rat)
, _band(band)
{

}

/******************************************************************************
PUBLIC MEMBER FUNCTIONS
******************************************************************************/

unsigned long CatM1ConnectionHandler::getTime()
{
return GSM.getTime();
}

/******************************************************************************
PROTECTED MEMBER FUNCTIONS
******************************************************************************/

NetworkConnectionState CatM1ConnectionHandler::update_handleInit()
{
return NetworkConnectionState::CONNECTING;
}

NetworkConnectionState CatM1ConnectionHandler::update_handleConnecting()
{
if(!GSM.begin(_pin, _apn, _login, _pass, _rat, _band))
{
Debug.print(DBG_ERROR, F("The board was not able to register to the network..."));
return NetworkConnectionState::ERROR;
}
Debug.print(DBG_INFO, F("Connected to Network"));
return NetworkConnectionState::CONNECTED;
}

NetworkConnectionState CatM1ConnectionHandler::update_handleConnected()
{
int const is_gsm_access_alive = GSM.isConnected();
if (is_gsm_access_alive != 1)
{
return NetworkConnectionState::DISCONNECTED;
}
return NetworkConnectionState::CONNECTED;
}

NetworkConnectionState CatM1ConnectionHandler::update_handleDisconnecting()
{
GSM.disconnect();
return NetworkConnectionState::DISCONNECTED;
}

NetworkConnectionState CatM1ConnectionHandler::update_handleDisconnected()
{
if (_keep_alive)
{
return NetworkConnectionState::INIT;
}
else
{
return NetworkConnectionState::CLOSED;
}
}

#endif /* #ifdef BOARD_HAS_CATM1_NBIOT */
71 changes: 71 additions & 0 deletions src/Arduino_CatM1ConnectionHandler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
This file is part of ArduinoIoTCloud.
Copyright 2019 ARDUINO SA (http://www.arduino.cc/)
This software is released under the GNU General Public License version 3,
which covers the main part of arduino-cli.
The terms of this license can be found at:
https://www.gnu.org/licenses/gpl-3.0.en.html
You can be released from the requirements of the above licenses by purchasing
a commercial license. Buying such a license is mandatory if you want to modify or
otherwise use the software for commercial activities involving the Arduino
software without disclosing the source code of your own applications. To purchase
a commercial license, send an email to [email protected].
*/

#ifndef ARDUINO_CATM1_CONNECTION_HANDLER_H_
#define ARDUINO_CATM1_CONNECTION_HANDLER_H_

/******************************************************************************
INCLUDE
******************************************************************************/

#include "Arduino_ConnectionHandler.h"


#ifdef BOARD_HAS_CATM1_NBIOT /* Only compile if the board has CatM1 BN-IoT */

/******************************************************************************
CLASS DECLARATION
******************************************************************************/

class CatM1ConnectionHandler : public ConnectionHandler
{
public:

CatM1ConnectionHandler(const char * pin, const char * apn, const char * login, const char * pass, RadioAccessTechnologyType rat = CATM1, uint32_t band = BAND_3 | BAND_20 | BAND_19, bool const keep_alive = true);


virtual unsigned long getTime() override;
virtual Client & getClient() override { return _gsm_client; };
virtual UDP & getUDP() override { return _gsm_udp; };


protected:

virtual NetworkConnectionState update_handleInit () override;
virtual NetworkConnectionState update_handleConnecting () override;
virtual NetworkConnectionState update_handleConnected () override;
virtual NetworkConnectionState update_handleDisconnecting() override;
virtual NetworkConnectionState update_handleDisconnected () override;


private:

const char * _pin;
const char * _apn;
const char * _login;
const char * _pass;

RadioAccessTechnologyType _rat;
uint32_t _band;

GSMUDP _gsm_udp;
GSMClient _gsm_client;
};

#endif /* #ifdef BOARD_HAS_CATM1_NBIOT */

#endif /* #ifndef ARDUINO_CATM1_CONNECTION_HANDLER_H_ */
28 changes: 18 additions & 10 deletions src/Arduino_ConnectionHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@
#ifndef ARDUINO_CONNECTION_HANDLER_H_
#define ARDUINO_CONNECTION_HANDLER_H_

/******************************************************************************
INCLUDES
******************************************************************************/

#if !defined(__AVR__)
# include <Arduino_DebugUtils.h>
#endif

#include <Arduino.h>

#ifdef ARDUINO_SAMD_MKR1000
Expand Down Expand Up @@ -48,9 +56,12 @@
#include <WiFiUdp.h>
#include <Ethernet.h>
#include <PortentaEthernet.h>
#include <GSM.h>

#define BOARD_HAS_WIFI
#define BOARD_HAS_ETHERNET
#define BOARD_HAS_CATM1_NBIOT
#define BOARD_HAS_PORTENTA_CATM1_NBIOT_SHIELD
#define BOARD_HAS_PORTENTA_VISION_SHIELD_ETHERNET
#define NETWORK_HARDWARE_ERROR WL_NO_SHIELD
#define NETWORK_IDLE_STATUS WL_IDLE_STATUS
Expand Down Expand Up @@ -157,14 +168,6 @@
#define WIFI_FIRMWARE_VERSION_REQUIRED WIFI_FIRMWARE_LATEST_VERSION
#endif

/******************************************************************************
INCLUDES
******************************************************************************/

#if !defined(__AVR__)
# include <Arduino_DebugUtils.h>
#endif

/******************************************************************************
TYPEDEFS
******************************************************************************/
Expand All @@ -190,7 +193,8 @@ enum class NetworkAdapter {
ETHERNET,
NB,
GSM,
LORA
LORA,
CATM1
};

typedef void (*OnNetworkEventCallback)();
Expand Down Expand Up @@ -226,7 +230,7 @@ class ConnectionHandler {

NetworkConnectionState check();

#if defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB) || defined(BOARD_HAS_ETHERNET)
#if defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB) || defined(BOARD_HAS_ETHERNET) || defined(BOARD_HAS_CATM1_NBIOT)
virtual unsigned long getTime() = 0;
virtual Client &getClient() = 0;
virtual UDP &getUDP() = 0;
Expand Down Expand Up @@ -289,4 +293,8 @@ class ConnectionHandler {
#include "Arduino_EthernetConnectionHandler.h"
#endif

#if defined(BOARD_HAS_CATM1_NBIOT)
#include "Arduino_CatM1ConnectionHandler.h"
#endif

#endif /* CONNECTION_HANDLER_H_ */

0 comments on commit 63872a1

Please sign in to comment.