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