Deadlock on the cloud inboud handler

Hi community

I’m having an issue I still didn’t find anyone complaining about.

I’ve created a route in the Hologram Cloud to other cloud. This other cloud will reply with a string back to the Hologram Cloud to the port 4444.
This message received on the port 4444 should be read on the hologram dash.

The issue:

Sometimes, I get a deadlock on the hologram cloud handle and sometimes I don’t receive anything from the port 4444.

For the sake of simplicity, I’ve removed all the classes from my code, and left only a single file to reproduce this issue.
To test this, you will need to have a route in Hologram Cloud to another Cloud (Azure, for example), and have this other cloud to reply something back back to Hologram Cloud to port 4444.

I’ve created this sample, where every 25 seconds, it will send a message to the cloud.
It takes sometime to start, since I’m waiting 20seconds to be connected to the network.
(I see my messages on the Hologram Cloud) and the OK message on my hologram cloud.

Here is my code:

static const int 	mSizeInBound = 4096;
char 				mBufferInbound[mSizeInBound];
volatile bool 		mNewCloudMsg;
uint32_t 			mAliveTimeCheck;
const int			mAliveTimeoutMs = 1 * 1000; // 1 second

void inbound(int length)
{
	mBufferInbound[length] = 0;
	mNewCloudMsg = true;
}

void notify(cloud_event e)
{
	switch(e)
	{
	case CLOUD_EVENT_DISCONNECTED:
		HologramCloud.listen(4444);
		break;
    }
}

void send(const String& msg, const String& topic)
{
	String tmp = "topic: " + topic;
	tmp += " msg: ";
	tmp += msg;
	Serial.print("Sending to cloud = ");
	Serial.println(tmp);

	HologramCloud.connect();
	HologramCloud.print(msg);
	HologramCloud.attachTopic(topic);

	if(HologramCloud.sendMessage() == false)
	{
		Serial.println("Msg was not sent to Cloud :(");
	}
	else
	{
		Serial.println("Msg was sent to Cloud :)");
	}
}

void setup()
{
	Serial.begin(9600);

	HologramCloud.clear();
	HologramCloud.disconnect();
	HologramCloud.resetSystem();
	HologramCloud.powerDown();

	delay(5000);
	HologramCloud.attachHandlerInbound(inbound, mBufferInbound, mSizeInBound - 1);
	HologramCloud.attachHandlerNotify(notify);
	HologramCloud.begin();
	HologramCloud.resetSystem();
	delay(20000);
	HologramCloud.listen(4444);

}

void loop()
{
	const uint32_t ms = millis();
    if (mAliveTimeCheck < ms)
    {
    	mAliveTimeCheck = ms + mAliveTimeoutMs;

    	Serial.print(".");

		static int counter = 0;
		Serial.print(counter);
		Serial.print(" ");
		Serial.print(millis());
		Serial.print(" ");
		counter++;

		Serial.println(HologramCloud.getNetworkOperator());

		static int count = 0;
		count++;
		if(count % 25 == 0)
		{
			send("{\"test\":\"987654321\"}", "TESTTOPIC");
		}
    }

    HologramCloud.pollEvents();

	if(true == mNewCloudMsg)
	{
		mNewCloudMsg = false;
            Serial.println("Received from cloud:");
            Serial.println(mBufferInbound);
	}
	HologramCloud.powerUp();
}

And here is the output:

