You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
3.5 KiB

/********************************************************************************
* Execute sanity check on the module and output version (hardware serial) *
* *
* Author: Olivier Staquet *
* Last version available on https://github.com/ostaquet/Arduino-SIM800L-driver *
********************************************************************************
* MIT License
*
* Copyright (c) 2019 Olivier Staquet
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*******************************************************************************/
#include "SIM800L.h"
#define SIM800_RST_PIN 6
SIM800L* sim800l;
void setup() {
// Initialize Serial Monitor for debugging
Serial.begin(115200);
while(!Serial);
// Initialize the hardware Serial1
Serial1.begin(9600);
delay(1000);
// Initialize SIM800L driver with an internal buffer of 200 bytes and a reception buffer of 512 bytes, debug disabled
sim800l = new SIM800L((Stream *)&Serial1, SIM800_RST_PIN, 200, 512);
// Equivalent line with the debug enabled on the Serial
//sim800l = new SIM800L((Stream *)&Serial1, SIM800_RST_PIN, 200, 512, (Stream *)&Serial);
Serial.println("Start of test protocol");
// Wait until the module is ready to accept AT commands
while(!sim800l->isReady()) {
Serial.println(F("Problem to initialize AT command, retry in 1 sec"));
delay(1000);
}
Serial.println("Module ready");
// Print version
Serial.print("Module ");
Serial.println(sim800l->getVersion());
Serial.print("Firmware ");
Serial.println(sim800l->getFirmware());
// Print SIM card number
Serial.print("SIM card number ");
Serial.println(sim800l->getSimCardNumber());
// Wait for the GSM signal
uint8_t signal = sim800l->getSignal();
while(signal <= 0) {
delay(1000);
signal = sim800l->getSignal();
}
if(signal > 5) {
Serial.print(F("Signal OK (strenght: "));
} else {
Serial.print(F("Signal low (strenght: "));
}
Serial.print(signal);
Serial.println(F(")"));
delay(1000);
// Wait for operator network registration (national or roaming network)
NetworkRegistration network = sim800l->getRegistrationStatus();
while(network != REGISTERED_HOME && network != REGISTERED_ROAMING) {
delay(1000);
network = sim800l->getRegistrationStatus();
}
Serial.println(F("Network registration OK"));
Serial.println("End of test protocol");
}
void loop() {
}