Created
September 11, 2018 09:45
-
-
Save siredmar/d51ed0da5b24e5d87ba7f5528a88a74f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "credentials.h" | |
#include <Arduino.h> // for type definitions | |
#define TINY_GSM_MODEM_SIM800 | |
#include <SoftwareSerial.h> | |
SoftwareSerial SerialAT(10, 11); // RX, TX | |
//#define DUMP_AT_COMMANDS | |
#define TINY_GSM_DEBUG Serial | |
#include <TinyGsmClient.h> | |
#ifdef DUMP_AT_COMMANDS | |
#include <StreamDebugger.h> | |
StreamDebugger debugger(SerialAT, Serial); | |
TinyGsm* modem = new TinyGsm(debugger); | |
#else | |
TinyGsm* modem = new TinyGsm(SerialAT); | |
#endif | |
class Gsm | |
{ | |
public: | |
Gsm(TinyGsm* modem) | |
: modem(modem) | |
{ | |
} | |
bool sendSms(const char* text, const char* number) | |
{ | |
bool res = modem->sendSMS(String(number), String(text)); | |
DBG("SMS:", res ? "OK" : "fail"); | |
return res; | |
} | |
private: | |
TinyGsm* modem; | |
}; | |
Gsm gsm(modem); | |
void setup() | |
{ | |
Serial.begin(115200); | |
delay(10); | |
// Set your reset, enable, power pins here | |
pinMode(8, OUTPUT); | |
digitalWrite(8, LOW); | |
delay(1000); | |
digitalWrite(8, HIGH); | |
// Set GSM module baud rate | |
TinyGsmAutoBaud(SerialAT, 57600, 57600); | |
// Restart takes quite some time | |
// To skip it, call init() instead of restart() | |
DBG("Initializing modem ..."); | |
if (!modem->restart()) | |
{ | |
delay(10000); | |
return; | |
} | |
String modemInfo = modem->getModemInfo(); | |
DBG("Modem:", modemInfo); | |
// Unlock your SIM card with a PIN | |
modem->simUnlock(PIN); | |
delay(5000); | |
DBG("Waiting for network..."); | |
if (!modem->waitForNetwork()) | |
{ | |
delay(10000); | |
return; | |
} | |
if (modem->isNetworkConnected()) | |
{ | |
DBG("Network connected"); | |
} | |
#if 1 | |
// Not working! | |
gsm.sendSms(NUMBER, "Hallo Test"); | |
#else | |
// Working! | |
bool res = modem->sendSMS(NUMBER, "Hello Test"); | |
DBG("SMS:", res ? "OK" : "fail"); | |
#endif | |
} | |
void loop() | |
{ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment