Skip to content

Commit 304352a

Browse files
authored
Update: RSSI und MAC an den Server senden
1 parent 4ed4060 commit 304352a

File tree

2 files changed

+108
-4
lines changed

2 files changed

+108
-4
lines changed

Mappings.h

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
2+
#ifndef MAPPINGS_H
3+
#define MAPPINGS_H
4+
5+
template<typename hash, typename map>
6+
class HashType {
7+
public:
8+
HashType() {
9+
reset();
10+
}
11+
12+
HashType(hash code, map value): hashCode(code), mappedValue(value) {}
13+
14+
void reset() {
15+
hashCode = 0;
16+
mappedValue = 0;
17+
}
18+
hash getKey() {
19+
return hashCode;
20+
}
21+
void setKey(hash code) {
22+
hashCode = code;
23+
}
24+
map getValue() {
25+
return mappedValue;
26+
}
27+
void setValue(map value) {
28+
mappedValue = value;
29+
}
30+
31+
HashType& operator()(hash key, map value) {
32+
setKey(key);
33+
setValue(value);
34+
}
35+
private:
36+
hash hashCode;
37+
map mappedValue;
38+
};
39+
40+
template<typename hash, typename map>
41+
class HashMap {
42+
public:
43+
HashMap() {
44+
45+
}
46+
47+
HashType<hash, map>& operator[](int x) {
48+
return hashMap[x];
49+
}
50+
51+
byte getIndexOf(hash key ) {
52+
for (byte i = 0; i < hashMap.size(); i++) {
53+
if (hashMap[i].getKey() == key) {
54+
return i;
55+
}
56+
}
57+
}
58+
map get(hash key) {
59+
for (int i = 0; i < hashMap.size(); i++) {
60+
if (hashMap[i].getKey() == key) {
61+
return hashMap[i].getValue();
62+
}
63+
}
64+
return 0;
65+
}
66+
67+
void clear() {
68+
hashMap.clear();
69+
}
70+
71+
void put(hash key, map object) {
72+
boolean setted = true;
73+
for (int i = 0; i < hashMap.size(); i++) {
74+
if (hashMap[i].getKey() == key) {
75+
hashMap[i].setValue(object);
76+
setted = false;
77+
}
78+
}
79+
if(setted) {
80+
HashType<hash, map> cur;
81+
cur.setKey(key);
82+
cur.setValue(object);
83+
hashMap.add(cur);
84+
}
85+
}
86+
87+
88+
private:
89+
ArrayList<HashType<hash, map>> hashMap;
90+
};
91+
92+
#endif

wifi_probe.ino

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "ESP8266WiFi.h"
22

33
#include "ArrayList.h"
4+
#include "Mappings.h"
45
#include "RXSniffer.h"
56
#include "Util.h"
67
#include "WebPageStore.h"
@@ -45,7 +46,7 @@ int checktime = 10;
4546
long lastdata = 0;
4647

4748
ArrayList<String> devices;
48-
49+
HashMap<String, int> rssimap;
4950

5051

5152

@@ -151,6 +152,7 @@ static void showMetadata(SnifferPacket *snifferPacket) {
151152
if (!devices.contains((String) addr)) {
152153
devices.add((String) addr);
153154
}
155+
rssimap.put((String) addr, rssi);
154156
}
155157
}
156158

@@ -242,10 +244,10 @@ void loop() {
242244
if (WiFi.status() != WL_CONNECTED) {
243245
WiFi.begin(wifiname, wifipass);
244246
}
245-
if ((lastdata + (checktime * 60000)) < millis()) {
247+
if ((lastdata + (20000)) < millis()) {
248+
// if ((lastdata + (checktime * 60000)) < millis()) {
246249
lastdata = millis();
247250
int devs = devices.size();
248-
devices.clear();
249251
WiFi.persistent(false);
250252
delay(20);
251253
// WiFi.setAutoReconnect(false);
@@ -306,9 +308,16 @@ void loop() {
306308
WiFiClient client;
307309
client.connect(ip, port);
308310

309-
client.println("WiFiProbe V0.1");
311+
client.println("WiFiProbe V0.1.1");
310312
client.println(room);
311313
client.println(String(devs));
314+
String currentdev;
315+
for (int i = 0; i < devices.size(); i++) {
316+
currentdev = devices[i];
317+
client.println(currentdev);
318+
client.println(String(rssimap.get(currentdev)));
319+
}
320+
312321

313322
client.stop();
314323

@@ -461,4 +470,7 @@ void recheckWiFi() {
461470
os_timer_disarm(&channelHop_timer);
462471
os_timer_setfn(&channelHop_timer, (os_timer_func_t *) channelHop, NULL);
463472
os_timer_arm(&channelHop_timer, CHANNEL_HOP_INTERVAL_MS, 1);
473+
474+
devices.clear();
475+
rssimap.clear();
464476
}

0 commit comments

Comments
 (0)