Skip to content

Commit d6b1204

Browse files
authored
Merge pull request #13 from sparkfun/add_first_examples
Add first examples
2 parents 6a73506 + 926ab5b commit d6b1204

File tree

7 files changed

+1077
-5
lines changed

7 files changed

+1077
-5
lines changed
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
#include "SparkFun_u-blox_Cellular_Arduino_Library.h"
2+
3+
// Uncomment the line below that you need for Serial on your platform
4+
#define mySerial Serial1
5+
// SoftwareSerial mySerial(16, 17);
6+
7+
// Uncomment the module you're using. If your module is not listed below, then
8+
// it's not supported for this example
9+
UBX_CELL myModule; // This example works with all modules, so the base class can be used
10+
// SARA_R5 myModule; // Base SARA-R5 class
11+
// SARA_R500S myModule;
12+
// SARA_R500S_01B myModule;
13+
// SARA_R500S_61B myModule;
14+
// SARA_R510M8S_61B myModule;
15+
// SARA_R510S myModule;
16+
// LARA_R6 myModule; // Base LARA-R6 class
17+
// LARA_R6001 myModule;
18+
// LARA_R6001D myModule;
19+
// LARA_R6401 myModule;
20+
// LARA_R6401D myModule;
21+
// LARA_R6801_00B myModule;
22+
// LARA_R6801D myModule;
23+
24+
// Map registration status messages to more readable strings
25+
String registrationString[] =
26+
{
27+
"Not registered", // 0
28+
"Registered, home", // 1
29+
"Searching for operator", // 2
30+
"Registration denied", // 3
31+
"Registration unknown", // 4
32+
"Registered, roaming", // 5
33+
"Registered, home (SMS only)", // 6
34+
"Registered, roaming (SMS only)", // 7
35+
"Registered, emergency service only", // 8
36+
"Registered, home, CSFB not preferred", // 9
37+
"Registered, roaming, CSFB not prefered" // 10
38+
};
39+
40+
// If you are based in Europe, you will (probably) need to select MNO_STD_EUROPE
41+
const mobile_network_operator_t MOBILE_NETWORK_OPERATOR = MNO_GLOBAL;
42+
43+
void setup()
44+
{
45+
Serial.begin(115200); // Start the serial console
46+
47+
// Wait for user to press key to begin
48+
Serial.println(F("u-blox Cellular Example 2 - Network Info"));
49+
Serial.println(F("Press any key to begin"));
50+
51+
while (!Serial.available()) // Wait for the user to press a key (send any serial character)
52+
;
53+
while (Serial.available()) // Empty the serial RX buffer
54+
Serial.read();
55+
56+
Serial.println(F("Beginning..."));
57+
58+
// myModule.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial
59+
60+
// For the MicroMod Asset Tracker, we need to invert the power pin so it pulls high instead of low
61+
// Uncomment the next line if required
62+
// myModule.invertPowerPin(true);
63+
64+
// Initialize the module
65+
if (myModule.begin(mySerial, UBX_CELL_DEFAULT_BAUD_RATE) )
66+
{
67+
Serial.println(F("Module connected!"));
68+
}
69+
else
70+
{
71+
Serial.println(F("Unable to communicate with the module."));
72+
Serial.println(F("Manually power-on (hold the module's On button for 3 seconds) and try again."));
73+
while (1) ; // Loop forever on fail
74+
}
75+
Serial.println();
76+
77+
if (!myModule.setNetworkProfile(MOBILE_NETWORK_OPERATOR))
78+
{
79+
Serial.println(F("Error setting network. Try cycling the power."));
80+
while (1) ;
81+
}
82+
83+
Serial.println(F("Network profile set. Ready to go!"));
84+
85+
// RSSI: Received signal strength:
86+
Serial.println("RSSI: " + String(myModule.rssi()));
87+
// Registration Status
88+
int regStatus = myModule.registration();
89+
if ((regStatus >= 0) && (regStatus <= 10))
90+
{
91+
Serial.println("Network registration: " + registrationString[regStatus]);
92+
}
93+
94+
// Print the Context IDs, Access Point Names and IP Addresses
95+
Serial.println(F("Available PDP (Packet Data Protocol) APNs (Access Point Names) and IP Addresses:"));
96+
Serial.println(F("Context ID:\tAPN Name:\tIP Address:"));
97+
for (int cid = 0; cid < UBX_CELL_NUM_PDP_CONTEXT_IDENTIFIERS; cid++)
98+
{
99+
String apn = "";
100+
IPAddress ip(0, 0, 0, 0);
101+
myModule.getAPN(cid, &apn, &ip);
102+
if (apn.length() > 0)
103+
{
104+
Serial.print(cid);
105+
Serial.print(F("\t\t"));
106+
Serial.print(apn);
107+
Serial.print(F("\t"));
108+
Serial.println(ip);
109+
}
110+
}
111+
112+
Serial.println();
113+
114+
if (regStatus > 0)
115+
{
116+
Serial.println(F("All set. Go to the next example!"));
117+
}
118+
}
119+
120+
void loop()
121+
{
122+
// Do nothing. Now that we're registered move on to the next example.
123+
}

0 commit comments

Comments
 (0)