1
1
#include " ArduinoCellular.h"
2
2
#include " arduino_secrets.h"
3
3
4
-
5
4
ArduinoCellular cellular = ArduinoCellular();
6
5
7
- float lat = 0.00 ;
8
- float lon = 0.00 ;
9
-
10
-
11
6
void setup (){
12
7
Serial.begin (115200 );
13
8
while (!Serial);
9
+ cellular.setDebugStream (Serial); // Uncomment this line to enable debug output
14
10
cellular.begin ();
15
- cellular.connect (SECRET_GPRS_APN, SECRET_GPRS_LOGIN, SECRET_GPRS_PASSWORD, SECRET_PINNUMBER);
11
+
12
+ if (String (SECRET_PINNUMBER).length () > 0 && !cellular.unlockSIM (SECRET_PINNUMBER)){
13
+ Serial.println (" Failed to unlock SIM card." );
14
+ while (true ); // Stop here
15
+ }
16
+
17
+ Serial.println (" Connecting..." );
18
+ cellular.connect (SECRET_GPRS_APN, SECRET_GPRS_LOGIN, SECRET_GPRS_PASSWORD);
19
+ Serial.println (" Connected!" );
16
20
}
17
21
18
22
void loop () {
19
- if (Serial.available () > 0 ) {
20
- // Define a buffer to store incoming data. Adjust the size as needed.
21
- char incomingData[255 ]; // Adjust the size according to your needs
22
-
23
- // Read data from serial until newline is found
24
- int size = Serial.readBytesUntil (' \n ' , incomingData, sizeof (incomingData) - 1 ); // Leave space for null terminator
25
-
26
- // Null-terminate the string
27
- incomingData[size] = ' \0 ' ;
28
- // Call the sendATCommand function with the read data
29
- Serial.println (cellular.sendATCommand (GF (incomingData)));
30
- }
23
+ while (Serial.available () == 0 ); // Wait for user input
24
+
25
+ // Read data from serial until newline
26
+ String userInput = Serial.readStringUntil (' \n ' );
27
+
28
+ // Call the sendATCommand function with the read data
29
+ String response = cellular.sendATCommand (userInput.c_str ());
30
+ Serial.println (response);
31
31
}
0 commit comments