~repos /remote-monitor
git clone https://pyrossh.dev/repos/remote-monitor.git
Remote Monitoring and Control using GSM-SMS
534f1c7a
—
pyros2097 12 years ago
v1.01 Final Version All checked
- IMG_20130609_195037.jpg +0 -0
- IMG_20130609_195048.jpg +0 -0
- IMG_20130609_195739.jpg +0 -0
- IMG_20130609_195751.jpg +0 -0
- RemoteMonitor.ino +561 -0
- RemoteMonitorApp/.classpath +9 -0
- RemoteMonitorApp/.project +33 -0
- RemoteMonitorApp/.settings/org.eclipse.jdt.core.prefs +4 -0
- RemoteMonitorApp/AndroidManifest.xml +29 -0
- RemoteMonitorApp/bin/AndroidManifest.xml +29 -0
- RemoteMonitorApp/bin/RemoteMonitor.apk +0 -0
- RemoteMonitorApp/bin/classes.dex +0 -0
- RemoteMonitorApp/bin/classes/com/pyros2097/remoteMonitor/BuildConfig.class +0 -0
- RemoteMonitorApp/bin/classes/com/pyros2097/remoteMonitor/R$attr.class +0 -0
- RemoteMonitorApp/bin/classes/com/pyros2097/remoteMonitor/R$drawable.class +0 -0
- RemoteMonitorApp/bin/classes/com/pyros2097/remoteMonitor/R$id.class +0 -0
- RemoteMonitorApp/bin/classes/com/pyros2097/remoteMonitor/R$layout.class +0 -0
- RemoteMonitorApp/bin/classes/com/pyros2097/remoteMonitor/R$string.class +0 -0
- RemoteMonitorApp/bin/classes/com/pyros2097/remoteMonitor/R.class +0 -0
- RemoteMonitorApp/bin/classes/com/pyros2097/remoteMonitor/SMSTest$1.class +0 -0
- RemoteMonitorApp/bin/classes/com/pyros2097/remoteMonitor/SMSTest$2.class +0 -0
- RemoteMonitorApp/bin/classes/com/pyros2097/remoteMonitor/SMSTest$3.class +0 -0
- RemoteMonitorApp/bin/classes/com/pyros2097/remoteMonitor/SMSTest$4.class +0 -0
- RemoteMonitorApp/bin/classes/com/pyros2097/remoteMonitor/SMSTest$5.class +0 -0
- RemoteMonitorApp/bin/classes/com/pyros2097/remoteMonitor/SMSTest$6.class +0 -0
- RemoteMonitorApp/bin/classes/com/pyros2097/remoteMonitor/SMSTest$7.class +0 -0
- RemoteMonitorApp/bin/classes/com/pyros2097/remoteMonitor/SMSTest$8.class +0 -0
- RemoteMonitorApp/bin/classes/com/pyros2097/remoteMonitor/SMSTest.class +0 -0
- RemoteMonitorApp/bin/classes/com/pyros2097/remoteMonitor/SmsReceiver.class +0 -0
- RemoteMonitorApp/bin/res/drawable-hdpi/icon.png +0 -0
- RemoteMonitorApp/bin/res/drawable-ldpi/icon.png +0 -0
- RemoteMonitorApp/bin/res/drawable-mdpi/icon.png +0 -0
- RemoteMonitorApp/bin/resources.ap_ +0 -0
- RemoteMonitorApp/gen/com/pyros2097/remoteMonitor/BuildConfig.java +6 -0
- RemoteMonitorApp/gen/com/pyros2097/remoteMonitor/R.java +41 -0
- RemoteMonitorApp/lint.xml +6 -0
- RemoteMonitorApp/project.properties +14 -0
- RemoteMonitorApp/res/drawable-hdpi/icon.png +0 -0
- RemoteMonitorApp/res/drawable-ldpi/icon.png +0 -0
- RemoteMonitorApp/res/drawable-mdpi/icon.png +0 -0
- RemoteMonitorApp/res/layout/main.xml +185 -0
- RemoteMonitorApp/res/values/strings.xml +5 -0
- RemoteMonitorApp/src/com/pyros2097/remoteMonitor/SMSTest.java +202 -0
- RemoteMonitorApp/src/com/pyros2097/remoteMonitor/SmsReceiver.java +53 -0
- Screenshot_2013-06-07-20-33-12.png +0 -0
- Screenshot_2013-06-07-20-33-31.png +0 -0
- Screenshot_2013-06-09-21-22-02.png +0 -0
- block.png +0 -0
- flow1.png +0 -0
- flow2.png +0 -0
- flow3.png +0 -0
- remotemonitor.png +0 -0
- snap.png +0 -0
- snap2.png +0 -0
IMG_20130609_195037.jpg
ADDED
|
Binary file
|
IMG_20130609_195048.jpg
ADDED
|
Binary file
|
IMG_20130609_195739.jpg
ADDED
|
Binary file
|
IMG_20130609_195751.jpg
ADDED
|
Binary file
|
RemoteMonitor.ino
ADDED
|
@@ -0,0 +1,561 @@
|
|
|
1
|
+
/* ********************************************************
|
|
2
|
+
Title: Remote Monitoring and Control using GSM-SMS
|
|
3
|
+
Author: Peter John
|
|
4
|
+
Date: 8th June 2013
|
|
5
|
+
Version: v1.01
|
|
6
|
+
***********************************************************/
|
|
7
|
+
#include <Bounce.h>
|
|
8
|
+
#include <Metro.h>
|
|
9
|
+
#include <SHT1x.h>
|
|
10
|
+
#include <EEPROM.h>
|
|
11
|
+
#include <EEPROMData.h>
|
|
12
|
+
|
|
13
|
+
/** IO Pins **/
|
|
14
|
+
/* Leds For Status Checking */
|
|
15
|
+
const int ledOrange = 13; // Teensy 3.0 has LED on 13
|
|
16
|
+
const int ledGreen = 16;
|
|
17
|
+
const int ledRed = 15;
|
|
18
|
+
const int ledBlue = 14;
|
|
19
|
+
/* States for each LED */
|
|
20
|
+
int ledOrangeState = LOW; // Orange indicates Board Running
|
|
21
|
+
int ledGreenState = LOW; // Green indicates Success
|
|
22
|
+
int ledRedState = LOW; // Red indicates Error
|
|
23
|
+
int ledBlueState = LOW; // Blue indicates Network Connected and SIM Present and Ready
|
|
24
|
+
/* Timers for each LED */
|
|
25
|
+
Metro ledOrangeBlink = Metro(1000); // Led Blink Event Timer
|
|
26
|
+
|
|
27
|
+
/* Buzzer for Alarms */
|
|
28
|
+
const int buzzerPin = 23;
|
|
29
|
+
|
|
30
|
+
/* Debouncer for Button 1 and 2*/
|
|
31
|
+
const int btn1Pin = 12;
|
|
32
|
+
Bounce btn1 = Bounce(btn1Pin, 10); // 10 ms debounce
|
|
33
|
+
const int btn2Pin = 11;
|
|
34
|
+
Bounce btn2 = Bounce(btn2Pin, 10); // 10 ms debounce
|
|
35
|
+
|
|
36
|
+
/** Temperature Variables **/
|
|
37
|
+
const int tempPin = A3; //17
|
|
38
|
+
Metro tempReadTimer = Metro(2000); // Temperature Read Event Timer
|
|
39
|
+
float tempC = 0;
|
|
40
|
+
float voltage = 0;
|
|
41
|
+
int readValue = 0;
|
|
42
|
+
float tempSetPoint = 40.00; // 40.00 degrees celsius
|
|
43
|
+
|
|
44
|
+
/** Humidity Variables **/
|
|
45
|
+
const int humidityDataPin = 20;
|
|
46
|
+
const int humidityClkPin = 21;
|
|
47
|
+
Metro humidityReadTimer = Metro(2000); // Humidity Read Event Timer
|
|
48
|
+
float humidityRH = 0;
|
|
49
|
+
SHT1x sht1x(humidityDataPin, humidityClkPin);
|
|
50
|
+
|
|
51
|
+
/** Temperature Control Variables **/
|
|
52
|
+
enum {AUTO, MAN};
|
|
53
|
+
boolean tempMode = AUTO;
|
|
54
|
+
boolean running = true; // Initially Heater is Running
|
|
55
|
+
int relayState = HIGH; // Initially Relay is ON
|
|
56
|
+
const int relayPin = 19; // Relay is on pin 19
|
|
57
|
+
|
|
58
|
+
/** Serial Port Received Strings **/
|
|
59
|
+
String inputString = ""; // Incoming data from GSM
|
|
60
|
+
Metro commTimer = Metro(10000); // Red Led Blink Event Timer
|
|
61
|
+
boolean commError = false;
|
|
62
|
+
boolean simReady = false;
|
|
63
|
+
boolean netReady = false;
|
|
64
|
+
Metro statusTimer = Metro(10000); // Blue Led Event Timer
|
|
65
|
+
char charBuf[15];
|
|
66
|
+
String mobileNo = "9036658002";
|
|
67
|
+
void sendMessage(String a,float b);
|
|
68
|
+
|
|
69
|
+
/* Setup Function
|
|
70
|
+
This function runs just once during the startup of the Board
|
|
71
|
+
1.The serialport buffer is reserved 100 bytes of memory
|
|
72
|
+
2.All Digital Pins are configured as INPUT/INPUT_PULLUP/OUTPUT
|
|
73
|
+
3.Serial Port to PC is initialized at 9600 baud rate
|
|
74
|
+
4.Serial Port to GSM Module is initialized at 9600 baud rate
|
|
75
|
+
5.ALL LEDS are on for about 10 seconds indicating the board is switched ON
|
|
76
|
+
6.Recieve Notification of GSM Modem is Set
|
|
77
|
+
*/
|
|
78
|
+
void setup() {
|
|
79
|
+
inputString.reserve(100);
|
|
80
|
+
pinMode(btn1Pin, INPUT_PULLUP);
|
|
81
|
+
pinMode(btn2Pin, INPUT_PULLUP);
|
|
82
|
+
pinMode(buzzerPin, OUTPUT);
|
|
83
|
+
pinMode(ledOrange, OUTPUT); // initialize the digital pin as an output.
|
|
84
|
+
pinMode(ledGreen, OUTPUT); // initialize the digital pin as an output.
|
|
85
|
+
pinMode(ledRed, OUTPUT); // initialize the digital pin as an output.
|
|
86
|
+
pinMode(ledBlue, OUTPUT); // initialize the digital pin as an output.
|
|
87
|
+
pinMode(relayPin, OUTPUT); // initialize the digital pin as an output.
|
|
88
|
+
Serial.begin(9600); // Serial port to the computer
|
|
89
|
+
Serial2.begin(9600); // Serial port to GSM Module
|
|
90
|
+
blink(ledOrange, ledOrangeState);
|
|
91
|
+
blink(ledGreen, ledGreenState);
|
|
92
|
+
blink(ledRed, ledRedState);
|
|
93
|
+
blink(ledBlue, ledBlueState);
|
|
94
|
+
startupAlarm();
|
|
95
|
+
delay(10000);
|
|
96
|
+
Serial2.println("ATE0"); //Switch off ECHO
|
|
97
|
+
delay(100);
|
|
98
|
+
Serial2.println("AT+CNMI=1,2,0,0,0");// Notify message directly
|
|
99
|
+
delay(50);
|
|
100
|
+
blink(ledGreen, ledGreenState);
|
|
101
|
+
blink(ledRed, ledRedState);
|
|
102
|
+
blink(ledRed, ledBlueState);
|
|
103
|
+
beep();
|
|
104
|
+
twoposControl();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/* Loop Function
|
|
108
|
+
This function runs over and over again as long as the board has power
|
|
109
|
+
1.The GSM Modem is first Checked for proper connectivity
|
|
110
|
+
1.The Button is monitored for forced message sending and testing
|
|
111
|
+
3.Then the Temperature if read from LM35 and checked
|
|
112
|
+
4.Any serialport Event is monitored
|
|
113
|
+
5.To indicate Board is running properly the onBoard Orange Led is made to Blink
|
|
114
|
+
*/
|
|
115
|
+
void loop() {
|
|
116
|
+
powerOn();
|
|
117
|
+
checkComm();
|
|
118
|
+
checkStatus();
|
|
119
|
+
checkBtn1();
|
|
120
|
+
checkBtn2();
|
|
121
|
+
checkLM35();
|
|
122
|
+
if(tempMode == AUTO)
|
|
123
|
+
tempAutomaticControl();
|
|
124
|
+
else
|
|
125
|
+
tempManualControl();
|
|
126
|
+
checkSHT75();
|
|
127
|
+
serialEvent2();
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/* Blink onBoard Orange LED to indicate Power ON */
|
|
131
|
+
void powerOn(){
|
|
132
|
+
if (ledOrangeBlink.check() == 1)
|
|
133
|
+
blink(ledOrange, ledOrangeState);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/* Buzzer Beep Sound */
|
|
137
|
+
void beep(){
|
|
138
|
+
digitalWrite(buzzerPin, HIGH);
|
|
139
|
+
delay(100);
|
|
140
|
+
digitalWrite(buzzerPin, LOW);
|
|
141
|
+
delay(100);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/* StartUp Sound Function */
|
|
145
|
+
void startupAlarm(){
|
|
146
|
+
for(int i=0;i<4;i++){
|
|
147
|
+
beep();
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/* Alarm Sound Function */
|
|
152
|
+
void soundAlarm(){
|
|
153
|
+
for(int i=0;i<6;i++){
|
|
154
|
+
beep();
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/* Button1 Function
|
|
159
|
+
This checks whether the Button state is changed/updated and
|
|
160
|
+
gives whether the button is rising or falling
|
|
161
|
+
Falling: Button is pressed - Sends Message of Temperature
|
|
162
|
+
Rising: Button is released
|
|
163
|
+
*/
|
|
164
|
+
void checkBtn1(){
|
|
165
|
+
if (btn1.update()) {
|
|
166
|
+
if (btn1.fallingEdge()) {
|
|
167
|
+
Serial.println("btn1 fall");
|
|
168
|
+
sendMessage("Temperature: ", tempC);
|
|
169
|
+
}
|
|
170
|
+
if (btn1.risingEdge()) {
|
|
171
|
+
Serial.println("btn1 rise");
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/* Button2 Function
|
|
177
|
+
This checks whether the Button state is changed/updated and
|
|
178
|
+
gives whether the button is rising or falling
|
|
179
|
+
Falling: Button is pressed - Sends Message of Humidity
|
|
180
|
+
Rising: Button is released
|
|
181
|
+
*/
|
|
182
|
+
void checkBtn2(){
|
|
183
|
+
if (btn2.update()) {
|
|
184
|
+
if (btn2.fallingEdge()) {
|
|
185
|
+
Serial.println("btn2 fall");
|
|
186
|
+
sendMessage("Humidity: ", humidityRH);
|
|
187
|
+
}
|
|
188
|
+
if (btn1.risingEdge()) {
|
|
189
|
+
Serial.println("btn2 rise");
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/* Blinking Function
|
|
195
|
+
This Toggles the state of the LED
|
|
196
|
+
*/
|
|
197
|
+
void blink(const int led,int &state){
|
|
198
|
+
if (state == LOW)
|
|
199
|
+
state = HIGH;
|
|
200
|
+
else
|
|
201
|
+
state = LOW;
|
|
202
|
+
digitalWrite(led, state);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
void checkComm(){
|
|
206
|
+
if(commTimer.check() == 1){
|
|
207
|
+
if(!Serial2.available()){
|
|
208
|
+
commError = true;
|
|
209
|
+
digitalWrite(ledGreen, LOW);
|
|
210
|
+
digitalWrite(ledRed, HIGH);
|
|
211
|
+
Serial.println("commError");
|
|
212
|
+
}
|
|
213
|
+
else{
|
|
214
|
+
commError = false;
|
|
215
|
+
digitalWrite(ledGreen, HIGH);
|
|
216
|
+
digitalWrite(ledRed, LOW);
|
|
217
|
+
Serial.println("comm Working");
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/* SerialPort Monitoring Function
|
|
223
|
+
This checks any incoming data at serialport and then splits the String based on
|
|
224
|
+
the LineFeed Character '\n' and sends it to the parser function
|
|
225
|
+
[GSM Modem SIM300 sends "\r\n" Carraige Return(CR) and LineFeed(LF) in every response]
|
|
226
|
+
*/
|
|
227
|
+
|
|
228
|
+
void serialEvent2(){
|
|
229
|
+
while (Serial2.available()) {
|
|
230
|
+
// get the new byte:
|
|
231
|
+
char inChar = (char)Serial2.read();
|
|
232
|
+
inputString += inChar; // add it to the inputString:
|
|
233
|
+
// if the incoming character is a newline, set a flag
|
|
234
|
+
// so the main loop can do something about it:
|
|
235
|
+
if (inChar == '\n') {
|
|
236
|
+
parseString();
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
/** GSM Related Functions **/
|
|
243
|
+
/* Network Connection Function
|
|
244
|
+
This checks whether the SIM in GSM Module SIM300 is connected and
|
|
245
|
+
whether network is connected based on which blue LED is turned ON or OFF
|
|
246
|
+
*/
|
|
247
|
+
void checkStatus(){
|
|
248
|
+
if(statusTimer.check() == 1){
|
|
249
|
+
checkSim();
|
|
250
|
+
delay(50);
|
|
251
|
+
checkNet();
|
|
252
|
+
delay(50);
|
|
253
|
+
if(simReady){
|
|
254
|
+
if(netReady)
|
|
255
|
+
digitalWrite(ledBlue, HIGH);
|
|
256
|
+
}
|
|
257
|
+
else{
|
|
258
|
+
digitalWrite(ledBlue, LOW);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
void checkSim(){
|
|
264
|
+
Serial2.println("AT+CSMINS?");
|
|
265
|
+
delay(20);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
void checkNet(){
|
|
269
|
+
Serial2.println("AT+CREG?");
|
|
270
|
+
delay(20);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
void sendMessage(String text, float value = 0.0){
|
|
274
|
+
Serial2.println("AT+CMGF=1");
|
|
275
|
+
delay(50);
|
|
276
|
+
Serial2.println("AT+CMGS=\""+mobileNo+"\"");
|
|
277
|
+
delay(50);
|
|
278
|
+
Serial2.print(text);
|
|
279
|
+
if(value != 0.0){
|
|
280
|
+
sprintf(charBuf,"%f", value);
|
|
281
|
+
Serial2.print(charBuf);
|
|
282
|
+
}
|
|
283
|
+
Serial2.print("\r\n\x1A"); //CR+LF+EOF
|
|
284
|
+
delay(100);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/* Parser Function
|
|
288
|
+
This checks any incoming String from serialport for necessary monitoring
|
|
289
|
+
the communication from GSM Module SIM300
|
|
290
|
+
*/
|
|
291
|
+
void parseString(){
|
|
292
|
+
Serial.println(inputString);
|
|
293
|
+
if(contains("+CREG: 0,0")){
|
|
294
|
+
Serial.println("No Network Connection");
|
|
295
|
+
netReady = false;
|
|
296
|
+
}
|
|
297
|
+
else if(contains("+CREG: 0,1") || contains("+CREG: 0,2") || contains("+CREG: 0,3")){
|
|
298
|
+
Serial.println("Net Ready");
|
|
299
|
+
netReady = true;
|
|
300
|
+
}
|
|
301
|
+
else if(contains("+CSMINS: 0,1")){//inputString.substring(0) == ){ //+CPIN: READY RDY +SCKS:0
|
|
302
|
+
Serial.println("SIM READY");
|
|
303
|
+
simReady = true;
|
|
304
|
+
}
|
|
305
|
+
else if(contains("+CSQ:")){ //RF Signal Strength
|
|
306
|
+
Serial.println(inputString); // Turn Green Led ON
|
|
307
|
+
}
|
|
308
|
+
else if(contains("OK")){
|
|
309
|
+
Serial.println(inputString); // Turn Green Led ON
|
|
310
|
+
digitalWrite(ledRed, LOW);
|
|
311
|
+
digitalWrite(ledGreen, HIGH);
|
|
312
|
+
}
|
|
313
|
+
else if(contains("Error")){
|
|
314
|
+
Serial.println(inputString); // Turn Red Led ON
|
|
315
|
+
digitalWrite(ledRed, HIGH);
|
|
316
|
+
digitalWrite(ledGreen, LOW);
|
|
317
|
+
delay(1000);
|
|
318
|
+
if(contains("+CMS ERROR: 517")){ //SIM Wait
|
|
319
|
+
Serial.println("SIM NOT READY");
|
|
320
|
+
simReady = false;
|
|
321
|
+
}
|
|
322
|
+
else if(contains("+CMS ERROR: 515")){ //Busy
|
|
323
|
+
Serial.println("Please Wait");
|
|
324
|
+
simReady = false;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
else if(contains("TEMP")){ //The String contains TEMP
|
|
328
|
+
Serial.println("TEMP Received");
|
|
329
|
+
digitalWrite(ledGreen, HIGH);
|
|
330
|
+
delay(500); // 515 error busy please wait
|
|
331
|
+
sendMessage("Temperature: ", tempC);
|
|
332
|
+
}
|
|
333
|
+
else if(contains("HUM")){ //The String contains HUM
|
|
334
|
+
Serial.println("HUM Received");
|
|
335
|
+
digitalWrite(ledGreen, HIGH);
|
|
336
|
+
delay(500); // 515 error busy please wait
|
|
337
|
+
sendMessage("Humidity: ", humidityRH);
|
|
338
|
+
}
|
|
339
|
+
else if(contains("MAN")){
|
|
340
|
+
Serial.println("MAN Received");
|
|
341
|
+
digitalWrite(ledGreen, HIGH);
|
|
342
|
+
delay(500);
|
|
343
|
+
if(tempMode == MAN){
|
|
344
|
+
sendMessage("Already in Manual Mode");
|
|
345
|
+
}
|
|
346
|
+
else{
|
|
347
|
+
sendMessage("Manual Mode is Set");
|
|
348
|
+
tempMode = MAN;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
else if(contains("AUTO")){
|
|
352
|
+
Serial.println("AUTO Received");
|
|
353
|
+
digitalWrite(ledGreen, HIGH);
|
|
354
|
+
delay(500);
|
|
355
|
+
if(tempMode == AUTO){
|
|
356
|
+
sendMessage("Already in Automatic Mode");
|
|
357
|
+
}
|
|
358
|
+
else{
|
|
359
|
+
sendMessage("Automatic Mode is Set");
|
|
360
|
+
tempMode = AUTO;
|
|
361
|
+
running = true;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
else if(contains("MOB")){
|
|
365
|
+
Serial.println("MOB Received");
|
|
366
|
+
digitalWrite(ledGreen, HIGH);
|
|
367
|
+
char newChar[9];
|
|
368
|
+
for(int i=0;i<10;i++)
|
|
369
|
+
newChar[i] = inputString[i+4];
|
|
370
|
+
mobileNo = newChar;
|
|
371
|
+
Serial.println("New Mobile no:"+mobileNo);
|
|
372
|
+
delay(500); // 515 error busy please wait
|
|
373
|
+
sendMessage("New Mobile Number: "+mobileNo);
|
|
374
|
+
}
|
|
375
|
+
else if(contains("ON")){
|
|
376
|
+
Serial.println("ON Received");
|
|
377
|
+
if(tempMode == MAN){
|
|
378
|
+
running = true;
|
|
379
|
+
delay(500); // 515 error busy please wait
|
|
380
|
+
sendMessage("Bulb is on");
|
|
381
|
+
}
|
|
382
|
+
else{
|
|
383
|
+
sendMessage("Please Change to manual mode");
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
else if(contains("OFF")){
|
|
387
|
+
Serial.println("OFF Received");
|
|
388
|
+
if(tempMode == MAN){
|
|
389
|
+
running = false;
|
|
390
|
+
delay(500); // 515 error busy please wait
|
|
391
|
+
sendMessage("Bulb is off");
|
|
392
|
+
}
|
|
393
|
+
else{
|
|
394
|
+
sendMessage("Please Change to manual mode");
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
else if(contains("SET")){
|
|
398
|
+
Serial.println("SET Received");
|
|
399
|
+
char newChar[1];
|
|
400
|
+
newChar[0] = inputString[4];
|
|
401
|
+
newChar[1] = inputString[5];
|
|
402
|
+
tempSetPoint = atof(newChar);// Converting tempSetPoint from message to float
|
|
403
|
+
Serial.println(tempSetPoint);
|
|
404
|
+
delay(500); // 515 error busy please wait
|
|
405
|
+
sendMessage("tempSetPoint: ", tempSetPoint);
|
|
406
|
+
}
|
|
407
|
+
inputString = ""; // clear the string:
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/* This checks if a search string is present in the inputString */
|
|
411
|
+
int contains(String search) {
|
|
412
|
+
int max = inputString.length() - search.length();
|
|
413
|
+
int lgsearch = search.length();
|
|
414
|
+
for (int i = 0; i <= max; i++) {
|
|
415
|
+
if (inputString.substring(i, i + lgsearch) == search) return true;
|
|
416
|
+
}
|
|
417
|
+
return false;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/** Monitor and Control Related Functions **/
|
|
421
|
+
/* Temperature Monitoring Function
|
|
422
|
+
This checks the temperature every 2second
|
|
423
|
+
*/
|
|
424
|
+
void checkLM35(){
|
|
425
|
+
if (tempReadTimer.check() == 1){ // check if the metro has passed it's interval
|
|
426
|
+
readLM35();
|
|
427
|
+
Serial.print("Temperature: ");
|
|
428
|
+
Serial.print(readValue);
|
|
429
|
+
Serial.print(" - ");
|
|
430
|
+
Serial.print(tempC);
|
|
431
|
+
Serial.println("c");
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/* Temperature Reading Function
|
|
436
|
+
Reads 8 samples from the ADC pin A4/18 and then takes average
|
|
437
|
+
Voltage is calculated by multiplying by 3.3v reference voltage and dividing by 1024 10-bit ADC value
|
|
438
|
+
Temperature is calculated by multiplying voltage with 100 as LM35 has 10mV/C ex: 28c is 280mV or 0.28V
|
|
439
|
+
*/
|
|
440
|
+
void readLM35(){
|
|
441
|
+
tempC = 0;
|
|
442
|
+
voltage = 0;
|
|
443
|
+
readValue = 0;
|
|
444
|
+
for(int i = 0;i<=7;i++){ // gets 8 samples from adc
|
|
445
|
+
readValue += analogRead(tempPin);
|
|
446
|
+
delay(20);
|
|
447
|
+
}
|
|
448
|
+
readValue = readValue/8;
|
|
449
|
+
voltage = (3.3 * readValue)/1024;
|
|
450
|
+
tempC = voltage * 100;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
/* Temperature Automatic Control Function
|
|
454
|
+
Automatically controls the temperature based on tempSetPoint value
|
|
455
|
+
*/
|
|
456
|
+
void tempAutomaticControl(){
|
|
457
|
+
if(tempC >= tempSetPoint){
|
|
458
|
+
if(running){ // This is to prevent the system from sending messages and alarm continously
|
|
459
|
+
Serial.print("Temperature >= ");
|
|
460
|
+
Serial.println(tempSetPoint);
|
|
461
|
+
running = false;
|
|
462
|
+
relayState = LOW;
|
|
463
|
+
sendMessage("Temperature: ", tempC);
|
|
464
|
+
soundAlarm();
|
|
465
|
+
twoposControl();
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
else{ // If Temperature dips below tempSetPoint then return to normal operation
|
|
469
|
+
if(!running){
|
|
470
|
+
Serial.print("Temperature < ");
|
|
471
|
+
Serial.println(tempSetPoint);
|
|
472
|
+
running = true;
|
|
473
|
+
relayState = HIGH;
|
|
474
|
+
twoposControl();
|
|
475
|
+
beep();
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
/* Temperature Manual Control Function
|
|
481
|
+
Manually controls the temperature based on used Input ON/OFF
|
|
482
|
+
*/
|
|
483
|
+
void tempManualControl(){
|
|
484
|
+
if(running)
|
|
485
|
+
relayState = HIGH;
|
|
486
|
+
else
|
|
487
|
+
relayState = LOW;
|
|
488
|
+
twoposControl();
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
/* Humidity Monitoring Function
|
|
492
|
+
This checks the humidity every 2seconds and performs necessary controlling
|
|
493
|
+
*/
|
|
494
|
+
void checkSHT75(){
|
|
495
|
+
if (humidityReadTimer.check() == 1){
|
|
496
|
+
humidityRH = sht1x.readHumidity();
|
|
497
|
+
Serial.print("Humidity: ");
|
|
498
|
+
Serial.print(humidityRH);
|
|
499
|
+
Serial.println("%");
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
/* 2-Position Controller Mode
|
|
504
|
+
This Turns ON or OFF the Relay based on tempSetPoint */
|
|
505
|
+
void twoposControl(){
|
|
506
|
+
digitalWrite(relayPin, relayState);
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
/** GPRS Related Functions **/
|
|
510
|
+
void initGPRS(){
|
|
511
|
+
Serial2.println("AT+CGATT=1"); // - Attach to GPRS Service
|
|
512
|
+
Serial2.println("AT+CGDCONT=1,\"IP\",\"wap.cingular\""); //- Define PDP Context (cid, PDP type, APN)
|
|
513
|
+
Serial2.println("AT+CDNSCFG=\"208.67.222.222\",\"208.67.220.220\""); //- Configure Domain Name Server (primary DNS, secondary DNS)
|
|
514
|
+
Serial2.println("AT+CSTT=\"wap.cingular\",\"\",\"\"");//- Start Task & set APN, User ID, and password
|
|
515
|
+
Serial2.println("AT+CIICR"); //- Bring up wireless connection with GPRS - THIS MAY TAKE A WHILE
|
|
516
|
+
Serial2.println("AT+CIFSR"); // - Get Local IP address
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
void senddToServer(){
|
|
520
|
+
Serial2.println("AT+CIPHEAD=1"); //- Tells module to add an 'IP Header' to receive data
|
|
521
|
+
Serial2.println("AT+CDNSORIP=1"); //- Indicates whether connection request will be IP address (0), or domain name (1)
|
|
522
|
+
Serial2.println("AT+CIPSTART=\"TCP\",\"www.google.com\",\"80\"");
|
|
523
|
+
//- Start up TCP connection (mode, IP address/name, port) CONNECT OK - Indicates you've connected to the server
|
|
524
|
+
//- IT MAY TAKE A WHILE FOR THIS TO BE RETURNED
|
|
525
|
+
Serial2.println("AT+CIPSEND"); //- Issue Send Command - wait for module to return'>'
|
|
526
|
+
Serial2.print("GET / HTTP/1.1\r\n\x1A"); //- Send data - this example is an HTTP request for the default page
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
|
|
530
|
+
void checkGPRS(){
|
|
531
|
+
Serial2.println("AT+CGATT?"); // +CGATT:1 Gprs is active, 0:de:active
|
|
532
|
+
Serial2.println("AT+CIPSTATUS"); // check GPRS Status STATE: CONNECT OK or IP STATUS
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
void closeGPRS(){
|
|
536
|
+
Serial2.println("AT+CGATT=0"); // close gprs
|
|
537
|
+
Serial2.println("AT+CIPSHUT"); // close gprs
|
|
538
|
+
Serial2.println("AT+CFUN=0,1"); // close gprs
|
|
539
|
+
Serial2.println("AT+CPOWD=1"); // close gprs
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
void sendPacket(){
|
|
543
|
+
Serial2.println("AT+CIPSTART=\"TCP\",\"211.136.42.12\",\"2020\""); // OK,CONENECT OK
|
|
544
|
+
Serial2.println("AT+CIPSEND");
|
|
545
|
+
Serial2.print("This is my data\r\n\x1A"); // SEND OK
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
void getIP(){
|
|
549
|
+
Serial2.print("AT+CIFSR");
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
void tcpServer(){
|
|
553
|
+
Serial2.print("AT+CIPCSGP=1\"CMNET\""); // OK
|
|
554
|
+
Serial2.print("AT+CLPORT=\"TCP\",\"2020\""); //OK
|
|
555
|
+
Serial2.print("AT+CIPSERVER"); // SERVER OK
|
|
556
|
+
Serial2.print("AT+CIPCCON=2"); // OK
|
|
557
|
+
Serial2.print("AT+CIFSR"); // IP nl REMOTE IP: 10.112.255.207:2020 Then CIPSEND
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
|
|
561
|
+
|
RemoteMonitorApp/.classpath
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<classpath>
|
|
3
|
+
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
|
|
4
|
+
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
|
|
5
|
+
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
|
|
6
|
+
<classpathentry kind="src" path="src"/>
|
|
7
|
+
<classpathentry kind="src" path="gen"/>
|
|
8
|
+
<classpathentry kind="output" path="bin/classes"/>
|
|
9
|
+
</classpath>
|
RemoteMonitorApp/.project
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<projectDescription>
|
|
3
|
+
<name>RemoteMonitor</name>
|
|
4
|
+
<comment></comment>
|
|
5
|
+
<projects>
|
|
6
|
+
</projects>
|
|
7
|
+
<buildSpec>
|
|
8
|
+
<buildCommand>
|
|
9
|
+
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
|
|
10
|
+
<arguments>
|
|
11
|
+
</arguments>
|
|
12
|
+
</buildCommand>
|
|
13
|
+
<buildCommand>
|
|
14
|
+
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
|
|
15
|
+
<arguments>
|
|
16
|
+
</arguments>
|
|
17
|
+
</buildCommand>
|
|
18
|
+
<buildCommand>
|
|
19
|
+
<name>org.eclipse.jdt.core.javabuilder</name>
|
|
20
|
+
<arguments>
|
|
21
|
+
</arguments>
|
|
22
|
+
</buildCommand>
|
|
23
|
+
<buildCommand>
|
|
24
|
+
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
|
|
25
|
+
<arguments>
|
|
26
|
+
</arguments>
|
|
27
|
+
</buildCommand>
|
|
28
|
+
</buildSpec>
|
|
29
|
+
<natures>
|
|
30
|
+
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
|
|
31
|
+
<nature>org.eclipse.jdt.core.javanature</nature>
|
|
32
|
+
</natures>
|
|
33
|
+
</projectDescription>
|
RemoteMonitorApp/.settings/org.eclipse.jdt.core.prefs
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
eclipse.preferences.version=1
|
|
2
|
+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
|
|
3
|
+
org.eclipse.jdt.core.compiler.compliance=1.6
|
|
4
|
+
org.eclipse.jdt.core.compiler.source=1.6
|
RemoteMonitorApp/AndroidManifest.xml
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
3
|
+
package="com.pyros2097.remoteMonitor"
|
|
4
|
+
android:versionCode="1"
|
|
5
|
+
android:versionName="1.0">
|
|
6
|
+
<uses-permission android:name="android.permission.READ_SMS"/>
|
|
7
|
+
<application android:icon="@drawable/icon" android:label="@string/app_name">
|
|
8
|
+
<activity android:name=".SMSTest"
|
|
9
|
+
android:label="@string/app_name"
|
|
10
|
+
android:theme="@android:style/Theme.NoTitleBar">
|
|
11
|
+
<intent-filter>
|
|
12
|
+
<action android:name="android.intent.action.MAIN" />
|
|
13
|
+
<category android:name="android.intent.category.LAUNCHER" />
|
|
14
|
+
</intent-filter>
|
|
15
|
+
</activity>
|
|
16
|
+
<receiver android:name=".SmsReceiver" android:exported="true" >
|
|
17
|
+
<intent-filter android:priority="1000">
|
|
18
|
+
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
|
|
19
|
+
</intent-filter>
|
|
20
|
+
</receiver>
|
|
21
|
+
</application>
|
|
22
|
+
<uses-permission android:name="android.permission.SEND_SMS">
|
|
23
|
+
</uses-permission>
|
|
24
|
+
<uses-permission android:name="android.permission.RECEIVE_SMS">
|
|
25
|
+
</uses-permission>
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
</manifest>
|
RemoteMonitorApp/bin/AndroidManifest.xml
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
3
|
+
package="com.pyros2097.remoteMonitor"
|
|
4
|
+
android:versionCode="1"
|
|
5
|
+
android:versionName="1.0">
|
|
6
|
+
<uses-permission android:name="android.permission.READ_SMS"/>
|
|
7
|
+
<application android:icon="@drawable/icon" android:label="@string/app_name">
|
|
8
|
+
<activity android:name=".SMSTest"
|
|
9
|
+
android:label="@string/app_name"
|
|
10
|
+
android:theme="@android:style/Theme.NoTitleBar">
|
|
11
|
+
<intent-filter>
|
|
12
|
+
<action android:name="android.intent.action.MAIN" />
|
|
13
|
+
<category android:name="android.intent.category.LAUNCHER" />
|
|
14
|
+
</intent-filter>
|
|
15
|
+
</activity>
|
|
16
|
+
<receiver android:name=".SmsReceiver" android:exported="true" >
|
|
17
|
+
<intent-filter android:priority="1000">
|
|
18
|
+
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
|
|
19
|
+
</intent-filter>
|
|
20
|
+
</receiver>
|
|
21
|
+
</application>
|
|
22
|
+
<uses-permission android:name="android.permission.SEND_SMS">
|
|
23
|
+
</uses-permission>
|
|
24
|
+
<uses-permission android:name="android.permission.RECEIVE_SMS">
|
|
25
|
+
</uses-permission>
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
</manifest>
|
RemoteMonitorApp/bin/RemoteMonitor.apk
ADDED
|
Binary file
|
RemoteMonitorApp/bin/classes.dex
ADDED
|
Binary file
|
RemoteMonitorApp/bin/classes/com/pyros2097/remoteMonitor/BuildConfig.class
ADDED
|
Binary file
|
RemoteMonitorApp/bin/classes/com/pyros2097/remoteMonitor/R$attr.class
ADDED
|
Binary file
|
RemoteMonitorApp/bin/classes/com/pyros2097/remoteMonitor/R$drawable.class
ADDED
|
Binary file
|
RemoteMonitorApp/bin/classes/com/pyros2097/remoteMonitor/R$id.class
ADDED
|
Binary file
|
RemoteMonitorApp/bin/classes/com/pyros2097/remoteMonitor/R$layout.class
ADDED
|
Binary file
|
RemoteMonitorApp/bin/classes/com/pyros2097/remoteMonitor/R$string.class
ADDED
|
Binary file
|
RemoteMonitorApp/bin/classes/com/pyros2097/remoteMonitor/R.class
ADDED
|
Binary file
|
RemoteMonitorApp/bin/classes/com/pyros2097/remoteMonitor/SMSTest$1.class
ADDED
|
Binary file
|
RemoteMonitorApp/bin/classes/com/pyros2097/remoteMonitor/SMSTest$2.class
ADDED
|
Binary file
|
RemoteMonitorApp/bin/classes/com/pyros2097/remoteMonitor/SMSTest$3.class
ADDED
|
Binary file
|
RemoteMonitorApp/bin/classes/com/pyros2097/remoteMonitor/SMSTest$4.class
ADDED
|
Binary file
|
RemoteMonitorApp/bin/classes/com/pyros2097/remoteMonitor/SMSTest$5.class
ADDED
|
Binary file
|
RemoteMonitorApp/bin/classes/com/pyros2097/remoteMonitor/SMSTest$6.class
ADDED
|
Binary file
|
RemoteMonitorApp/bin/classes/com/pyros2097/remoteMonitor/SMSTest$7.class
ADDED
|
Binary file
|
RemoteMonitorApp/bin/classes/com/pyros2097/remoteMonitor/SMSTest$8.class
ADDED
|
Binary file
|
RemoteMonitorApp/bin/classes/com/pyros2097/remoteMonitor/SMSTest.class
ADDED
|
Binary file
|
RemoteMonitorApp/bin/classes/com/pyros2097/remoteMonitor/SmsReceiver.class
ADDED
|
Binary file
|
RemoteMonitorApp/bin/res/drawable-hdpi/icon.png
ADDED
|
Binary file
|
RemoteMonitorApp/bin/res/drawable-ldpi/icon.png
ADDED
|
Binary file
|
RemoteMonitorApp/bin/res/drawable-mdpi/icon.png
ADDED
|
Binary file
|
RemoteMonitorApp/bin/resources.ap_
ADDED
|
Binary file
|
RemoteMonitorApp/gen/com/pyros2097/remoteMonitor/BuildConfig.java
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Automatically generated file. DO NOT MODIFY */
|
|
2
|
+
package com.pyros2097.remoteMonitor;
|
|
3
|
+
|
|
4
|
+
public final class BuildConfig {
|
|
5
|
+
public final static boolean DEBUG = true;
|
|
6
|
+
}
|
RemoteMonitorApp/gen/com/pyros2097/remoteMonitor/R.java
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/* AUTO-GENERATED FILE. DO NOT MODIFY.
|
|
2
|
+
*
|
|
3
|
+
* This class was automatically generated by the
|
|
4
|
+
* aapt tool from the resource data it found. It
|
|
5
|
+
* should not be modified by hand.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
package com.pyros2097.remoteMonitor;
|
|
9
|
+
|
|
10
|
+
public final class R {
|
|
11
|
+
public static final class attr {
|
|
12
|
+
}
|
|
13
|
+
public static final class drawable {
|
|
14
|
+
public static final int icon=0x7f020000;
|
|
15
|
+
}
|
|
16
|
+
public static final class id {
|
|
17
|
+
public static final int button1=0x7f050008;
|
|
18
|
+
public static final int button2=0x7f050004;
|
|
19
|
+
public static final int button3=0x7f05000a;
|
|
20
|
+
public static final int button4=0x7f05000b;
|
|
21
|
+
public static final int button5=0x7f05000e;
|
|
22
|
+
public static final int editText3=0x7f05000d;
|
|
23
|
+
public static final int textView1=0x7f050001;
|
|
24
|
+
public static final int textView2=0x7f050005;
|
|
25
|
+
public static final int textView3=0x7f05000c;
|
|
26
|
+
public static final int textView4=0x7f050002;
|
|
27
|
+
public static final int textView5=0x7f050006;
|
|
28
|
+
public static final int textView6=0x7f050003;
|
|
29
|
+
public static final int textView7=0x7f050007;
|
|
30
|
+
public static final int textView8=0x7f05000f;
|
|
31
|
+
public static final int toggleButton1=0x7f050009;
|
|
32
|
+
public static final int txtPhoneNo=0x7f050000;
|
|
33
|
+
}
|
|
34
|
+
public static final class layout {
|
|
35
|
+
public static final int main=0x7f030000;
|
|
36
|
+
}
|
|
37
|
+
public static final class string {
|
|
38
|
+
public static final int app_name=0x7f040001;
|
|
39
|
+
public static final int hello=0x7f040000;
|
|
40
|
+
}
|
|
41
|
+
}
|
RemoteMonitorApp/lint.xml
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<lint>
|
|
3
|
+
<issue id="NewApi" severity="ignore">
|
|
4
|
+
<ignore path="src/com/example/smsTest/SMSTest.java" />
|
|
5
|
+
</issue>
|
|
6
|
+
</lint>
|
RemoteMonitorApp/project.properties
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# This file is automatically generated by Android Tools.
|
|
2
|
+
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
|
|
3
|
+
#
|
|
4
|
+
# This file must be checked in Version Control Systems.
|
|
5
|
+
#
|
|
6
|
+
# To customize properties used by the Ant build system edit
|
|
7
|
+
# "ant.properties", and override values to adapt the script to your
|
|
8
|
+
# project structure.
|
|
9
|
+
#
|
|
10
|
+
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
|
|
11
|
+
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
|
|
12
|
+
|
|
13
|
+
# Project target.
|
|
14
|
+
target=android-17
|
RemoteMonitorApp/res/drawable-hdpi/icon.png
ADDED
|
Binary file
|
RemoteMonitorApp/res/drawable-ldpi/icon.png
ADDED
|
Binary file
|
RemoteMonitorApp/res/drawable-mdpi/icon.png
ADDED
|
Binary file
|
RemoteMonitorApp/res/layout/main.xml
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
3
|
+
android:layout_width="fill_parent"
|
|
4
|
+
android:layout_height="fill_parent"
|
|
5
|
+
android:background="#ffffff"
|
|
6
|
+
android:orientation="vertical" >
|
|
7
|
+
|
|
8
|
+
<TextView
|
|
9
|
+
android:layout_width="fill_parent"
|
|
10
|
+
android:layout_height="wrap_content"
|
|
11
|
+
android:background="#A6A6C0"
|
|
12
|
+
android:text="Mobile no"
|
|
13
|
+
android:textColor="#000000" />
|
|
14
|
+
|
|
15
|
+
<EditText
|
|
16
|
+
android:id="@+id/txtPhoneNo"
|
|
17
|
+
android:layout_width="fill_parent"
|
|
18
|
+
android:layout_height="wrap_content"
|
|
19
|
+
android:inputType="number" />
|
|
20
|
+
|
|
21
|
+
<LinearLayout
|
|
22
|
+
android:layout_width="match_parent"
|
|
23
|
+
android:layout_height="wrap_content"
|
|
24
|
+
android:background="#A6A6C0" >
|
|
25
|
+
|
|
26
|
+
<TextView
|
|
27
|
+
android:id="@+id/textView1"
|
|
28
|
+
android:layout_width="wrap_content"
|
|
29
|
+
android:layout_height="wrap_content"
|
|
30
|
+
android:text="Temperature: "
|
|
31
|
+
android:textAppearance="?android:attr/textAppearanceLarge"
|
|
32
|
+
android:textColor="#000000" />
|
|
33
|
+
|
|
34
|
+
<TextView
|
|
35
|
+
android:id="@+id/textView4"
|
|
36
|
+
android:layout_width="wrap_content"
|
|
37
|
+
android:layout_height="wrap_content"
|
|
38
|
+
android:text="25.55"
|
|
39
|
+
android:textAppearance="?android:attr/textAppearanceLarge"
|
|
40
|
+
android:textColor="#800000" />
|
|
41
|
+
|
|
42
|
+
<TextView
|
|
43
|
+
android:id="@+id/textView6"
|
|
44
|
+
android:layout_width="wrap_content"
|
|
45
|
+
android:layout_height="wrap_content"
|
|
46
|
+
android:text="°c "
|
|
47
|
+
android:textAppearance="?android:attr/textAppearanceLarge"
|
|
48
|
+
android:textColor="#000000" />
|
|
49
|
+
|
|
50
|
+
<Button
|
|
51
|
+
android:id="@+id/button2"
|
|
52
|
+
style="?android:attr/buttonStyleSmall"
|
|
53
|
+
android:layout_width="wrap_content"
|
|
54
|
+
android:layout_height="wrap_content"
|
|
55
|
+
android:layout_weight="0.02"
|
|
56
|
+
android:text="TEMP"
|
|
57
|
+
android:textStyle="bold" />
|
|
58
|
+
|
|
59
|
+
</LinearLayout>
|
|
60
|
+
|
|
61
|
+
<LinearLayout
|
|
62
|
+
android:layout_width="match_parent"
|
|
63
|
+
android:layout_height="wrap_content"
|
|
64
|
+
android:background="#A6A6C0"
|
|
65
|
+
android:paddingTop="20dp" >
|
|
66
|
+
|
|
67
|
+
<TextView
|
|
68
|
+
android:id="@+id/textView2"
|
|
69
|
+
android:layout_width="wrap_content"
|
|
70
|
+
android:layout_height="wrap_content"
|
|
71
|
+
android:layout_weight="0.51"
|
|
72
|
+
android:text="Humidity:"
|
|
73
|
+
android:textAppearance="?android:attr/textAppearanceLarge"
|
|
74
|
+
android:textColor="#000000" />
|
|
75
|
+
|
|
76
|
+
<TextView
|
|
77
|
+
android:id="@+id/textView5"
|
|
78
|
+
android:layout_width="wrap_content"
|
|
79
|
+
android:layout_height="wrap_content"
|
|
80
|
+
android:text="55.55"
|
|
81
|
+
android:textAppearance="?android:attr/textAppearanceLarge"
|
|
82
|
+
android:textColor="#0066FF" />
|
|
83
|
+
|
|
84
|
+
<TextView
|
|
85
|
+
android:id="@+id/textView7"
|
|
86
|
+
android:layout_width="wrap_content"
|
|
87
|
+
android:layout_height="wrap_content"
|
|
88
|
+
android:layout_weight="1"
|
|
89
|
+
android:text="%RH"
|
|
90
|
+
android:textAppearance="?android:attr/textAppearanceLarge"
|
|
91
|
+
android:textColor="#000000" />
|
|
92
|
+
|
|
93
|
+
<Button
|
|
94
|
+
android:id="@+id/button1"
|
|
95
|
+
style="?android:attr/buttonStyleSmall"
|
|
96
|
+
android:layout_width="wrap_content"
|
|
97
|
+
android:layout_height="wrap_content"
|
|
98
|
+
android:layout_weight="1"
|
|
99
|
+
android:text="HUM"
|
|
100
|
+
android:textStyle="bold" />
|
|
101
|
+
|
|
102
|
+
</LinearLayout>
|
|
103
|
+
|
|
104
|
+
<RelativeLayout
|
|
105
|
+
android:layout_width="match_parent"
|
|
106
|
+
android:layout_height="wrap_content"
|
|
107
|
+
android:layout_weight="0.05"
|
|
108
|
+
android:background="#4C4C80" >
|
|
109
|
+
|
|
110
|
+
<ToggleButton
|
|
111
|
+
android:id="@+id/toggleButton1"
|
|
112
|
+
android:layout_width="100dp"
|
|
113
|
+
android:layout_height="80dp"
|
|
114
|
+
android:layout_alignBaseline="@+id/button3"
|
|
115
|
+
android:layout_alignBottom="@+id/button3"
|
|
116
|
+
android:layout_alignParentRight="true"
|
|
117
|
+
android:text="MAN"
|
|
118
|
+
android:textStyle="bold" />
|
|
119
|
+
|
|
120
|
+
<Button
|
|
121
|
+
android:id="@+id/button4"
|
|
122
|
+
android:layout_width="100dp"
|
|
123
|
+
android:layout_height="80dp"
|
|
124
|
+
android:layout_alignParentLeft="true"
|
|
125
|
+
android:layout_below="@+id/toggleButton1"
|
|
126
|
+
android:layout_marginTop="33dp"
|
|
127
|
+
android:text="AUTO"
|
|
128
|
+
android:textStyle="bold" />
|
|
129
|
+
|
|
130
|
+
<LinearLayout
|
|
131
|
+
android:layout_width="wrap_content"
|
|
132
|
+
android:layout_height="wrap_content"
|
|
133
|
+
android:layout_alignParentBottom="true"
|
|
134
|
+
android:layout_alignParentLeft="true"
|
|
135
|
+
android:layout_alignParentRight="true" >
|
|
136
|
+
|
|
137
|
+
<TextView
|
|
138
|
+
android:id="@+id/textView3"
|
|
139
|
+
android:layout_width="wrap_content"
|
|
140
|
+
android:layout_height="wrap_content"
|
|
141
|
+
android:text="Setpoint "
|
|
142
|
+
android:textAppearance="?android:attr/textAppearanceLarge"
|
|
143
|
+
android:textColor="#000000" />
|
|
144
|
+
|
|
145
|
+
<EditText
|
|
146
|
+
android:id="@+id/editText3"
|
|
147
|
+
android:layout_width="160dp"
|
|
148
|
+
android:layout_height="wrap_content"
|
|
149
|
+
android:ems="10"
|
|
150
|
+
android:inputType="number" />
|
|
151
|
+
|
|
152
|
+
<Button
|
|
153
|
+
android:id="@+id/button5"
|
|
154
|
+
android:layout_width="match_parent"
|
|
155
|
+
android:layout_height="wrap_content"
|
|
156
|
+
android:text="SET"
|
|
157
|
+
android:textStyle="bold" />
|
|
158
|
+
|
|
159
|
+
</LinearLayout>
|
|
160
|
+
|
|
161
|
+
<TextView
|
|
162
|
+
android:id="@+id/textView8"
|
|
163
|
+
android:layout_width="wrap_content"
|
|
164
|
+
android:layout_height="wrap_content"
|
|
165
|
+
android:layout_alignParentLeft="true"
|
|
166
|
+
android:layout_alignParentTop="true"
|
|
167
|
+
android:background="#4D70DB"
|
|
168
|
+
android:text="Mode: AUTO"
|
|
169
|
+
android:textAppearance="?android:attr/textAppearanceLarge"
|
|
170
|
+
android:textColor="#000000"
|
|
171
|
+
android:textStyle="bold" />
|
|
172
|
+
|
|
173
|
+
<Button
|
|
174
|
+
android:id="@+id/button3"
|
|
175
|
+
android:layout_width="100dp"
|
|
176
|
+
android:layout_height="80dp"
|
|
177
|
+
android:layout_alignParentLeft="true"
|
|
178
|
+
android:layout_below="@+id/textView8"
|
|
179
|
+
android:layout_marginTop="14dp"
|
|
180
|
+
android:text="MAN"
|
|
181
|
+
android:textStyle="bold" />
|
|
182
|
+
|
|
183
|
+
</RelativeLayout>
|
|
184
|
+
|
|
185
|
+
</LinearLayout>
|
RemoteMonitorApp/res/values/strings.xml
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
+
<resources>
|
|
3
|
+
<string name="hello">Hello World, SMSTest!</string>
|
|
4
|
+
<string name="app_name">RemoteMonitor</string>
|
|
5
|
+
</resources>
|
RemoteMonitorApp/src/com/pyros2097/remoteMonitor/SMSTest.java
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
package com.pyros2097.remoteMonitor;
|
|
2
|
+
|
|
3
|
+
import android.app.Activity;
|
|
4
|
+
import android.app.PendingIntent;
|
|
5
|
+
import android.content.BroadcastReceiver;
|
|
6
|
+
import android.content.Context;
|
|
7
|
+
import android.content.Intent;
|
|
8
|
+
import android.content.IntentFilter;
|
|
9
|
+
import android.os.Bundle;
|
|
10
|
+
import android.telephony.SmsManager;
|
|
11
|
+
import android.view.View;
|
|
12
|
+
import android.widget.Button;
|
|
13
|
+
import android.widget.EditText;
|
|
14
|
+
import android.widget.TextView;
|
|
15
|
+
import android.widget.Toast;
|
|
16
|
+
import android.widget.ToggleButton;
|
|
17
|
+
|
|
18
|
+
public class SMSTest extends Activity
|
|
19
|
+
{
|
|
20
|
+
Button btn1;
|
|
21
|
+
Button btn2;
|
|
22
|
+
Button btn3;
|
|
23
|
+
Button btn4;
|
|
24
|
+
ToggleButton btn5;
|
|
25
|
+
Button btn6;
|
|
26
|
+
static TextView txt4;
|
|
27
|
+
static TextView txt5;
|
|
28
|
+
static TextView txt8;
|
|
29
|
+
EditText txtPhoneNo;
|
|
30
|
+
EditText etxt3;
|
|
31
|
+
String phoneNo;
|
|
32
|
+
|
|
33
|
+
/** Called when the activity is first created. */
|
|
34
|
+
@Override
|
|
35
|
+
public void onCreate(Bundle savedInstanceState)
|
|
36
|
+
{
|
|
37
|
+
super.onCreate(savedInstanceState);
|
|
38
|
+
setContentView(R.layout.main);
|
|
39
|
+
btn1 = (Button) findViewById(R.id.button1);
|
|
40
|
+
btn2 = (Button) findViewById(R.id.button2);
|
|
41
|
+
btn3 = (Button) findViewById(R.id.button3);
|
|
42
|
+
btn4 = (Button) findViewById(R.id.button4);
|
|
43
|
+
btn5 = (ToggleButton) findViewById(R.id.toggleButton1);
|
|
44
|
+
btn6 = (Button) findViewById(R.id.button5);
|
|
45
|
+
txtPhoneNo = (EditText) findViewById(R.id.txtPhoneNo);
|
|
46
|
+
etxt3 = (EditText) findViewById(R.id.editText3);
|
|
47
|
+
txt4 = (TextView) findViewById(R.id.textView4);
|
|
48
|
+
txt5 = (TextView) findViewById(R.id.textView5);
|
|
49
|
+
txt8 = (TextView) findViewById(R.id.textView8);
|
|
50
|
+
|
|
51
|
+
/*
|
|
52
|
+
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
|
|
53
|
+
sendIntent.putExtra("sms_body", "Content of the SMS goes here...");
|
|
54
|
+
sendIntent.setType("vnd.android-dir/mms-sms");
|
|
55
|
+
startActivity(sendIntent);
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
btn1.setOnClickListener(new View.OnClickListener()
|
|
59
|
+
{
|
|
60
|
+
public void onClick(View v)
|
|
61
|
+
{
|
|
62
|
+
phoneNo = txtPhoneNo.getText().toString();
|
|
63
|
+
sendSMS(phoneNo, "HUM");
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
btn2.setOnClickListener(new View.OnClickListener()
|
|
67
|
+
{
|
|
68
|
+
public void onClick(View v)
|
|
69
|
+
{
|
|
70
|
+
phoneNo = txtPhoneNo.getText().toString();
|
|
71
|
+
sendSMS(phoneNo, "TEMP");
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
btn3.setOnClickListener(new View.OnClickListener()
|
|
75
|
+
{
|
|
76
|
+
public void onClick(View v)
|
|
77
|
+
{
|
|
78
|
+
phoneNo = txtPhoneNo.getText().toString();
|
|
79
|
+
sendSMS(phoneNo, "MAN");
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
btn4.setOnClickListener(new View.OnClickListener()
|
|
83
|
+
{
|
|
84
|
+
public void onClick(View v)
|
|
85
|
+
{
|
|
86
|
+
phoneNo = txtPhoneNo.getText().toString();
|
|
87
|
+
sendSMS(phoneNo, "AUTO");
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
btn5.setOnClickListener(new View.OnClickListener()
|
|
91
|
+
{
|
|
92
|
+
public void onClick(View v)
|
|
93
|
+
{
|
|
94
|
+
phoneNo = txtPhoneNo.getText().toString();
|
|
95
|
+
if(btn5.isChecked())
|
|
96
|
+
sendSMS(phoneNo, "ON");
|
|
97
|
+
else
|
|
98
|
+
sendSMS(phoneNo, "OFF");
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
btn6.setOnClickListener(new View.OnClickListener()
|
|
102
|
+
{
|
|
103
|
+
public void onClick(View v)
|
|
104
|
+
{
|
|
105
|
+
phoneNo = txtPhoneNo.getText().toString();
|
|
106
|
+
if(etxt3.getText().length()>=2)
|
|
107
|
+
sendSMS(phoneNo, "SET "+etxt3.getText());
|
|
108
|
+
else
|
|
109
|
+
Toast.makeText(getBaseContext(), "Please enter Setpoint greater than 30", Toast.LENGTH_SHORT).show();
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
//---sends a SMS message to another device---
|
|
115
|
+
private void sendSMS(String phoneNumber, String message)
|
|
116
|
+
{
|
|
117
|
+
/*
|
|
118
|
+
PendingIntent pi = PendingIntent.getActivity(this, 0,
|
|
119
|
+
new Intent(this, test.class), 0);
|
|
120
|
+
SmsManager sms = SmsManager.getDefault();
|
|
121
|
+
sms.sendTextMessage(phoneNumber, null, message, pi, null);
|
|
122
|
+
*/
|
|
123
|
+
if (phoneNo.length()<9){
|
|
124
|
+
Toast.makeText(getBaseContext(),
|
|
125
|
+
"Please enter mobile number",
|
|
126
|
+
Toast.LENGTH_SHORT).show();
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
String SENT = "SMS_SENT";
|
|
131
|
+
String DELIVERED = "SMS_DELIVERED";
|
|
132
|
+
|
|
133
|
+
PendingIntent sentPI = PendingIntent.getBroadcast(this, 0,
|
|
134
|
+
new Intent(SENT), 0);
|
|
135
|
+
|
|
136
|
+
PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,
|
|
137
|
+
new Intent(DELIVERED), 0);
|
|
138
|
+
|
|
139
|
+
//---when the SMS has been sent---
|
|
140
|
+
registerReceiver(new BroadcastReceiver(){
|
|
141
|
+
@Override
|
|
142
|
+
public void onReceive(Context arg0, Intent arg1) {
|
|
143
|
+
switch (getResultCode())
|
|
144
|
+
{
|
|
145
|
+
case Activity.RESULT_OK:
|
|
146
|
+
Toast.makeText(getBaseContext(), "SMS sent",
|
|
147
|
+
Toast.LENGTH_SHORT).show();
|
|
148
|
+
break;
|
|
149
|
+
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
|
|
150
|
+
Toast.makeText(getBaseContext(), "Generic failure",
|
|
151
|
+
Toast.LENGTH_SHORT).show();
|
|
152
|
+
break;
|
|
153
|
+
case SmsManager.RESULT_ERROR_NO_SERVICE:
|
|
154
|
+
Toast.makeText(getBaseContext(), "No service",
|
|
155
|
+
Toast.LENGTH_SHORT).show();
|
|
156
|
+
break;
|
|
157
|
+
case SmsManager.RESULT_ERROR_NULL_PDU:
|
|
158
|
+
Toast.makeText(getBaseContext(), "Null PDU",
|
|
159
|
+
Toast.LENGTH_SHORT).show();
|
|
160
|
+
break;
|
|
161
|
+
case SmsManager.RESULT_ERROR_RADIO_OFF:
|
|
162
|
+
Toast.makeText(getBaseContext(), "Radio off",
|
|
163
|
+
Toast.LENGTH_SHORT).show();
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}, new IntentFilter(SENT));
|
|
168
|
+
|
|
169
|
+
//---when the SMS has been delivered---
|
|
170
|
+
registerReceiver(new BroadcastReceiver(){
|
|
171
|
+
@Override
|
|
172
|
+
public void onReceive(Context arg0, Intent arg1) {
|
|
173
|
+
switch (getResultCode())
|
|
174
|
+
{
|
|
175
|
+
case Activity.RESULT_OK:
|
|
176
|
+
Toast.makeText(getBaseContext(), "SMS delivered",
|
|
177
|
+
Toast.LENGTH_SHORT).show();
|
|
178
|
+
break;
|
|
179
|
+
case Activity.RESULT_CANCELED:
|
|
180
|
+
Toast.makeText(getBaseContext(), "SMS not delivered",
|
|
181
|
+
Toast.LENGTH_SHORT).show();
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}, new IntentFilter(DELIVERED));
|
|
186
|
+
|
|
187
|
+
SmsManager sms = SmsManager.getDefault();
|
|
188
|
+
sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
public static void setTemp(String temp){
|
|
192
|
+
txt4.setText(temp);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
public static void setHum(String hum){
|
|
196
|
+
txt5.setText(hum);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
public static void setMode(String mode){
|
|
200
|
+
txt8.setText(mode);
|
|
201
|
+
}
|
|
202
|
+
}
|
RemoteMonitorApp/src/com/pyros2097/remoteMonitor/SmsReceiver.java
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
package com.pyros2097.remoteMonitor;
|
|
2
|
+
|
|
3
|
+
import android.content.BroadcastReceiver;
|
|
4
|
+
import android.content.Context;
|
|
5
|
+
import android.content.Intent;
|
|
6
|
+
import android.os.Bundle;
|
|
7
|
+
import android.telephony.SmsMessage;
|
|
8
|
+
import android.widget.Toast;
|
|
9
|
+
|
|
10
|
+
public class SmsReceiver extends BroadcastReceiver
|
|
11
|
+
{
|
|
12
|
+
@Override
|
|
13
|
+
public void onReceive(Context context, Intent intent)
|
|
14
|
+
{
|
|
15
|
+
//---get the SMS message passed in---
|
|
16
|
+
Bundle bundle = intent.getExtras();
|
|
17
|
+
SmsMessage[] msgs = null;
|
|
18
|
+
String str = "";
|
|
19
|
+
if (bundle != null)
|
|
20
|
+
{
|
|
21
|
+
//---retrieve the SMS message received---
|
|
22
|
+
Object[] pdus = (Object[]) bundle.get("pdus");
|
|
23
|
+
msgs = new SmsMessage[pdus.length];
|
|
24
|
+
for (int i=0; i<msgs.length; i++){
|
|
25
|
+
msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
|
|
26
|
+
//str += "SMS from " + msgs[i].getOriginatingAddress();
|
|
27
|
+
//str += " :";
|
|
28
|
+
str += msgs[i].getMessageBody().toString();
|
|
29
|
+
parseSMS(str);
|
|
30
|
+
}
|
|
31
|
+
//---display the new SMS message---
|
|
32
|
+
Toast.makeText(context, str, Toast.LENGTH_SHORT).show();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public void parseSMS(String msg){
|
|
37
|
+
String fval= "";
|
|
38
|
+
if(msg.contains("Humidity")){
|
|
39
|
+
fval = msg.substring(10, 15);
|
|
40
|
+
SMSTest.setHum(fval);
|
|
41
|
+
}
|
|
42
|
+
if(msg.contains("Temperature")){
|
|
43
|
+
fval = msg.substring(13, 18);
|
|
44
|
+
SMSTest.setTemp(fval);
|
|
45
|
+
}
|
|
46
|
+
if(msg.contains("Automatic Mode")){
|
|
47
|
+
SMSTest.setMode("Mode: AUTO");
|
|
48
|
+
}
|
|
49
|
+
if(msg.contains("Manual Mode")){
|
|
50
|
+
SMSTest.setMode("Mode: MANUAL");
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
Screenshot_2013-06-07-20-33-12.png
ADDED
|
Binary file
|
Screenshot_2013-06-07-20-33-31.png
ADDED
|
Binary file
|
Screenshot_2013-06-09-21-22-02.png
ADDED
|
Binary file
|
block.png
ADDED
|
Binary file
|
flow1.png
ADDED
|
Binary file
|
flow2.png
ADDED
|
Binary file
|
flow3.png
ADDED
|
Binary file
|
remotemonitor.png
ADDED
|
Binary file
|
snap.png
ADDED
|
Binary file
|
snap2.png
ADDED
|
Binary file
|