Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: mbed-os-example-wifi-milkcocoa MilkcocoaOsSample_Eth MilkcocoaOsSample_ESP8266 MilkcocoaOsSample_Eth_DigitalIn
Diff: Milkcocoa.cpp
- Revision:
- 8:e2f15b1b4f70
- Parent:
- 7:f1e123331cad
- Child:
- 9:5c195c1036da
--- a/Milkcocoa.cpp Thu Jun 01 05:33:50 2017 +0000
+++ b/Milkcocoa.cpp Wed Jun 14 07:48:45 2017 +0000
@@ -100,6 +100,8 @@
for (int i=0; i<MILKCOCOA_SUBSCRIBERS; i++) {
milkcocoaSubscribers[i] = NULL;
}
+ connectting = false;
+ mqtt_connectting = false;
#ifdef __MILKCOCOA_THREAD
setLoopCycle(5000);
@@ -122,6 +124,8 @@
for (int i=0; i<MILKCOCOA_SUBSCRIBERS; i++) {
milkcocoaSubscribers[i] = NULL;
}
+ connectting = false;
+ mqtt_connectting = false;
#ifdef __MILKCOCOA_THREAD
setLoopCycle(5000);
@@ -142,11 +146,14 @@
if(client->isConnected())
return;
+ connectting = true;
if(client->connect(servername, portnum)!=0) {
DBG(pc.printf("Network connect err\r\n");)
+ connectting = false;
return;
}
-
+ connectting = false;
+ mqtt_connectting = true;
MQTTPacket_connectData data = MQTTPacket_connectData_initializer;
data.keepAliveInterval = 20;
data.cleansession = 1;
@@ -157,9 +164,15 @@
if (client->connect(data) != 0) {
DBG(pc.printf("Milkcocoa connect err\r\n");)
+ mqtt_connectting = false;
return;
}
+ mqtt_connectting = false;
+}
+void Milkcocoa::close()
+{
+ client->disconnect();
}
bool Milkcocoa::push(const char *path, DataElement dataelement) {
@@ -236,6 +249,7 @@
}
void Milkcocoa::loop() {
+ if((connectting == true)||(mqtt_connectting == true)) return;
connect();
client->yield(1);