TL;DR: The module is finnicky, only works near windows or outdoors, and to make it work its all trial and error with the linked datasheet
So it took a lot of trial and error, and a lot of searching, but my friend and I finally got it working. It took a lot of sifting through datasheets to see what changed what, especially this one.
A76XX Series_AT_Command_Manual_V1.06.pdf (3.1 MB)
By the way, Chat GPT was helpful in explaining what each command was about. I think the code I ended up with should work with you.
#include <SoftwareSerial.h>
int hallSensorPin = 4;
int state;
char msg = '1';
int startPos;
int endPos;
String number = "+123456789"; //put your number here, as well as the correct country code
SoftwareSerial SIM7670Serial(2, 3); // RX, TX
String sendATCommand(const char* cmd, const char* expectedResponse, unsigned long timeout) {
SIM7670Serial.println(cmd);
String response = "";
response.reserve(50);
unsigned long startTime = millis();
bool responseOK = false;
while (millis() - startTime < timeout) {
while (SIM7670Serial.available() > 0) {
char c = SIM7670Serial.read();
response += c;
}
if (response.indexOf(expectedResponse) != -1) {
responseOK = true;
break;
}
}
return response;
}
void setup() {
pinMode(hallSensorPin, INPUT);
Serial.begin(115200);
SIM7670Serial.begin(115200);
sendATCommand("AT+CGNSSPWR=1", "OK", 1000);
sendATCommand("AT+CGMM", "OK", 1000);
sendATCommand("AT+CMGF=1", "OK", 1000);
sendATCommand("AT+CMGD=,1", "OK", 1000);
sendATCommand("AT+CGNSSMODE=1", "OK", 1000);
}
void sendSMS(String number, String message) {
String cmd = "AT+CMGS=\"" + number + "\"\r\n";
SIM7670Serial.print(cmd);
delay(100);
SIM7670Serial.println(message);
delay(100);
SIM7670Serial.write(0x1A);
delay(100);
}
String getGPS(){
String lat = "";
String log = "-";
bool digit = true;
do {
String r = sendATCommand("AT+CGNSSPWR=1", "OK", 1000);
lat = "";
log = "-";
digit = true;
String location = sendATCommand("AT+CGNSSINFO", "OK", 2000);
Serial.println(location);
int logIndex = location.indexOf('W') - 11;
for(int i = logIndex; i < logIndex + 9; i++){
log += location[i];
if (!(isDigit(location[i])) && location[i] != '.'){
digit = false;
break;
}
}
if (digit){
int latIndex = logIndex - 13;
for (int i = latIndex; i < logIndex - 3; i++){
lat += location[i];
if (!(isDigit(location[i])) && location[i] != '.'){
digit = false;
break;
}
}
}
} while(!digit);
Serial.println("acquired");
String link = "https://www.google.com/maps/place/" + lat + ',' + log;
return link;
}
void checkSMS() {
String reply = sendATCommand("AT+CMGR=1", "OK", 1000);
int check = reply.indexOf("Gps");
int check1 = reply.indexOf("gps");
int check2 = reply.indexOf("GPS");
if (check < 0 || check1 < 0 || check2 < 0){
String reply = sendATCommand("AT+CMGR=1", "OK", 1000);
int check = reply.indexOf("Gps");
int check1 = reply.indexOf("gps");
int check2 = reply.indexOf("GPS");
}
sendATCommand("AT+CMGD=,1", "OK", 1000);
if (check > 0 || check1 > 0 || check2 > 0){
Serial.println("recieved");
String link = getGPS();
sendSMS(number, link);
Serial.println("sent");
}
delay(1000);
}
void loop() {
state = digitalRead(hallSensorPin);
Serial.println(state);
if (state == LOW && msg == '1') {
Serial.println("closed");
sendSMS(number, "Your door has been closed.");
Serial.println("Sent");
msg = '0';
}
else if (state == HIGH && msg == '0'){
msg = '1';
Serial.println("opened");
String link = "Your door has been opened: " + getGPS();
sendSMS(number, link);
Serial.println("sent");
}
checkSMS();
}`
It basically senses the state of a hall sensor (which senses a magnet on a door), and when the door opens or closes, it sends the corresponding message. I believe I put an AT COMMAND that resets the module at the top of the sendATCommand function, but I can't find that file.
Anyway, the module only works when out in the open, near a window, and/or when it feels like it! I don't know why but sometimes it just decides not to work, and then will be fine in a couple of minutes without any change. The blue GPS light on it is key, when it is stably on, then everything works, but when it is off, even sending messages doesn't work.
By the way for some reason it got attached to one of my SIM cards and did not work with the other one, which was a pain as it was only the other one that had working international text messages. I don't know what inspired me, but I managed to trick it by letting it register the first fingerprint, and as it was looking for GPS, in between one of the delays I quickly swapped SIM cards and it worked. I don't advise this though, I have no idea of the risks.
Good luck, hope you manage to make it work! Feel free to ask any further questions, although I am in no means an expert.