.0 25657 vodafone P
.1 26675 vodafone P
.2 27682 vodafone P
.3 28689 vodafone P
.4 29699 vodafone P
.5 30706 vodafone P
.6 31712 vodafone P
.7 32720 vodafone P
.8 33725 vodafone P
.9 34732 vodafone P
.10 35739 vodafone P
.11 36754 vodafone P
.12 37761 vodafone P
.13 38764 vodafone P
.14 39769 vodafone P
.15 40771 vodafone P
.16 41776 vodafone P
.17 42780 vodafone P
.18 43782 vodafone P
.19 44788 vodafone P
.20 45789 vodafone P
.21 46793 vodafone P
.22 47803 vodafone P
.23 48816 vodafone P
.24 49835 vodafone P
Sending to cloud = topic: TESTTOPIC msg: {"test":"987654321"}
Msg was sent to Cloud :)
.25 53128 vodafone P
.26 54132 vodafone P
.27 55134 vodafone P
.28 56137 vodafone P
Received from cloud:
True
.29 57147 vodafone P
.30 58151 vodafone P
.31 59152 vodafone P
.32 60156 vodafone P
.33 61163 vodafone P
.34 62166 vodafone P
.35 63178 vodafone P
.36 64197 vodafone P
.37 65200 vodafone P
.38 66209 vodafone P
.39 67214 vodafone P
.40 68215 vodafone P
.41 69216 vodafone P
.42 70218 vodafone P
.43 71225 vodafone P
.44 72227 vodafone P
.45 73229 vodafone P
.46 74232 vodafone P
.47 75248 vodafone P
.48 76268 vodafone P
.49 77282 vodafone P
Sending to cloud = topic: TESTTOPIC msg: {"test":"987654321"}
Msg was sent to Cloud :)
.50 79489 vodafone P
.51 80493 vodafone P
.52 81500 vodafone P
.53 82504 vodafone P
Received from cloud:
True
.54 83815 vodafone P
.55 84819 vodafone P
.56 85819 vodafone P
.57 86824 vodafone P
.58 87827 vodafone P
.59 88832 vodafone P
.60 89835 vodafone P
.61 90836 vodafone P
.62 91842 vodafone P
.63 92844 vodafone P
.64 93846 vodafone P
.65 94849 vodafone P
.66 95872 vodafone P
.67 96887 vodafone P
.68 97902 vodafone P
.69 98911 vodafone P
.70 99925 vodafone P
.71 100939 vodafone P
.72 101956 vodafone P
.73 102969 vodafone P
.74 103984 vodafone P
Sending to cloud = topic: TESTTOPIC msg: {"test":"987654321"}
Msg was sent to Cloud :)
.75 106939 vodafone P
.76 107944 vodafone P
.77 108947 vodafone P
.78 109972 vodafone P
Received from cloud:
True
.79 110989 vodafone P
.80 111993 vodafone P
.81 112998 vodafone P
.82 114002 vodafone P
.83 115009 vodafone P
.84 116811 vodafone P
.85 117825 vodafone P
.86 118826 vodafone P
.87 119827 vodafone P
.88 120830 vodafone P
.89 121834 vodafone P
.90 122837 vodafone P
.91 123839 vodafone P
.92 124843 vodafone P
.93 125846 vodafone P
.94 126851 vodafone P
.95 127869 vodafone P
.96 128884 vodafone P
.97 129898 vodafone P
.98 130908 vodafone P
.99 131923 vodafone P
Sending to cloud = topic: TESTTOPIC msg: {"test":"987654321"}
Msg was sent to Cloud :)
.100 134310 vodafone P
.101 135332 vodafone P
.102 136335 vodafone P
Received from cloud:
True
.103 137396 vodafone P
.104 138406 vodafone P
.105 139412 vodafone P
.106 140421 vodafone P
.107 141440 vodafone P
.108 142441 vodafone P
.109 143462 vodafone P
.110 144464 vodafone P
.111 145467 vodafone P
.112 146488 vodafone P
.113 147493 vodafone P
.114 148496 vodafone P
.115 149500 vodafone P
.116 150502 vodafone P
.117 151507 vodafone P
.118 152521 vodafone P
.119 153534 vodafone P
.120 154555 vodafone P
.121 155564 vodafone P
.122 156575 vodafone P
.123 157587 vodafone P
.124 158604 vodafone P
Sending to cloud = topic: TESTTOPIC msg: {"test":"987654321"}
Msg was sent to Cloud :)
.125 161040 vodafone P
.126 162047 vodafone P
.127 163048 vodafone P
.128 164815 vodafone P
Received from cloud:
True
.129 165822 vodafone P
.130 167481 Not available
.131 168497 vodafone P
.132 169504 vodafone P
.133 170507 vodafone P
.134 171509 vodafone P
.135 172530 vodafone P
.136 173532 vodafone P
.137 174540 vodafone P
.138 175541 vodafone P
.139 176544 vodafone P
.140 177546 vodafone P
.141 178555 vodafone P
.142 179568 vodafone P
.143 180584 vodafone P
.144 181598 vodafone P
.145 182613 vodafone P
.146 183622 vodafone P
.147 184637 vodafone P
.148 185646 vodafone P
.149 186660 vodafone P
Sending to cloud = topic: TESTTOPIC msg: {"test":"987654321"}
Msg was sent to Cloud :)
.150 189021 vodafone P
.151 190026 vodafone P
.152 192016 vodafone P
Received from cloud:

