1 | #include <Wire.h>
|
---|
2 | #include <LSM303.h>
|
---|
3 | #include <GSM.h>
|
---|
4 |
|
---|
5 | LSM303 compass;
|
---|
6 | GSM_SMS sms;
|
---|
7 |
|
---|
8 | // PIN Number
|
---|
9 | #define PINNUMBER ""
|
---|
10 |
|
---|
11 | // char array of the message
|
---|
12 | //char txtMsg[200]= "Hello";
|
---|
13 |
|
---|
14 | // char array of the telephone number to send SMS
|
---|
15 | // change the number 1-212-555-1212 to a number
|
---|
16 | // you have access to
|
---|
17 | ///char destinationNumber[20]= "+4917687545809";
|
---|
18 |
|
---|
19 | // initialize the library instance
|
---|
20 | GSM gsmAccess(true); // include a 'true' parameter for debug enabled
|
---|
21 | GSMScanner scannerNetworks;
|
---|
22 | GSMModem modemTest;
|
---|
23 |
|
---|
24 | // Save data variables
|
---|
25 | String IMEI = "";
|
---|
26 |
|
---|
27 | // serial monitor result messages
|
---|
28 | String errortext = "ERROR";
|
---|
29 |
|
---|
30 | // Array to hold the number a SMS is retreived from
|
---|
31 | char senderNumber[20];
|
---|
32 |
|
---|
33 | void setup()
|
---|
34 | {
|
---|
35 |
|
---|
36 | Serial.begin(9600);
|
---|
37 | Wire.begin();
|
---|
38 | compass.init();
|
---|
39 | compass.enableDefault();
|
---|
40 |
|
---|
41 | // Calibration values. Use the Calibrate example program to get the values for
|
---|
42 | // your compass.
|
---|
43 | compass.m_min.x = -700; compass.m_min.y = -695; compass.m_min.z = -635;
|
---|
44 | compass.m_max.x = +293; compass.m_max.y = +551; compass.m_max.z = 606;
|
---|
45 |
|
---|
46 | // initialize serial communications
|
---|
47 | Serial.begin(9600);
|
---|
48 | Serial.println("GSM networks scanner");
|
---|
49 | scannerNetworks.begin();
|
---|
50 |
|
---|
51 | // connection state
|
---|
52 | boolean notConnected = true;
|
---|
53 |
|
---|
54 | // Start GSM shield
|
---|
55 | // If your SIM has PIN, pass it as a parameter of begin() in quotes
|
---|
56 | while(notConnected)
|
---|
57 | {
|
---|
58 | if(gsmAccess.begin(PINNUMBER)==GSM_READY)
|
---|
59 | notConnected = false;
|
---|
60 | else
|
---|
61 | {
|
---|
62 | Serial.println("Not connected");
|
---|
63 | delay(1000);
|
---|
64 | }
|
---|
65 | }
|
---|
66 |
|
---|
67 | // get modem parameters
|
---|
68 | // IMEI, modem unique identifier
|
---|
69 | Serial.print("Modem IMEI: ");
|
---|
70 | IMEI = modemTest.getIMEI();
|
---|
71 | IMEI.replace("\n","");
|
---|
72 | if(IMEI != NULL)
|
---|
73 | Serial.println(IMEI);
|
---|
74 |
|
---|
75 | // currently connected carrier
|
---|
76 | Serial.print("Current carrier: ");
|
---|
77 | Serial.println(scannerNetworks.getCurrentCarrier());
|
---|
78 |
|
---|
79 | // returns strength and ber
|
---|
80 | // signal strength in 0-31 scale. 31 means power > 51dBm
|
---|
81 | // BER is the Bit Error Rate. 0-7 scale. 99=not detectable
|
---|
82 | Serial.print("Signal Strength: ");
|
---|
83 | Serial.print(scannerNetworks.getSignalStrength());
|
---|
84 | Serial.println(" [0-31]");
|
---|
85 | }
|
---|
86 |
|
---|
87 | void loop()
|
---|
88 | {
|
---|
89 |
|
---|
90 | char c;
|
---|
91 |
|
---|
92 | // scan for existing networks, displays a list of networks
|
---|
93 | Serial.println("Scanning available networks. May take some seconds.");
|
---|
94 | Serial.println(scannerNetworks.readNetworks());
|
---|
95 |
|
---|
96 | // currently connected carrier
|
---|
97 | Serial.print("Current carrier: ");
|
---|
98 | Serial.println(scannerNetworks.getCurrentCarrier());
|
---|
99 |
|
---|
100 | // returns strength and ber
|
---|
101 | // signal strength in 0-31 scale. 31 means power > 51dBm
|
---|
102 | // BER is the Bit Error Rate. 0-7 scale. 99=not detectable
|
---|
103 | Serial.print("Signal Strength: ");
|
---|
104 | Serial.print(scannerNetworks.getSignalStrength());
|
---|
105 | Serial.println(" [0-31]");
|
---|
106 |
|
---|
107 | Serial.print("Outside the LOOP ");
|
---|
108 | Serial.println(scannerNetworks.getCurrentCarrier());
|
---|
109 |
|
---|
110 | if( scannerNetworks.getCurrentCarrier() == "Orange" )
|
---|
111 | {
|
---|
112 |
|
---|
113 | ////
|
---|
114 | // If there are any SMSs available()
|
---|
115 | if (sms.available())
|
---|
116 | {
|
---|
117 | Serial.println("Message received from:");
|
---|
118 |
|
---|
119 | // Get remote number
|
---|
120 | sms.remoteNumber(senderNumber, 20);
|
---|
121 | Serial.println(senderNumber);
|
---|
122 |
|
---|
123 | // An example of message disposal
|
---|
124 | // Any messages starting with # should be discarded
|
---|
125 | if(sms.peek()=='#')
|
---|
126 | {
|
---|
127 | Serial.println("Discarded SMS");
|
---|
128 | sms.flush();
|
---|
129 | }
|
---|
130 |
|
---|
131 | // Read message bytes and print them
|
---|
132 | while(c=sms.read())
|
---|
133 | Serial.print(c);
|
---|
134 |
|
---|
135 | Serial.println("\nEND OF MESSAGE");
|
---|
136 |
|
---|
137 | // Delete message from modem memory
|
---|
138 | sms.flush();
|
---|
139 | Serial.println("MESSAGE DELETED");
|
---|
140 |
|
---|
141 | compass.read();
|
---|
142 | int heading = compass.heading((LSM303::vector){0,-1,0});
|
---|
143 | Serial.print("Pointing: ");
|
---|
144 | Serial.println(heading);
|
---|
145 | Serial.println("SENDING!!!");
|
---|
146 | ///sendSMS();
|
---|
147 | ////SMS////
|
---|
148 | //Serial.print("Message to mobile number: ");
|
---|
149 | //Serial.println(senderNumber);
|
---|
150 | //char txtMsg[200];
|
---|
151 | //sprintf(txtMsg,"%d",heading);
|
---|
152 | //// sms text
|
---|
153 | //Serial.println("SENDING");
|
---|
154 | //Serial.println();
|
---|
155 | //Serial.println("Message:");
|
---|
156 | //Serial.println(txtMsg);
|
---|
157 | //// send the message
|
---|
158 | //sms.beginSMS(senderNumber);
|
---|
159 | //sms.print(txtMsg);
|
---|
160 | //sms.endSMS();
|
---|
161 | //Serial.println("\nCOMPLETE!\n");
|
---|
162 | ////!SMS////
|
---|
163 | for( ;; )
|
---|
164 | ;
|
---|
165 |
|
---|
166 |
|
---|
167 | } else
|
---|
168 | {
|
---|
169 | if(!gsmAccess.begin(PINNUMBER)==GSM_READY)
|
---|
170 | Serial.println("Not Connected!");
|
---|
171 | Serial.println("Scanning available networks. May take some seconds.");
|
---|
172 | Serial.println(scannerNetworks.readNetworks());
|
---|
173 | Serial.print("Waiting ... ");
|
---|
174 | Serial.print("Current carrier: ");
|
---|
175 | Serial.print(scannerNetworks.getCurrentCarrier());
|
---|
176 | Serial.print(" Signal Strength: ");
|
---|
177 | Serial.print(scannerNetworks.getSignalStrength());
|
---|
178 | Serial.println(" [0-31]");
|
---|
179 | delay(1000);
|
---|
180 |
|
---|
181 | }
|
---|
182 |
|
---|
183 | } else
|
---|
184 | {
|
---|
185 | Serial.println("Else Loop....");
|
---|
186 | }
|
---|
187 |
|
---|
188 |
|
---|
189 | }
|
---|
190 | /*
|
---|
191 | void sendSMS()
|
---|
192 | {
|
---|
193 |
|
---|
194 | Serial.print("Message to mobile number: ");
|
---|
195 | Serial.println(destinationNumber);
|
---|
196 |
|
---|
197 | // sms text
|
---|
198 | Serial.println("SENDING");
|
---|
199 | Serial.println();
|
---|
200 | Serial.println("Message:");
|
---|
201 | Serial.println(txtMsg);
|
---|
202 |
|
---|
203 | // send the message
|
---|
204 | sms.beginSMS(destinationNumber);
|
---|
205 | sms.print(txtMsg);
|
---|
206 | sms.endSMS();
|
---|
207 | Serial.println("\nCOMPLETE!\n");
|
---|
208 | }
|
---|
209 | */
|
---|