Initial port of the Arduino MQTT Client: http://knolleary.net/arduino-client-for-mqtt/ Updated with larger timeout and buffer sizes
Dependents: mbed_mqtt_endpoint_ublox_ethernet mbed_mqtt_endpoint_ublox_cellular mbed_mqtt_endpoint_nxp
Fork of MQTT by
Diff: PubSubClient.cpp
- Revision:
- 9:f28fd918d58c
- Parent:
- 8:40326dd71c95
--- a/PubSubClient.cpp Mon Apr 07 03:47:16 2014 +0000 +++ b/PubSubClient.cpp Mon Jun 30 22:17:23 2014 +0000 @@ -109,7 +109,11 @@ while ((len=readPacket(llen))==0) { unsigned long t = millis(); if (t-lastInActivity > MQTT_KEEPALIVE*1000UL) { +#ifdef CELLULAR_NETWORK + _client.close(); +#else _client.close(true); +#endif return false; } } @@ -120,7 +124,11 @@ return true; } } +#ifdef CELLULAR_NETWORK + _client.close(); +#else _client.close(true); +#endif } return false; } @@ -139,7 +147,11 @@ unsigned long t = millis(); if ((t - lastInActivity > MQTT_KEEPALIVE*1000UL) || (t - lastOutActivity > MQTT_KEEPALIVE*1000UL)) { if (pingOutstanding) { +#ifdef CELLULAR_NETWORK + _client.close(); +#else _client.close(true); +#endif return false; } else { buffer[0] = MQTTPINGREQ; @@ -295,7 +307,11 @@ buffer[0] = MQTTDISCONNECT; buffer[1] = 0; _client.send(buffer,2); +#ifdef CELLULAR_NETWORK + _client.close(); +#else _client.close(true); +#endif lastInActivity = lastOutActivity = millis(); } @@ -318,6 +334,10 @@ { bool rc; rc = (int)_client.is_connected(); +#ifdef CELLULAR_NETWORK + if (!rc) _client.close(); +#else if (!rc) _client.close(true); +#endif return rc; } \ No newline at end of file