.153 193022 vodafone P
.154 194023 vodafone P
.155 195033 vodafone P
.156 196045 vodafone P
.157 197826 vodafone P
.158 198831 vodafone P
.159 199834 vodafone P
.160 200838 vodafone P
.161 201841 vodafone P
.162 202842 vodafone P
.163 203843 vodafone P
.164 204849 vodafone P
.165 205850 vodafone P
.166 206852 vodafone P
.167 207859 vodafone P
.168 208871 vodafone P
.169 209881 vodafone P
.170 210895 vodafone P
.171 211908 vodafone P
.172 212919 vodafone P
.173 213933 vodafone P
.174 214955 vodafone P
Sending to cloud = topic: TESTTOPIC msg: {"test":"987654321"}
Msg was sent to Cloud :)
.175 217324 vodafone P
.176 218328 vodafone P
.177 219334 vodafone P
.178 220458 vodafone P
Received from cloud:
True
.179 221461 vodafone P
.180 222467 vodafone P
.181 224097 vodafone P
.182 225102 vodafone P
.183 226104 vodafone P
.184 227106 vodafone P
.185 228109 vodafone P
.186 229110 vodafone P
.187 230118 vodafone P
.188 231119 vodafone P
.189 232123 vodafone P
.190 233126 vodafone P
.191 234138 vodafone P
.192 235152 vodafone P
.193 236167 vodafone P
.194 237179 vodafone P
.195 238191 vodafone P
.196 239205 vodafone P
.197 240220 vodafone P
.198 241230 vodafone P
.199 242241 vodafone P
Sending to cloud = topic: TESTTOPIC msg: {"test":"987654321"}
Msg was sent to Cloud :)
.200 244408 vodafone P
.201 245415 vodafone P
.202 246419 vodafone P
Received from cloud:
True
.203 247432 vodafone P
.204 248434 vodafone P
.205 249437 vodafone P
.206 250441 vodafone P
.207 251452 vodafone P
.208 253238 vodafone P
.209 254244 vodafone P
.210 255248 vodafone P
.211 256249 vodafone P
.212 257252 vodafone P
.213 258255 vodafone P
.214 259260 vodafone P
.215 260262 vodafone P
.216 261263 vodafone P
.217 262267 vodafone P
.218 263273 vodafone P
.219 264286 vodafone P
.220 265295 vodafone P
.221 266309 vodafone P
.222 267318 vodafone P
.223 268332 vodafone P
.224 269353 vodafone P
Sending to cloud = topic: TESTTOPIC msg: {"test":"987654321"}
Msg was sent to Cloud :)
.225 271320 vodafone P
.226 272334 vodafone P
Received from cloud:
True
.227 273875 vodafone P
.228 274881 vodafone P
.229 275886 vodafone P
.230 278072 vodafone P
.231 279084 vodafone P
.232 280085 vodafone P
.233 281106 vodafone P
.234 282112 vodafone P
.235 283115 vodafone P
.236 284118 vodafone P
.237 285121 vodafone P
.238 286125 vodafone P
.239 287130 vodafone P
.240 288147 vodafone P
.241 289162 vodafone P
.242 290176 vodafone P
.243 291191 vodafone P
.244 292209 vodafone P
.245 293223 vodafone P
.246 294238 vodafone P
.247 295254 vodafone P
.248 296269 vodafone P
.249 297289 vodafone P
Sending to cloud = topic: TESTTOPIC msg: {"test":"987654321"}
Msg was sent to Cloud :)
.250 299330 vodafone P
.251 300333 vodafone P
.252 302095 vodafone P
Received from cloud:
True
.253 303098 vodafone P
.254 304099 vodafone P
.255 305101 vodafone P
.256 306106 vodafone P
.257 307125 vodafone P
.258 308323 Not available
.259 309332 vodafone P
.260 310336 vodafone P
.261 311339 vodafone P
.262 312345 vodafone P
.263 313348 vodafone P
.264 314353 vodafone P
.265 315356 vodafone P
.266 316359 vodafone P
.267 317365 vodafone P
.268 318369 vodafone P
.269 319384 vodafone P
.270 320398 vodafone P
.271 321409 vodafone P
.272 322424 vodafone P
.273 323439 vodafone P
.274 324454 vodafone P
Sending to cloud = topic: TESTTOPIC msg: {"test":"987654321"}
Msg was sent to Cloud :)
.275 326490 vodafone P
.276 327494 vodafone P <------- DEADLOCK HERE

