Skip to content

Commit 0f7a7ab

Browse files
committed
Simplify Modem Terminal Sketch
1 parent 82a1c6e commit 0f7a7ab

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

Diff for: examples/ModemTerminal/ModemTerminal.ino

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
#include "ArduinoCellular.h"
22
#include "arduino_secrets.h"
33

4-
54
ArduinoCellular cellular = ArduinoCellular();
65

7-
float lat = 0.00;
8-
float lon = 0.00;
9-
10-
116
void setup(){
127
Serial.begin(115200);
138
while (!Serial);
9+
cellular.setDebugStream(Serial); // Uncomment this line to enable debug output
1410
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!");
1620
}
1721

1822
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);
3131
}

0 commit comments

Comments
 (0)