Hi everyone,
Recently purchased a Particle Photon, its very similar to the arduino so I’ve picked up on it with ease however my Photon keeps disconnecting from the cloud after a random amount of time. Could be a few mins, could be an hour. I thought I had it fixed with my latest revision to the code but even with the reconnection command in the loop it still will not connect to the cloud. I believe its staying connected to wifi but i’m currently testing this now. I did some research and looks like i’m not the only one having cloud connection issues. I found 2 others within 10 mins of searching these forums. Is this a common issue?
This is using a example from the adafruit library for DHT sensors. I also have the library files attached to the code, just don’t see a point in posting them here.
I thought maybe the delay command was messing with the connection so I switched to a non-blocking time tracking but even with this, the connection is lost to the cloud and refuses to reconnect. Any ideas?
EDIT:
I did just verify after around an hour of running, it just disconnected from the cloud and it IS still connected to the wifi of my network.
// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain
// REQUIRES the following Arduino libraries:
// - DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library
// - Adafruit Unified Sensor Library: https://github.com/adafruit/Adafruit_Senso
#include "dht.h"
#define DHTPIN 3 // what digital pin we're connected to
// Uncomment whatever type you're using!
//#define DHTTYPE DHT11 // DHT 11
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
// Connect pin 1 (on the left) of the sensor to +5V
// NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1
// to 3.3V instead of 5V!
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor
// Initialize DHT sensor.
// Note that older versions of this library took an optional third parameter to
// tweak the timings for faster processors. This parameter is no longer needed
// as the current DHT reading algorithm adjusts itself to work on faster procs.
DHT dht(DHTPIN, DHTTYPE);
unsigned long previousTimer01;
const int waitTime = 4000;
void setup() {
dht.begin();
Particle.connect();
}
void loop() {
// Wait a few seconds between measurements.
if (Particle.connected() == false) {
Particle.connect();
}
if ((millis() - previousTimer01 >= waitTime) && (Particle.connected() == true)){
previousTimer01 = millis();
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
//Serial.println(F("Failed to read from DHT sensor!"));
return;
}
// Compute heat index in Fahrenheit (the default)
float hif = dht.computeHeatIndex(f, h);
// Compute heat index in Celsius (isFahreheit = false)
float hic = dht.computeHeatIndex(t, h, false);
/*
Serial.print(F("Humidity: "));
Serial.print(h);
Serial.print(F("% Temperature: "));
Serial.print(t);
Serial.print(F("°C "));
Serial.print(f);
Serial.print(F("°F Heat index: "));
Serial.print(hic);
Serial.print(F("°C "));
Serial.print(hif);
Serial.println(F("°F"));
*/
String temper = String(f,DEC);
if (Particle.connected()) {
Particle.publish("Temperature", temper);
}
}
}