[SIM800][WIP] Added SIM800 files
This commit is contained in:
parent
f9958ff83d
commit
7db24913cb
4 changed files with 121 additions and 0 deletions
41
examples/SIM800/SIM800_SMS_Send/SIM800_SMS_Send.ino
Normal file
41
examples/SIM800/SIM800_SMS_Send/SIM800_SMS_Send.ino
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
RadioLib SIM800 Send SMS Example
|
||||
*/
|
||||
|
||||
// include the library
|
||||
#include <RadioLib.h>
|
||||
|
||||
// SIM800 module is in slot A on the shield
|
||||
SIM800 gsm = RadioShield.ModuleA;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
||||
// initialize SIM800 with default settings
|
||||
Serial.print(F("[SIM800] Initializing ... "));
|
||||
// baudrate: 9600 baud
|
||||
// PIN: "1234"
|
||||
int state = gsm.begin(9600);
|
||||
if (state == ERR_NONE) {
|
||||
Serial.println(F("success!"));
|
||||
} else {
|
||||
Serial.print(F("failed, code "));
|
||||
Serial.println(state);
|
||||
while (true);
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// send SMS to number 0123456789
|
||||
Serial.print(F("[SIM800] Sending SMS ... "));
|
||||
int state = gsm.sendSMS("0123456789", "Hello World!");
|
||||
if (state == ERR_NONE) {
|
||||
Serial.println(F("success!"));
|
||||
} else {
|
||||
Serial.print(F("failed, code "));
|
||||
Serial.println(state);
|
||||
}
|
||||
|
||||
// wait 10 seconds before sending again
|
||||
delay(10000);
|
||||
}
|
|
@ -47,6 +47,7 @@
|
|||
#include "modules/RFM95.h"
|
||||
#include "modules/RFM96.h"
|
||||
#include "modules/RFM97.h"
|
||||
#include "modules/SIM800.h"
|
||||
#include "modules/SX1231.h"
|
||||
#include "modules/SX1261.h"
|
||||
#include "modules/SX1262.h"
|
||||
|
|
59
src/modules/SIM800.cpp
Normal file
59
src/modules/SIM800.cpp
Normal file
|
@ -0,0 +1,59 @@
|
|||
#include "SIM800.h"
|
||||
|
||||
SIM800::SIM800(Module* module) {
|
||||
_mod = module;
|
||||
}
|
||||
|
||||
int16_t SIM800::begin(long speed, const char* pin) {
|
||||
// set module properties
|
||||
_mod->AtLineFeed = "\r\n";
|
||||
_mod->baudrate = speed;
|
||||
_mod->init(USE_UART, INT_0);
|
||||
|
||||
// empty UART buffer (garbage data)
|
||||
_mod->ATemptyBuffer();
|
||||
|
||||
// power on
|
||||
pinMode(_mod->getInt0(), OUTPUT);
|
||||
digitalWrite(_mod->getInt0(), LOW);
|
||||
delay(1000);
|
||||
pinMode(_mod->getInt0(), INPUT);
|
||||
|
||||
// test AT setup
|
||||
if(!_mod->ATsendCommand("AT")) {
|
||||
return(ERR_AT_FAILED);
|
||||
}
|
||||
|
||||
// set phone functionality
|
||||
if(!_mod->ATsendCommand("AT+CFUN=1")) {
|
||||
return(ERR_AT_FAILED);
|
||||
}
|
||||
|
||||
// set SMS message format
|
||||
if(!_mod->ATsendCommand("AT+CMFG=1")) {
|
||||
return(ERR_AT_FAILED);
|
||||
}
|
||||
|
||||
// set PIN code
|
||||
char cmd[14];
|
||||
strcat(cmd, "AT+CPIN=\"");
|
||||
strcat(cmd, pin);
|
||||
strcat(cmd, "\"");
|
||||
if(!_mod->ATsendCommand(cmd)) {
|
||||
return(ERR_AT_FAILED);
|
||||
}
|
||||
|
||||
return(ERR_NONE);
|
||||
}
|
||||
|
||||
void SIM800::shutdown() {
|
||||
// power off
|
||||
pinMode(_mod->getInt0(), OUTPUT);
|
||||
digitalWrite(_mod->getInt0(), LOW);
|
||||
delay(1500);
|
||||
pinMode(_mod->getInt0(), INPUT);
|
||||
}
|
||||
|
||||
int16_t SIM800::sendSMS(const char* num, const char* msg) {
|
||||
|
||||
}
|
20
src/modules/SIM800.h
Normal file
20
src/modules/SIM800.h
Normal file
|
@ -0,0 +1,20 @@
|
|||
#ifndef _RADIOLIB_SIM800_H
|
||||
#define _RADIOLIB_SIM800_H
|
||||
|
||||
#include "Module.h"
|
||||
|
||||
class SIM800 {
|
||||
public:
|
||||
// constructor
|
||||
SIM800(Module* module);
|
||||
|
||||
// basic methods
|
||||
int16_t begin(long speed, const char* pin = "1234");
|
||||
void shutdown();
|
||||
int16_t sendSMS(const char* num, const char* msg);
|
||||
|
||||
private:
|
||||
Module* _mod;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Add table
Reference in a new issue