If you take a look at the output above, there ate two things here:

  • On the second .152, I could not get the string (True) back from the cloud
  • On the second .276, as soon as we should have the cloud handler being executed, there was a deadlock on the code. Where it stays like this forever. I could unblock this only by sending manually a message to the port 4444 using the known API:

Is this a firmware bug?

PS:
The .276 second was random, because if I re-test this it can enter the deadlock at another time, for example see the test I’ve made right after:

.0 29796 vodafone P
.1 30813 vodafone P
.2 31819 vodafone P
.3 32826 vodafone P
.4 33833 vodafone P
.5 34840 vodafone P
.6 35856 vodafone P
.7 36867 vodafone P
.8 37868 vodafone P
.9 38873 vodafone P
.10 39879 vodafone P
.11 40884 vodafone P
.12 41885 vodafone P
.13 42891 vodafone P
.14 44429 Not available
.15 45450 vodafone P
.16 46454 vodafone P
.17 47470 vodafone P
.18 48481 vodafone P
.19 49494 vodafone P
.20 50510 vodafone P
.21 51523 vodafone P
.22 52539 vodafone P
.23 53558 vodafone P
.24 54573 vodafone P
Sending to cloud = topic: TESTTOPIC msg: {"test":"987654321"}
Msg was sent to Cloud :)
.25 57317 vodafone P
.26 58322 vodafone P
.27 59331 vodafone P
.28 60336 vodafone P <------- DEADLOCK HERE

I’m using:

Board version: 0.11.0
Dash Boot Version: 3.1.1
Dash Boot Version Number: 196865
Hologram Cloud System Version: 0.10.1

Thank you,
jpgl

Upon reading your code, I noticed the .connect is called everytime send command is called. Though .connect is a non-blocking command, I guess some of it’s underlying AT commands are doing some network communication and waiting for URCs… and those ‘might’ caused some traffic in the SystemSerial port.

On another note, I’ve seen the system firmware re-establish network and cloud re-connections automatically (when running REPL sample code).

So try to consider using switch case for .getConnectionStatus or .isconnected rather than calling .connect in your send command block.

Hi Arnold

Thanks for the tip.
I’ve now changed as you’ve suggested on the send() function.

From:

HologramCloud.connect();

To:

if(HologramCloud.isConnected() == false)
{
	HologramCloud.connect();
}

But I’m afraid the issue remains :frowning:

I still have the deadklock after a while, and randomly.

Kind regards,
jpgl

