-
Notifications
You must be signed in to change notification settings - Fork 0
/
lansensor.h
69 lines (49 loc) · 1.62 KB
/
lansensor.h
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
/*
Office presence sensor monitoring LAN devices
Copyright (C) 2012-2013 Tuomas Haapala, Nemein <[email protected]>
*/
#ifndef LANSENSOR_H
#define LANSENSOR_H
#include "mosquittohandler.h"
#include "datagetter.h"
#include "arpscanner.h"
class LANSensor
{
public:
LANSensor();
~LANSensor();
bool initAll(std::string configFileName);
void run();
private:
// gets device info json from server and updates the local device database
bool updateDeviceData();
// checks if devices in the local database exist in the lan.
// sends results using mqtt
bool checkDevices();
// checks incoming messages if they contain request for database update or device discovery
void processIncomingMessages(bool& updateDB, bool& scan);
// scans lan and sends every found device using mqtt
bool discoverDevices();
// tries to connect mosquitto when it didn't succeed normally or connection was lost
bool connectMosquitto(bool reconnect = true);
// sends hello message using mqtt
void sendHello();
void print(std::string str, bool endl = true);
void printError(std::string str);
// returns sensor's own MAC address
std::string getOwnMAC();
bool m_running;
ARPScanner* m_ARPScanner;
MosquittoHandler* m_mosquitto;
DataGetter* m_dataGetter;
std::string m_sensorID;
std::vector<std::string> m_devices;
std::string m_arpscan_parameters;
std::string m_brokerAddress;
uint16_t m_brokerPort;
std::string m_dataFetchUrl;
int16_t m_scanInterval;
int16_t m_connectAttemptInterval;
bool m_updateDBNeeded;
};
#endif // LANSENSOR_H