At this moment I have tested something like:
ThingergGPRS.h:
#ifndef THINGER_GPRS_H
#define THINGER_GPRS_H
#include "ThingerClient.h"
class ThingerGPRS : public ThingerClient {
public:
ThingerGPRS(const char* user, const char* device, const char* device_credential, Stream& serial) :
apn_(NULL),
user_(NULL),
password_(NULL),
pin_(NULL),
modem_(serial),
client_(modem_),
lastModemCheck_(0),
ThingerClient(client_, user, device, device_credential)
{
}
~ThingerGPRS(){
}
protected:
virtual bool network_connected(){
return false;
}
virtual bool connect_network(){
if(apn_==NULL) {
THINGER_DEBUG("NETWORK", "Cannot connect without setting the APN!")
return false;
}
RegStatus regStatus = modem_.getRegistrationStatus();
THINGER_DEBUG_VALUE("NETWORK", "Network Status: ", regStatus)
if(regStatus==REG_UNKNOWN || regStatus==REG_UNREGISTERED){
THINGER_DEBUG("NETWORK", "Restarting Modem...")
modem_.restart();
THINGER_DEBUG("NETWORK", "Waiting for Network...")
if(!modem_.waitForNetwork()) {
THINGER_DEBUG("NETWORK", "Cannot connect network!")
return false;
}
THINGER_DEBUG("NETWORK", "Network Connected!")
}
THINGER_DEBUG("NETWORK", "Connecting to APN...")
if (!modem_.gprsConnect(apn_, user_, password_)) {
THINGER_DEBUG("NETWORK", "Cannot connect to APN!")
return false;
}
}
public:
TinyGsm& getTinyGsm(){
return modem_;
}
TinyGsmClient& getTinyGsmClient(){
return client_;
}
void setAPN(const char* APN, const char* user=NULL, const char* password=NULL){
apn_ = APN;
user_ = user;
password_ = password;
}
void setPIN(const char* PIN){
}
private:
const char* apn_;
const char* user_;
const char* password_;
const char* pin_;
TinyGsm modem_;
TinyGsmClient client_;
unsigned long lastModemCheck_;
bool connected_ = false;
};
#endif
And the Sketch:
// Select your modem:
#define TINY_GSM_MODEM_SIM800
//#define TINY_GSM_MODEM_SIM900
//#define TINY_GSM_MODEM_A6
//#define TINY_GSM_MODEM_M590
#define _DEBUG_
#include <TinyGsmClient.h>
#include <SoftwareSerial.h>
#include <ThingerGSM.h>
#define USERNAME ""
#define DEVICE_ID ""
#define DEVICE_CREDENTIAL ""
SoftwareSerial SerialAT(9, 8); // RX, TX
ThingerGPRS thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL, SerialAT);
void setup() {
// for logging
Serial.begin(115200);
// SerialAT
SerialAT.begin(38400);
// set APN
thing.setAPN("orangeworld", "orange", "orange");
// set PIN (optional)
// thing.setPin("1234");
pinMode(13, OUTPUT);
}
void loop() {
thing.handle();
}
And seems to work fine! I think something similar will be released soon!