I want to work you on this because I too am encountering some connection/registration issues in DASH U201.

  1. Please add Serial log inside .isConnected to see if the code pass to this state.
  2. If indeed it passes through this state multiple times, then you have no significant change in code yet (because it just call the .connect as before.
  3. I suggest you ‘block’ your process and wait for .isConnected to turn true like the following:
    while(!HologramCloud.isConnected()) {
    //do nothing and just wait for System Firmware to reconnect.
    Serial.print(".");
    }
  4. If in case the .isConnected is always true, then try to add delay(500) between sending data and reading data… This works for me in some cases.

Hi Arnold

Thanks for the reply. I’m also using the DASH U201 for this.

I’ve re-factored the code to have your suggestion in the 3. here:

if(HologramCloud.isConnected() == false)
{
	Serial.print("[NOT CONNECTED TO THE NETWORK]");
	HologramCloud.connect();
	while(HologramCloud.isConnected() == false)
	{
		Serial.println(".");
		delay(100);
	}
	Serial.print("[NOW IS CONNECTED TO THE NETWORK]");
}

And also right after send() and before HologramCloud.pollEvents() added a 500ms delay following your 4. suggestion:

The full source that I’m using for testing, already taking into account your tips is the following (please check the comments saying "------NEW-----" :

 static const int 	mSizeInBound = 4096;
 char 				mBufferInbound[mSizeInBound];
 volatile bool 		mNewCloudMsg;
 uint32_t 			mAliveTimeCheck;
 const int			mAliveTimeoutMs = 1 * 1000; // 1 second

 void inbound(int length)
 {
 	mBufferInbound[length] = 0;
 	mNewCloudMsg = true;
 }

 void notify(cloud_event e)
 {
 	switch(e)
 	{
 	case CLOUD_EVENT_DISCONNECTED:
 		HologramCloud.listen(4444);
 		break;
     }
 }

 void send(const String& msg, const String& topic)
 {
 	String tmp = "topic: " + topic;
 	tmp += " msg: ";
 	tmp += msg;
 	Serial.print("Sending to cloud = ");
 	Serial.println(tmp);

    //------------ NEW ---------------
 	if(HologramCloud.isConnected() == false)
 	{
 		Serial.print("[NOT CONNECTED TO THE NETWORK]");
 		HologramCloud.connect();
 		while(HologramCloud.isConnected() == false)
 		{
 			Serial.println(".");
 			delay(100);
 		}
 		Serial.print("[NOW IS CONNECTED TO THE NETWORK]");
 	}
    //-------------------------------

 	HologramCloud.print(msg);
 	HologramCloud.attachTopic(topic);

 	if(HologramCloud.sendMessage() == false)
 	{
 		Serial.println("Msg was not sent to Cloud :(");
 	}
 	else
 	{
 		Serial.println("Msg was sent to Cloud :)");
 	}
 }

 void setup()
 {
 	Serial.begin(9600);

 	HologramCloud.clear();
 	HologramCloud.disconnect();
 	HologramCloud.resetSystem();
 	HologramCloud.powerDown();

 	delay(5000);
 	HologramCloud.attachHandlerInbound(inbound, mBufferInbound, mSizeInBound - 1);
 	HologramCloud.attachHandlerNotify(notify);
 	HologramCloud.begin();
 	HologramCloud.resetSystem();
 	delay(20000);
 	HologramCloud.listen(4444);

 }

 void loop()
 {
 	const uint32_t ms = millis();
     if (mAliveTimeCheck < ms)
     {
     	mAliveTimeCheck = ms + mAliveTimeoutMs;

     	Serial.print(".");

 		static int counter = 0;
 		Serial.print(counter);
 		Serial.print(" ");
 		Serial.print(millis());
 		Serial.print(" ");
 		counter++;

 		Serial.println(HologramCloud.getNetworkOperator());

 		static int count = 0;
 		count++;
 		if(count % 25 == 0)
 		{
 			send("{\"test\":\"987654321\"}", "TESTTOPIC");
 			//------------ NEW ---------------
            delay(500); // 500ms between sending data and reading data
 			//------------------------------------
 		}
     }

     HologramCloud.pollEvents();

 	if(true == mNewCloudMsg)
 	{
 		mNewCloudMsg = false;
        Serial.println("Received from cloud:");
        Serial.println(mBufferInbound);
 	}

 	HologramCloud.powerUp();
 }

Unfortunatelly the issue still remains…

The delay of 500ms could fix, but apparently not. However I find strange that we would need such a delay before reading, since the cloud inboud handler should be executed only when a message is there to read, on the HologramCloud.pollEvents(), right?

Regarding .pollEvents, I need to read the source code to better understand it, so no comment for now.

BTW, did the serial monitor logged the messages inside the NEW code block?

Hi Arnold

I didn’t paste here the output of the serial monitor because it’s basically the same as my first post… after a while, it locks on the cloud inbound handler on the time it should receive and message from the cloud.

I’ve read somewhere on this community forum about TCP connection being lost on the cloud handler… Maybe this is something related?

Kind regards,
jpgl

If log is still the same as before, then it means your cloud connection is stable and problem is somewhere else.

I’ll try to find time to look into the cloud inbound… I haven’t tried to use TCP on Hologram cloud using their AT command wrappers yet. All my current R&D are sending data to my client’s HTML/TCP server/network.

I’ve reviewed your code again and would like to know your purpose on:

  1. calling .powerUp in the loop (document/guide does not mention if this is ignored when .powerDown is not called).;
  2. calling .getNetworkOperator in the loop (can be done once in the setup block);
  3. calling .resetSystem in the setup (document says it is used when system processor becomes unresponsive).
  4. what you expect in the inbound method? (it just sets value of mNewCloudMsg)
    What do you think will happen if you delete the codes starting from HologramCloud.pollEvents(); down to the HologramCloud.powerUp() and transfer the below code inside inbound method:
    Serial.println(“Received from cloud:”);
    Serial.println(mBufferInbound);

Pardon if my recommendations does not make sense to you at this point.

Yes, I agree the cloud connection is stable. I’ve seen no logs on the serial from from this section below, and it never enters the condition:

if(HologramCloud.isConnected() == false)
{
	Serial.print("[NOT CONNECTED TO THE NETWORK]");
	HologramCloud.connect();
	while(HologramCloud.isConnected() == false)
	{
		Serial.println(".");
		delay(100);
	}
	Serial.print("[NOW IS CONNECTED TO THE NETWORK]");
}

Replying to your points:

Many of this implementation was based on the Hologram’s example here. But I will remove the HologramCloud.powerUp() since it’s already being powered up onthe HologramCloud.begin() and retest it.

Sometimes it take some seconds to register in the network, and this was just for debug to check which network provider was connected, since I have two Holograms dash and both connect to different network operators. But I will also remove this and re-test.

I’ve removed the clear, disconnect, reset, and powerDown from the setup. This was added to restart the whole system on boot.

The inbound method was refactored to be read and printed to the serial port outside of the cloud handler based on @Reuben’s suggestion here.
I will add again the code for reading the data from the cloud handler inside the handler itself and re-test it.

Currently the source code for testing this is the following. The ----NEW---- tag contains the differences between this post and the previous one:

static const int 	mSizeInBound = 4096;
char 				mBufferInbound[mSizeInBound];
// --------- NEW --------
//volatile bool 		mNewCloudMsg;
// ----------------------
uint32_t 			mAliveTimeCheck;
const int			mAliveTimeoutMs = 1 * 1000; // 1 second

void inbound(int length)
{
	mBufferInbound[length] = 0;

	// --------- NEW --------
 	//mNewCloudMsg = true;

    Serial.println("Received from cloud:");
    Serial.println(mBufferInbound);
    // ----------------------
}

void notify(cloud_event e)
{
	switch(e)
 	{
 	case CLOUD_EVENT_DISCONNECTED:
 		HologramCloud.listen(4444);
 		break;
     }
}

void send(const String& msg, const String& topic)
{
 	String tmp = "topic: " + topic;
 	tmp += " msg: ";
 	tmp += msg;
 	Serial.print("Sending to cloud = ");
 	Serial.println(tmp);

 	if(HologramCloud.isConnected() == false)
 	{
 		Serial.print("[NOT CONNECTED TO THE NETWORK]");
 		HologramCloud.connect();
 		while(HologramCloud.isConnected() == false)
 		{
 			Serial.println(".");
 			delay(100);
 		}
 		Serial.print("[NOW IS CONNECTED TO THE NETWORK]");
 	}

 	HologramCloud.print(msg);
 	HologramCloud.attachTopic(topic);

 	if(HologramCloud.sendMessage() == false)
 	{
 		Serial.println("Msg was not sent to Cloud :(");
 	}
 	else
 	{
 		Serial.println("Msg was sent to Cloud :)");
 	}
}

void setup()
{
 	Serial.begin(9600);

 	// --------- NEW --------
 	//HologramCloud.clear();
 	//HologramCloud.disconnect();
 	//HologramCloud.resetSystem();
 	//HologramCloud.powerDown();
 	// ----------------------

 	delay(5000);
 	HologramCloud.attachHandlerInbound(inbound, mBufferInbound, mSizeInBound - 1);
 	HologramCloud.attachHandlerNotify(notify);
 	HologramCloud.begin();
 	// --------- NEW --------
 	//HologramCloud.resetSystem();
 	// ----------------------
 	delay(20000);
 	HologramCloud.listen(4444);

}

void loop()
{
 	const uint32_t ms = millis();
     if (mAliveTimeCheck < ms)
     {
     	mAliveTimeCheck = ms + mAliveTimeoutMs;

     	Serial.print(".");

 		static int counter = 0;
 		Serial.print(counter);
 		Serial.print(" ");
 		Serial.print(millis());
 		Serial.print(" ");
 		counter++;

 		// --------- NEW --------
 		//Serial.println(HologramCloud.getNetworkOperator());
 		// ----------------------

 		static int count = 0;
 		count++;
 		if(count % 25 == 0)
 		{
 			send("{\"test\":\"987654321\"}", "TESTTOPIC");
            delay(500); // 500ms between sending data and reading data
 		}
     }

     HologramCloud.pollEvents();

    // --------- NEW --------
 	//if(true == mNewCloudMsg)
 	//{
 	//	mNewCloudMsg = false;
    //    Serial.println("Received from cloud:");
    //    Serial.println(mBufferInbound);
 	//}


 	//HologramCloud.powerUp();
 	// ----------------------
}

The output of the test is:

.0 25247 
.1 26263 
.2 27279 
.3 28295 
.4 29311 
.5 30328 
.6 31344 
.7 32360 
.8 33378 
.9 34396 
.10 35411 
.11 36428 
.12 37443 
.13 38462 
.14 39470 
.15 40484 
.16 41497 
.17 42513 
.18 43525 
.19 44541 
.20 45558 
.21 46574 
.22 47587 
.23 48605 
.24 49621 
Sending to cloud = topic: TESTTOPIC msg: {"test":"987654321"}
Msg was sent to Cloud :)
.25 52435 
.26 53451 
.27 54920 
Received from cloud:
		 <-------- NOTHING RECEIVED FROM CLOUD
.28 55928 
.29 56943 
.30 57954 
.31 58967 
.32 59986 
.33 60995 
.34 62004 
.35 63006 
.36 64019 
.37 65031 
.38 66047 
.39 67060 
.40 68074 
.41 69088 
.42 70107 
.43 71128 
.44 72142 
.45 73147 
.46 74149 
.47 75153 
.48 76158 
.49 77161 
Sending to cloud = topic: TESTTOPIC msg: {"test":"987654321"}
Msg was sent to Cloud :)
.50 79881 
.51 80896 
.52 81916 
Received from cloud:
True
.53 83417 
.54 84432 
.55 85450 
.56 86451 
.57 87695 
.58 88700 
.59 89714 
.60 90728 
.61 91744 
.62 92758 
.63 93772 
.64 94787 
.65 95800 
.66 96819 
.67 97839 
.68 98842 
.69 99846 
.70 100848 
.71 101853 
.72 102855 
.73 103864 
.74 104873 
Sending to cloud = topic: TESTTOPIC msg: {"test":"987654321"}
Msg was sent to Cloud :)
.75 108838 
.76 109843 
.77 110845 
Received from cloud:
True
.78 111851 
.79 112865 
.80 113878 
.81 114891 
.82 115907 
.83 116919 
.84 117940 
.85 118953 
.86 119959 
.87 120973 
.88 121987 
.89 123007 
.90 124023 
.91 125036 
.92 126050 
.93 127064 
.94 128083 
.95 129095 
.96 130112 
.97 131120 
.98 132125 
.99 133135 
Sending to cloud = topic: TESTTOPIC msg: {"test":"987654321"}
Msg was sent to Cloud :)
.100 135908 
.101 136925 
Received from cloud:
True
.102 138213 
.103 139227 
.104 140229 
.105 141234 
.106 142252 
.107 143272 
.108 144287 
.109 145301 
.110 146314 
.111 147333 
.112 148349 
.113 149366 
.114 150382 
.115 151403 
.116 152412 
.117 153415 
.118 154421 
.119 155425 
.120 156430 
.121 157436 
.122 158439 
.123 159442 
.124 160446 
Sending to cloud = topic: TESTTOPIC msg: {"test":"987654321"}
Msg was sent to Cloud :)
.125 163214 
Received from cloud:
True
.126 165043 
.127 166061 
.128 167073 
.129 168088 
.130 169091 
.131 170100 
.132 171117 
.133 172130 
.134 173148 
.135 174162 
.136 175176 
.137 176191 
.138 177204 
.139 178222 
.140 179236 
.141 180254 
.142 181260 
.143 182264 
.144 183271 
.145 184275 
.146 185280 
.147 186284 
.148 187287 
.149 188296 
Sending to cloud = topic: TESTTOPIC msg: {"test":"987654321"}
Msg was sent to Cloud :)
.150 190870 
.151 191886 
.152 192899 
Received from cloud:
True
.153 193905 
.154 194919 
.155 195921 
.156 196930 
.157 197934 
.158 198948 
.159 199960 
.160 200975 
.161 201989 
.162 203001 
.163 204017 
.164 205031 
.165 206045 
.166 207060 
.167 208066 
.168 209074 
.169 210077 
.170 211081 
.171 212087 
.172 213089 
.173 214099 
.174 215103 
Sending to cloud = topic: TESTTOPIC msg: {"test":"987654321"}
Msg was sent to Cloud :)
.175 217668 
.176 218686 
Received from cloud:
		 <-------- NOTHING RECEIVED FROM CLOUD
