This repository has been archived by the owner on Jun 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathBasicTest_SoftSerial.ino
111 lines (91 loc) · 3.81 KB
/
BasicTest_SoftSerial.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/********************************************************************************
* Execute sanity check on the module and output version (software 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 <SoftwareSerial.h>
#include "SIM800L.h"
#define SIM800_RX_PIN 10
#define SIM800_TX_PIN 11
#define SIM800_RST_PIN 6
SIM800L* sim800l;
void setup() {
// Initialize Serial Monitor for debugging
Serial.begin(115200);
while(!Serial);
// Initialize a SoftwareSerial
SoftwareSerial* serial = new SoftwareSerial(SIM800_RX_PIN, SIM800_TX_PIN);
serial->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 *)serial, SIM800_RST_PIN, 200, 512);
// Equivalent line with the debug enabled on the Serial
//sim800l = new SIM800L((Stream *)serial, 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);
}
// Active echo mode (for some module, it is required)
sim800l->enableEchoMode();
Serial.println("Module ready");
// Print version
Serial.print("Module ");
Serial.println(sim800l->getVersion());
Serial.print("Firmware ");
Serial.println(sim800l->getFirmware());
// Print SIM card status
Serial.print(F("SIM status "));
Serial.println(sim800l->getSimStatus());
// 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() {
}