-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
37 lines (33 loc) · 876 Bytes
/
main.cpp
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
#include <iostream>
#include <string.h>
#include "mymosqclient.h"
//#define DEAMON 1
using namespace std;
int keepalive = 120;
int port = 1883;
char deamon_name_and_id[] = "MQTTMoodlightDeamon";
int main()
{
#ifdef DEAMON
//syslog(LOG_INFO, "Entering Daemon");
pid_t pid, sid;
pid = fork();
if (pid < 0) { exit(EXIT_FAILURE); }
if (pid > 0) { exit(EXIT_SUCCESS); }
umask(0);
sid = setsid();
if (sid < 0) { exit(EXIT_FAILURE); }
if ((chdir("/")) < 0) { exit(EXIT_FAILURE); }
close(STDIN_FILENO);
close(STDOUT_FILENO);
close(STDERR_FILENO);
#endif // DEAMON
MQTTSerialInterface *client = new MQTTSerialInterface(deamon_name_and_id, HOST , port, keepalive);
client->subscribe(NULL, TOPIC, qos);
client->subscribe(NULL, "kitchen/shutdown/", qos);
while(true)
{
usleep(1000000);
}
return 0;
}