Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2eac22a

Browse files
committed
3370 Connect to server even if sensor is not detected.
1 parent 087af36 commit 2eac22a

File tree

3 files changed

+49
-20
lines changed

3 files changed

+49
-20
lines changed

Sensors/BMP180/BMP180.ino

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Steps:
3636
#define TEMPERATURE_PIN V2
3737

3838
Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10180);
39+
bool bmpSensorDetected = true;
3940

4041
// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
4142
char token[] = "AuthenticationToken";
@@ -47,7 +48,7 @@ void setup()
4748
if (!bmp.begin())
4849
{
4950
CAYENNE_LOG("No BMP sensor detected");
50-
while (1);
51+
bmpSensorDetected = false;
5152
}
5253
}
5354

@@ -59,22 +60,36 @@ void loop()
5960
// This function is called when the Cayenne widget requests data for the barometer's Virtual Pin.
6061
CAYENNE_OUT(BAROMETER_PIN)
6162
{
62-
// Send the command to get data.
63-
sensors_event_t event;
64-
bmp.getEvent(&event);
63+
if (bmpSensorDetected)
64+
{
65+
// Send the command to get data.
66+
sensors_event_t event;
67+
bmp.getEvent(&event);
6568

66-
if (event.pressure)
69+
if (event.pressure)
70+
{
71+
// Send the value to Cayenne in hectopascals.
72+
Cayenne.hectoPascalWrite(BAROMETER_PIN, event.pressure);
73+
}
74+
}
75+
else
6776
{
68-
// Send the value to Cayenne in hectopascals.
69-
Cayenne.hectoPascalWrite(BAROMETER_PIN, event.pressure);
77+
CAYENNE_LOG("No BMP sensor detected");
7078
}
7179
}
7280

7381
// This function is called when the Cayenne widget requests data for the temperature's Virtual Pin.
7482
CAYENNE_OUT(TEMPERATURE_PIN)
7583
{
76-
float temperature;
77-
bmp.getTemperature(&temperature);
78-
// Send the value to Cayenne in Celsius.
79-
Cayenne.celsiusWrite(TEMPERATURE_PIN, temperature);
84+
if (bmpSensorDetected)
85+
{
86+
float temperature;
87+
bmp.getTemperature(&temperature);
88+
// Send the value to Cayenne in Celsius.
89+
Cayenne.celsiusWrite(TEMPERATURE_PIN, temperature);
90+
}
91+
else
92+
{
93+
CAYENNE_LOG("No BMP sensor detected");
94+
}
8095
}

Sensors/TSL2561/TSL2561.ino

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ void setup()
5252
if (!tsl.begin())
5353
{
5454
CAYENNE_LOG("No TSL2561 detected");
55-
while (1);
5655
}
5756

5857
tsl.enableAutoRange(true);
@@ -83,6 +82,6 @@ CAYENNE_OUT(VIRTUAL_PIN)
8382
{
8483
/* If event.light = 0 lux the sensor is probably saturated
8584
and no reliable data could be generated! */
86-
CAYENNE_LOG("Sensor overload");
85+
CAYENNE_LOG("No sensor data");
8786
}
8887
}

Sensors/VCNL4000/VCNL4000.ino

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Steps:
3232
#define LUMINOSITY_PIN V2
3333

3434
VCNL4000 proximitySensor;
35+
bool sensorDetected = true;
3536

3637
// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
3738
char token[] = "AuthenticationToken";
@@ -43,7 +44,7 @@ void setup()
4344
if (!proximitySensor.begin())
4445
{
4546
CAYENNE_LOG("No sensor detected");
46-
while (1);
47+
sensorDetected = false;
4748
}
4849
}
4950

@@ -55,16 +56,30 @@ void loop()
5556
// This function is called when the Cayenne widget requests data for the distance Virtual Pin.
5657
CAYENNE_OUT(DISTANCE_PIN)
5758
{
58-
//The getMillimeters() function only provides a rough estimate of distance. If greater accuracy is desired
59-
//settings can be tweaked in CayenneVCNL400.h.
60-
int distance = proximitySensor.getMillimeters();
61-
if (distance != NO_PROXIMITY) {
62-
Cayenne.virtualWrite(DISTANCE_PIN, distance, DISTANCE, MILLIMETERS);
59+
if (sensorDetected)
60+
{
61+
//The getMillimeters() function only provides a rough estimate of distance. If greater accuracy is desired
62+
//settings can be tweaked in CayenneVCNL400.h.
63+
int distance = proximitySensor.getMillimeters();
64+
if (distance != NO_PROXIMITY) {
65+
Cayenne.virtualWrite(DISTANCE_PIN, distance, DISTANCE, MILLIMETERS);
66+
}
67+
}
68+
else
69+
{
70+
CAYENNE_LOG("No sensor detected");
6371
}
6472
}
6573

6674
// This function is called when the Cayenne widget requests data for the luminosity Virtual Pin.
6775
CAYENNE_OUT(LUMINOSITY_PIN)
6876
{
69-
Cayenne.luxWrite(LUMINOSITY_PIN, proximitySensor.getLux());
77+
if (sensorDetected)
78+
{
79+
Cayenne.luxWrite(LUMINOSITY_PIN, proximitySensor.getLux());
80+
}
81+
else
82+
{
83+
CAYENNE_LOG("No sensor detected");
84+
}
7085
}

0 commit comments

Comments
 (0)