Commit ebd3a38f authored by Daniele Tafani's avatar Daniele Tafani
Browse files

The collectagent command accepts now an argument to specify the listen...

The collectagent command accepts now an argument to specify the listen address. If no arguments are passed, the collectagent listens by default to localhost at port 1883.
parent 6f53fa99
......@@ -8,6 +8,8 @@
#include <cstdlib>
#include <signal.h>
#include <unistd.h>
#include <string>
#include <boost/date_time/posix_time/posix_time.hpp>
......@@ -21,6 +23,7 @@ int keepRunning;
uint64_t msgCtr;
uint64_t pmsgCtr;
SensorDataStore *mySensorDataStore;
std::string host;
void sigHandler(int sig)
{
......@@ -78,7 +81,17 @@ void mqttCallback(SimpleMQTTMessage *msg)
delete msg;
}
int main(void) {
/*
* Print usage information
*/
void usage() {
printf("Usage: collectagent [-h <host>]\n");
printf("Collectagent will accept remote connections by listening to the\n");
printf("specified listen address <host> at port 1883 (default MQTT port).\n");
printf("The default <host> is localhost.\n\n");
}
int main(int argc, char* const argv[]) {
try{
/*
......@@ -91,10 +104,26 @@ int main(void) {
*/
mySensorDataStore = new SensorDataStore();
/* Parse command line */
char ret;
host="localhost";
while ((ret=getopt(argc, argv, "h:"))!=EOF) {
switch(ret) {
case 'h':
host = optarg;
break;
case '?':
default:
usage();
exit(EXIT_FAILURE);
}
}
/*
* Start the MQTT Message Server.
*/
SimpleMQTTServer ms;
SimpleMQTTServer ms(host,"1883");
ms.setMessageCallback(mqttCallback);
ms.start();
......@@ -132,3 +161,5 @@ int main(void) {
return EXIT_SUCCESS;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment