mbed based IoT Gateway More details http://blog.thiseldo.co.uk/wp-filez/IoTGateway.pdf
Dependencies: NetServices FatFileSystem csv_parser mbed MQTTClient RF12B DNSResolver SDFileSystem
Diff: Outputs/OutputMqtt.cpp
- Revision:
- 2:27714c8c9c0a
- Parent:
- 0:a29a0225f203
- Child:
- 5:0dbc27a7af55
--- a/Outputs/OutputMqtt.cpp Mon Apr 02 22:06:46 2012 +0000 +++ b/Outputs/OutputMqtt.cpp Thu Apr 05 08:03:07 2012 +0000 @@ -37,11 +37,11 @@ sendCount = 0; } -void callback(char* topic, char* payload); /*Callback function prototype*/ +static void callback(char* topic, char* payload); /*Callback function prototype*/ //MQTTClient mqtt(serverIpAddr, 1883, callback); -void callback(char* topic, char* payload) +static void callback(char* topic, char* payload) { printf("Topic: %s\r\n", topic); printf("Payload: %s\r\n\r\n", payload); @@ -54,13 +54,15 @@ this->password = password; } -void OutputMqtt::init( ) { +bool OutputMqtt::init( ) { // printf("MQTT server ip is %d.%d.%d.%d\n",serverIpAddr[0],serverIpAddr[1],serverIpAddr[2],serverIpAddr[3]); - mqtt.init(serverIpAddr, port, callback); + mqtt.init(serverIpAddr, port, username, password, callback); if(!mqtt.connect("IoTGateway")){ printf("\r\nConnect to server failed ..\r\n"); - // return -1; + mqtt.disconnect(); + return false; } + return true; } // These are used to send @@ -71,6 +73,7 @@ // send here does nothing int OutputMqtt::send( void ) { + mqtt.live(); return 0; }