From 0f7a7abf5e58d02be85eb158391cdad0c4617398 Mon Sep 17 00:00:00 2001 From: Sebastian Romero Date: Fri, 12 Apr 2024 10:01:16 +0200 Subject: [PATCH] Simplify Modem Terminal Sketch --- examples/ModemTerminal/ModemTerminal.ino | 36 ++++++++++++------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/examples/ModemTerminal/ModemTerminal.ino b/examples/ModemTerminal/ModemTerminal.ino index 7436d2e..b9ba519 100644 --- a/examples/ModemTerminal/ModemTerminal.ino +++ b/examples/ModemTerminal/ModemTerminal.ino @@ -1,31 +1,31 @@ #include "ArduinoCellular.h" #include "arduino_secrets.h" - ArduinoCellular cellular = ArduinoCellular(); -float lat = 0.00; -float lon = 0.00; - - void setup(){ Serial.begin(115200); while (!Serial); + cellular.setDebugStream(Serial); // Uncomment this line to enable debug output cellular.begin(); - cellular.connect(SECRET_GPRS_APN, SECRET_GPRS_LOGIN, SECRET_GPRS_PASSWORD, SECRET_PINNUMBER); + + if(String(SECRET_PINNUMBER).length() > 0 && !cellular.unlockSIM(SECRET_PINNUMBER)){ + Serial.println("Failed to unlock SIM card."); + while(true); // Stop here + } + + Serial.println("Connecting..."); + cellular.connect(SECRET_GPRS_APN, SECRET_GPRS_LOGIN, SECRET_GPRS_PASSWORD); + Serial.println("Connected!"); } void loop() { - if (Serial.available() > 0) { - // Define a buffer to store incoming data. Adjust the size as needed. - char incomingData[255]; // Adjust the size according to your needs - - // Read data from serial until newline is found - int size = Serial.readBytesUntil('\n', incomingData, sizeof(incomingData) - 1); // Leave space for null terminator - - // Null-terminate the string - incomingData[size] = '\0'; - // Call the sendATCommand function with the read data - Serial.println(cellular.sendATCommand(GF(incomingData))); - } + while(Serial.available() == 0); // Wait for user input + + // Read data from serial until newline + String userInput = Serial.readStringUntil('\n'); + + // Call the sendATCommand function with the read data + String response = cellular.sendATCommand(userInput.c_str()); + Serial.println(response); } \ No newline at end of file