It may be more than just a delay to the monitor, it looks like setup lines aren't being executed.
I have the following code for a temp sensor:
/*
Sketch generated by the Arduino IoT Cloud Thing "Temp"
https://create.arduino.cc/cloud/things/3b3b213f-68cc-4015-9776-b14cbb952ea4
Arduino IoT Cloud Properties description
The following variables are automatically generated and updated when changes are made to the Thing properties
float Temp;
Properties which are marked as READ/WRITE in the Cloud Thing will also have functions
which are called when their values are changed from the Dashboard.
These functions are generated with the Thing and added at the end of this sketch.
*/
#include "thingProperties.h"
// Adafruit MCP9808 Library - Version: Latest
#include <Adafruit_MCP9808.h>
#include <Wire.h>
// Create the MCP9808 temperature sensor object
Adafruit_MCP9808 tempsensor = Adafruit_MCP9808();
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(5000);
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you'll get.
The default is 0 (only errors).
Maximum is 4
*/
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}
void loop() {
ArduinoCloud.update();
// Your code here
while(!tempsensor.begin(0x18)){
//stay here, try again
delay(250);
}
Serial.println("Sensor initialized");
tempsensor.setResolution(0); // sets the resolution mode of reading, the modes are defined in the table bellow:
delay(2000);
tempsensor.wake(); // wake up, ready to read!
Temp = tempsensor.readTempF();
tempsensor.shutdown(); // shutdown MSP9808 - power consumption ~0.1 mikro Ampere, stops temperature sampling
Serial.println(Temp);
}
This has the initialization and temp print inside loop() and both print before the connection according to the monitor output:
77.90
[ 14828 ] Connected to "Network1"
[ 14828 ] Connecting to Arduino IoT Cloud...
Sensor initialized
77.90
[ 17289 ] Bogus NTP time from API, fallback to UDP method
[ 19791 ] Connected to Arduino IoT Cloud
Sensor initialized
77.90
Sensor initialized
77.90
Sensor initialized
77.90
The sensor doesn't initialize if the initialization is setup():
/*
Sketch generated by the Arduino IoT Cloud Thing "Temp"
https://create.arduino.cc/cloud/things/3b3b213f-68cc-4015-9776-b14cbb952ea4
Arduino IoT Cloud Properties description
The following variables are automatically generated and updated when changes are made to the Thing properties
float Temp;
Properties which are marked as READ/WRITE in the Cloud Thing will also have functions
which are called when their values are changed from the Dashboard.
These functions are generated with the Thing and added at the end of this sketch.
*/
#include "thingProperties.h"
// Adafruit MCP9808 Library - Version: Latest
#include <Adafruit_MCP9808.h>
#include <Wire.h>
// Create the MCP9808 temperature sensor object
Adafruit_MCP9808 tempsensor = Adafruit_MCP9808();
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(5000);
while(!tempsensor.begin(0x18)){
//stay here, try again
delay(250);
}
Serial.println("Sensor initialized");
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you'll get.
The default is 0 (only errors).
Maximum is 4
*/
setDebugMessageLevel(3);
ArduinoCloud.printDebugInfo();
}
void loop() {
ArduinoCloud.update();
// Your code here
tempsensor.setResolution(0); // sets the resolution mode of reading, the modes are defined in the table bellow:
delay(2000);
tempsensor.wake(); // wake up, ready to read!
Temp = tempsensor.readTempF();
tempsensor.shutdown(); // shutdown MSP9808 - power consumption ~0.1 mikro Ampere, stops temperature sampling
Serial.println(Temp);
}
31.89
[ 13825 ] Connected to "Network1"
[ 13825 ] Connecting to Arduino IoT Cloud...
31.89
[ 16667 ] Bogus NTP time from API, fallback to UDP method
[ 19548 ] Connected to Arduino IoT Cloud
31.89
31.89
31.89
Something in ArduinoCloud.Update() maybe??
Here's better output but the sensor is de-initialized somehow:
[ 8142 ] ***** Arduino IoT Cloud - configuration info *****
[ 8142 ] Device ID: xxxxxxx
[ 8143 ] Thing ID: xxxxxxx
[ 8143 ] MQTT Broker: mqtts-sa.iot.arduino.cc:8883
Sensor initialized
[ 8910 ] WiFi.status(): 0
[ 8910 ] Current WiFi Firmware: 1.2.1
[ 8911 ] Connecting to "Network1"
78.80
[ 17546 ] Connected to "Network1"
[ 17546 ] Connecting to Arduino IoT Cloud...
78.80
[ 20207 ] Bogus NTP time from API, fallback to UDP method
[ 22738 ] Connected to Arduino IoT Cloud
31.89
31.89
31.89
31.89
/*
Sketch generated by the Arduino IoT Cloud Thing "Temp"
https://create.arduino.cc/cloud/things/3b3b213f-68cc-4015-9776-b14cbb952ea4
Arduino IoT Cloud Properties description
The following variables are automatically generated and updated when changes are made to the Thing properties
float Temp;
Properties which are marked as READ/WRITE in the Cloud Thing will also have functions
which are called when their values are changed from the Dashboard.
These functions are generated with the Thing and added at the end of this sketch.
*/
#include "thingProperties.h"
// Adafruit MCP9808 Library - Version: Latest
#include <Adafruit_MCP9808.h>
#include <Wire.h>
// Create the MCP9808 temperature sensor object
Adafruit_MCP9808 tempsensor = Adafruit_MCP9808();
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);
while(!Serial){
delay(250);
};
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you'll get.
The default is 0 (only errors).
Maximum is 4
*/
setDebugMessageLevel(3);
ArduinoCloud.printDebugInfo();
while(!tempsensor.begin(0x18)){
//stay here, try again
delay(250);
}
Serial.println("Sensor initialized");
}
void loop() {
ArduinoCloud.update();
// Your code here
tempsensor.setResolution(0); // sets the resolution mode of reading, the modes are defined in the table bellow:
delay(2000);
tempsensor.wake(); // wake up, ready to read!
Temp = tempsensor.readTempF();
tempsensor.shutdown(); // shutdown MSP9808 - power consumption ~0.1 mikro Ampere, stops temperature sampling
Serial.println(Temp);
}