.177 220364 
.178 221365 
.179 223087 
.180 224100 
.181 225115 
.182 226129 
.183 227145 
.184 228159 
.185 229173 
.186 230424 
.187 231432 
.188 232447 
.189 233452 
.190 234458 
.191 235461 
.192 236465 
.193 237467 
.194 238470 
.195 239476 
.196 240479 
.197 241481 
.198 242485 
.199 243489 
Sending to cloud = topic: TESTTOPIC msg: {"test":"987654321"}
Msg was sent to Cloud :)
.200 246109 
.201 247123 
.202 248202 
Received from cloud:
True
.203 249217 
.204 250234 
.205 251250 
.206 252269 
.207 253283 
.208 254289 
.209 255545 
.210 256559 
.211 257575 
.212 258589 
.213 259611 
.214 260625 
.215 261639 
.216 262654 
.217 263666 
.218 264684 
.219 265690 
.220 266694 
.221 267697 
.222 268700 
.223 269708 
.224 270713 
Sending to cloud = topic: TESTTOPIC msg: {"test":"987654321"}
Msg was sent to Cloud :)
.225 273321 
.226 274338 <-------- DEADLOCK

I had:

  • On the second 27 and 176, didn’t receive anything from the cloud, despite the fact there should be data to read
  • On the second 226 I got again the deadlock, where I can unlock it if I send manually a message to the port 4444.

By sending manually a message “hello” to the port 4444, the process continues:

.226 274338 
Received from cloud:
		 <-------- NOTHING RECEIVED FROM CLOUD (was expecting the "hello" sent manually)
.227 646648 
.228 647661 
.229 648678 
.230 649692 
.231 650713 
.232 651728 
(...)

Thank you for the help,
jpgl

I visited Hologram API document but cant’ find attachTopic (what I found is attachTag).

Also there’s a shortcut to send message + topic in one line of code as shown below.

Oh, I think the attachTag was deprecated already in favor of attachTopic?

Yes. The attachTopic is the one we should use

My last input regarding your code:

  1. .listen in the sample code is called inside the loop. Yours is in the setup. Though your approach is much logical (only 1 socket connection as not to flood the server), I wonder why it is inside the loop in the sample.
  2. My best guest is to avoid socket connection timeout (if keep alive or heartbeat is not implemented to check socket connection).

Give it a try and see if the deadlock goes away.

Hi Arnold

No luck here…

I didn’t add the listen() on the loop because if I do it, I never receive messages from the cloud, and on my hologram cloud dashboard, I will see the:

Socket error: [Errno 111] Connection refused

jpgl

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.