-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalarme.ino
105 lines (91 loc) · 2.04 KB
/
alarme.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
Name: Alarme.ino
Created: 8/27/2015 11:03:19 PM
Author: Luiz
*/
//Server Info
#define HOST "SERVER IP OR DNS"
#define PORT 3001 //OR ANOTHER PORT
// APN data
#define APN "your APN here" // replace your GPRS APN
#define LOGIN "your APN login" // replace with your GPRS login
#define PASSWORD "your APN password" // replace with your GPRS password
//LIBRARIES
#include <SoftwareSerial.h>
#include <SIM900.h>
#include "inetGSM.h"
//Global variables
boolean started = false;
InetGSM inet;
char eventoStatus = '0';
//SIM900 IMEI
char IMEI[16] = "000000000000000"; //GSM IMEI NUMBER
//Global Constants
const int led = 12;
const int button = 4;
void setup()
{
//Serial connection.
Serial.begin(9600);
Serial.println("GSM Shield testing.");
pinMode(button, INPUT);
pinMode(led, OUTPUT);
if (gsm.begin(9600)) {
Serial.println("\nstatus=READY");
if (inet.attachGPRS(APN, LOGIN, PASSWORD)) {
Serial.println("status=ATTACHED");
if (inet.connectTCP(HOST, PORT)) {
started = true;
}
} else {
Serial.println("status=ERROR");
}
}
}
void loop()
{
if (started) {
disparaAlarme();
IMEI[15] = eventoStatus;
submit(IMEI);
}
};
void submit(char* message)
{
gsm.SimpleWriteln("AT+CIPSEND=16");
delay(500);
gsm.SimpleWriteln(message);
gsm.SimpleWriteln((char)26);
char state;
int i = 0;
for (i = 0; i < 15; i++) {
state = (char)gsm.read();
if ((state == '1') || (state == '2')) {
break;
}
}
acendeLed(state);
}
void disparaAlarme()
{
int stateButton = digitalRead(button);
if (stateButton == HIGH) {
eventoStatus = '1';
} else {
eventoStatus = '0';
}
}
void acendeLed(char state) {
switch (state) {
case '1': {
Serial.println("Alarme Ativado");
digitalWrite(led, HIGH);
break;
}
case '2': {
Serial.println("Alarme Desativado");
digitalWrite(led, LOW);
break;
}
}
}