This repository has been archived by the owner on Jan 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathSerialGSMPassthrough.ino
180 lines (142 loc) · 5.8 KB
/
SerialGSMPassthrough.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*********************************************************************************************************************************
SerialGSMSPassthrough.ino
For ESP8266, ESP32, SAMD21/SAMD51, nRF52, SAM DUE, Teensy and STM32 with GSM modules
GSM_Generic is a library for the ESP8266, ESP32, SAMD21/SAMD51, nRF52, SAM DUE, Teensy and STM32 with GSM modules
Based on and modified from MKRGSM Library (https://github.com/arduino-libraries/MKRGSM)
Built by Khoi Hoang https://github.com/khoih-prog/GSM_Generic
Licensed under GNU Lesser General Public License
Copyright (C) 2017 Arduino AG (http://www.arduino.cc/)
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation, either version 2.1 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program.
If not, see <https://www.gnu.org/licenses/>.
**********************************************************************************************************************************/
/*
SerialGSMPassthrough sketch
This sketch allows you to send AT commands from the USB CDC serial port
of the GSM module to the onboard ublox SARA-U201 celluar module.
For a list of supported AT commands see:
https://www.u-blox.com/sites/default/files/u-blox-CEL_ATCommands_%28UBX-13002752%29.pdf
Circuit:
- GSM module
- Antenna
- 1500 mAh or higher LIPO battery connected
- SIM card
Make sure the Serial Monitor's line ending is set to "Both NL and CR"
create 11 December 2017
Sandeep Mistry
*/
//////////////////////////////////////////////
#if defined(ARDUINO_SAMD_MKRGSM1400)
// For original MKRGSM1400 => GSM_MODEM_UBLOX == true, GSM_MODEM_LARAR2 == false
// For modified MKRGSM1400 using LARA R2 => GSM_MODEM_UBLOX == false, GSM_MODEM_LARAR2 == true
#define GSM_MODEM_UBLOX false
#if GSM_MODEM_UBLOX
#define GSM_MODEM_LARAR2 false
#else
#define GSM_MODEM_LARAR2 true
#endif
#define UBLOX_USING_RESET_PIN true
#define UBLOX_USING_LOW_POWER_MODE true
#if GSM_MODEM_UBLOX
#warning Using MKRGSM1400 Configuration with SARA U201
#elif GSM_MODEM_LARAR2
#warning Using MKRGSM1400 Configuration with LARA R2xx
#else
#error Must select either GSM_MODEM_UBLOX or GSM_MODEM_LARAR2
#endif
#else
// Optional usage of GSM_RESETN and GSM_DTR. Need to be here only when true. Default is false
#define UBLOX_USING_RESET_PIN true
#define UBLOX_USING_LOW_POWER_MODE true
// Override the default (and certainly not good) pins and port
// Only for boards other than ARDUINO_SAMD_MKRGSM1400
#if (ESP32)
#define GSM_RESETN (33u)
#define GSM_DTR (34u)
#elif (ESP8266)
#define GSM_RESETN (D3)
#define GSM_DTR (D4)
#else
#define GSM_RESETN (10u)
#define GSM_DTR (11u)
#endif
#if ESP8266
// Using Software Serial for ESP8266, as Serial1 is TX only
#define GSM_USING_SOFTWARE_SERIAL true
#else
// Optional Software Serial here for other boards, but not advised if HW Serial available
#define GSM_USING_SOFTWARE_SERIAL false
#endif
#if GSM_USING_SOFTWARE_SERIAL
#warning Using default SerialGSM = SoftwareSerial
#define D8 (15)
#define D7 (13)
#include <SoftwareSerial.h>
SoftwareSerial swSerial(D7, D8); // (D7, D8, false, 256); // (RX, TX, false, 256);
#define SerialGSM swSerial
#else
#warning Using default SerialGSM = HardwareSerial Serial1
#define SerialGSM Serial1
#endif // GSM_USING_SOFTWARE_SERIAL
#warning You must connect the Modem correctly and modify the pins / Serial port here
//////////////////////////////////////////////
#define GSM_MODEM_UBLOX true
#define GSM_MODEM_SARAR4 false
#define GSM_MODEM_LARAR2 false
//////////////////////////////////////////////
// Not supported yet
#define GSM_MODEM_SIM800 false
#define GSM_MODEM_SIM808 false
#define GSM_MODEM_SIM868 false
#define GSM_MODEM_SIM900 false
#define GSM_MODEM_SIM5300 false
#define GSM_MODEM_SIM5320 false
#define GSM_MODEM_SIM5360 false
#define GSM_MODEM_SIM7000 false
#define GSM_MODEM_SIM7100 false
#define GSM_MODEM_SIM7500 false
#define GSM_MODEM_SIM7600 false
#define GSM_MODEM_SIM7800 false
#define GSM_MODEM_M95 false
#define GSM_MODEM_BG96 false
#define GSM_MODEM_A6 false
#define GSM_MODEM_A7 false
#define GSM_MODEM_M590 false
#define GSM_MODEM_MC60 false
#define GSM_MODEM_MC60E false
#define GSM_MODEM_XBEE false
#define GSM_MODEM_SEQUANS_MONARCH false
//////////////////////////////////////////////
#endif
// libraries
#include <GSM_Generic_Main.h>
// baud rate used for both Serial ports
unsigned long baud = 115200;
void setup()
{
// reset the ublox module
pinMode(GSM_RESETN, OUTPUT);
digitalWrite(GSM_RESETN, HIGH);
delay(100);
digitalWrite(GSM_RESETN, LOW);
Serial.begin(baud);
SerialGSM.begin(baud);
}
void loop()
{
char c;
if (Serial.available())
{
c = Serial.read();
Serial.print(c);
//SerialGSM.write(Serial.read());
SerialGSM.write(c);
}
if (SerialGSM.available())
{
Serial.write(SerialGSM.read());
}
}