-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPingMaster.ino
197 lines (176 loc) · 4.4 KB
/
PingMaster.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/*
PingMaster project by M.J. Meijer 2014
Ping phones/tablets of friends in your network, when a phone/tablet is found => send a pushovermessage to your own phone/tablet
This way you know who is visiting you when they make contact to you wifi network
Also usefull to see if friends visited you while you where not at home
You need to give friends a static ip address on your router from the mac address of their phones/tablets
Parts needed:
-Arduino Uno http://www.dx.com/p/uno-r3-atmega328p-uno-r3-development-board-deep-blue-285620
-Ethernet Shield: http://www.dx.com/p/ethernet-shield-with-wiznet-w5100-ethernet-chip-tf-slot-118061
*/
#include <SPI.h>
#include <Ethernet.h>
#include <ICMPPing.h>
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; // mac addres for ethernet shield
byte ip[] = {192,168,2,177}; // ip address for ethernet shield
// Pushover settings
char pushoversite[] = "api.pushover.net";
char apitoken[] = "your30characterapitokenhere123";
char userkey [] = "your30characteruserkeygoeshere";
int length;
// Static IP of phones from friends
IPAddress Friend1(192,168,2,200);
IPAddress Friend2(192,168,2,201);
IPAddress Friend3(192,168,2,202);
IPAddress Friend4(192,168,2,203);
IPAddress Friend5(192,168,2,204);
// Set variables
boolean friend1po = false;
boolean friend2po = false;
boolean friend3po = false;
boolean friend4po = false;
boolean friend5po = false;
int pingfailed1 = 0;
int pingfailed2 = 0;
int pingfailed3 = 0;
int pingfailed4 = 0;
int pingfailed5 = 0;
SOCKET pingSocket = 0;
char buffer [256];
ICMPPing ping(pingSocket, (uint16_t)random(0, 255));
EthernetClient client;
/********** Setup **********/
void setup()
{
// start Ethernet
Ethernet.begin(mac, ip);
//Serial.begin(9600);
delay(2500);
pushover("The PingMaster server started");
}
/********** Loop **********/
void loop()
{
pingfriends();
}
/********** Ping telefoons van bekenden **********/
void pingfriends()
{
ICMPEchoReply echoReply1 = ping(Friend1, 4);
if (echoReply1.status == SUCCESS)
{
if (friend1po == false)
{
pushover("Phone from Friend1 detected");
friend1po = true;
}
}
else if (echoReply1.status != SUCCESS)
{
pingfailed1++;
if (pingfailed1 > 500)
{
friend1po = false;
pingfailed1 = 0;
}
}
delay(500);
ICMPEchoReply echoReply2 = ping(Friend2, 4);
if (echoReply2.status == SUCCESS)
{
if (friend2po == false)
{
pushover("Phone from Friend2 detected");
friend2po = true;
}
}
else if (echoReply2.status != SUCCESS)
{
pingfailed2++;
if (pingfailed1 > 500)
{
friend2po = false;
pingfailed2 = 0;
}
}
delay(500);
ICMPEchoReply echoReply3 = ping(Friend3, 4);
if (echoReply3.status == SUCCESS)
{
if (friend3po == false)
{
pushover("Phone from Friend3 detected");
friend3po = true;
}
}
else if (echoReply3.status != SUCCESS)
{
pingfailed3++;
if (pingfailed3 > 500)
{
friend3po = false;
pingfailed3 = 0;
}
}
delay(500);
ICMPEchoReply echoReply4 = ping(Friend4, 4);
if (echoReply4.status == SUCCESS)
{
if (friend4po == false)
{
pushover("Phone from Friend4 detected");
friend4po = true;
}
}
else if (echoReply4.status != SUCCESS)
{
pingfailed4++;
if (pingfailed4 > 500)
{
friend4po = false;
pingfailed4 = 0;
}
}
delay(500);
ICMPEchoReply echoReply5 = ping(Friend5, 4);
if (echoReply5.status == SUCCESS)
{
if (friend5po == false)
{
pushover("Phone from Friend5 detected");
friend5po = true;
}
}
else if (echoReply5.status != SUCCESS)
{
pingfailed5++;
if (pingfailed5 > 500)
{
friend5po = false;
pingfailed5 = 0;
}
}
delay(500);
}
/********** Send pushover message **********/
byte pushover(char *pushovermessage)
{
String message = pushovermessage;
length = 81 + data.length();
if(client.connect(pushoversite,80))
{
client.println("POST /1/messages.json HTTP/1.1");
client.println("Host: api.pushover.net");
client.println("Connection: close\r\nContent-Type: application/x-www-form-urlencoded");
client.print("Content-Length: ");
client.print(length);
client.println("\r\n");;
client.print("token=");
client.print(apitoken);
client.print("&user=");
client.print(userkey);
client.print("&message=");
client.print(message);
client.stop();
}
}