|
| 1 | +/* |
| 2 | + Send an SMS with the SARA-R5 |
| 3 | + By: Paul Clark |
| 4 | + SparkFun Electronics |
| 5 | + Date: October 20th 2020 |
| 6 | +
|
| 7 | + Please see LICENSE.md for the license information |
| 8 | +
|
| 9 | + This example demonstrates how to send an SMS message with your MicroMod Asset Tracker Carrier Board. |
| 10 | +
|
| 11 | + Before uploading, set the DESTINATION_NUMBER constant to the |
| 12 | + phone number you want to send a text message to. |
| 13 | + (Don't forget to add an internation code (e.g. 1 for US)). |
| 14 | +
|
| 15 | + Once programmed, open the serial monitor, set the baud rate to 9600, |
| 16 | + and type a message to be sent via SMS. |
| 17 | + |
| 18 | + This code is intend to run on the MicroMod Asset Tracker Carrier Board |
| 19 | + using (e.g.) the MicroMod Artemis Processor Board |
| 20 | +
|
| 21 | + Select the SparkFun RedBoard Artemis ATP from the SparkFun Apollo3 boards |
| 22 | + |
| 23 | +*/ |
| 24 | + |
| 25 | +//Click here to get the library: http://librarymanager/All#SparkFun_u-blox_SARA-R5_Arduino_Library |
| 26 | +#include <SparkFun_u-blox_SARA-R5_Arduino_Library.h> |
| 27 | + |
| 28 | +// Uncomment the next line to connect to the SARA-R5 using hardware Serial1 |
| 29 | +#define saraSerial Serial1 |
| 30 | + |
| 31 | +// Uncomment the next line to create a SoftwareSerial object to pass to the SARA-R5 library instead |
| 32 | +//SoftwareSerial saraSerial(8, 9); |
| 33 | + |
| 34 | +// Create a SARA_R5 object to use throughout the sketch |
| 35 | +// We need to tell the library what GPIO pin is connected to the SARA power pin. |
| 36 | +// If you're using the MicroMod Asset Tracker and the MicroMod Artemis Processor Board, |
| 37 | +// the pin number is GPIO2 which is connected to AD34. TO DO: Check this! |
| 38 | +SARA_R5 assetTracker(34); |
| 39 | + |
| 40 | +// Set the cell phone number to be texted |
| 41 | +String DESTINATION_NUMBER = "11234567890"; |
| 42 | + |
| 43 | +void setup() { |
| 44 | + Serial.begin(9600); |
| 45 | + |
| 46 | + // Initialize the SARA |
| 47 | + if (assetTracker.begin(saraSerial, 9600)) |
| 48 | + { |
| 49 | + Serial.println(F("Asset Tracker (SARA-R5) connected!")); |
| 50 | + } |
| 51 | + else |
| 52 | + { |
| 53 | + Serial.println(F("Unable to communicate with the SARA.")); |
| 54 | + Serial.println(F("Manually power-on (hold POWER for 3 seconds) on and try again.")); |
| 55 | + while (1) ; // Loop forever on fail |
| 56 | + } |
| 57 | + Serial.println(); |
| 58 | + |
| 59 | + Serial.println(F("Type a message. Send a Newline (\\n) to send it...")); |
| 60 | +} |
| 61 | + |
| 62 | +void loop() { |
| 63 | + static String message = ""; |
| 64 | + if (Serial.available()) |
| 65 | + { |
| 66 | + char c = Serial.read(); |
| 67 | + // Read a message until a \n (newline) is received |
| 68 | + if (c == '\n') |
| 69 | + { |
| 70 | + // Once we receive a newline. send the text. |
| 71 | + Serial.println("Sending: \"" + String(message) + "\" to " + DESTINATION_NUMBER); |
| 72 | + // Call assetTracker.sendSMS(String number, String message) to send an SMS |
| 73 | + // message. |
| 74 | + assetTracker.sendSMS(DESTINATION_NUMBER, message); |
| 75 | + message = ""; // Clear message string |
| 76 | + } |
| 77 | + else |
| 78 | + { |
| 79 | + message += c; // Add last character to message |
| 80 | + } |
| 81 | + } |
| 82 | +} |
0 commit comments