MQTT Client example program. Ethernet connection is via an ENC28J60 module.
Dependencies: UIPEthernet MQTTClient
Diff: main.cpp
- Revision:
- 6:fb8b9925e844
- Parent:
- 3:3e5f4d503a66
- Child:
- 7:4435b52322e4
--- a/main.cpp Sat Nov 28 10:33:33 2015 +0000 +++ b/main.cpp Sat Nov 28 11:49:50 2015 +0000 @@ -39,7 +39,7 @@ const IPAddress MY_IP(192, 168, 1, 181); #endif -const int INTERVAL = 10; // Interval for publishing the messages (in seconds) +const int INTERVAL = 5; // Interval for publishing the messages (in seconds) char message_buff[100]; @@ -101,7 +101,7 @@ // The client can subscribe to as many topics as you like. mqttClient.subscribe("outdoor/temperature"); mqttClient.subscribe("boiler/outlet/temperature"); - pc.printf("Subscribed to the following topics:\r\n"); + pc.printf("Subscribing to topics:\r\n"); pc.printf(" outdoor/temperature\r\n"); pc.printf(" boiler/outlet/temperature\r\n"); } @@ -111,11 +111,11 @@ while(1) { t = time(NULL); - if(t > (lastTime + 5)) { + if(t > (lastTime + INTERVAL)) { lastTime = t; if(connected) { mqttClient.publish("example/hello", payload); - pc.printf("Published: example/hello\r\n"); + pc.printf("Publishing: example/hello\r\n"); } } mqttClient.loop(); // MQTT client loop processing (receiving messages) @@ -143,5 +143,5 @@ } message_buff[i] = '\0'; - pc.printf(" Payload: %s\r\n", message_buff); + pc.printf(" Payload: %s\r\n", message_buff); }