RESOLVED - New Photon refusing to flash

Good news - the situation is resolved and the situation was caused by the use of an outdated library. Anyone experiencing this problem should ensure that they are using the PIETTECH_DHT library as recommended by @peekay123 below. It solved the problem.

Okay, this is fixed by RTFM! I put it into safe mode. (Instructions: http://docs.particle.io/photon/) I still am not quite sure how I got into this state to begin with. Anyone know? Was there something wrong with my code?

Hi,

I have a brand new Photon that I am currently playing with along with a DHT22 sensor. I have been struggling to get the DHT22 working, but that is a problem for another thread. Anyway, things have worked well as I keep trying different code options and then flashing them to the Photon via the web IDE. The board has happily accepted all flashes and returned to breathing blue until moments ago…

Just now, I flashed code and everything seemed normal including the breathing blue LED. However, the device now refuses to respond to either the rest API commands or Web IDE flashes. In both cases, the requests time out. Here is the last code that I flashed, if that matters.

// This #include statement was automatically added by the Spark IDE.
#include "idDHT22/idDHT22.h"


int idDHT22pin = D4; //Digital pin for comunications
void dht22_wrapper(); // must be declared before the lib initialization
idDHT22 DHT22(idDHT22pin, dht22_wrapper);

double tempF;
int tempFi;
boolean ledonoff = true;
boolean tempupdate = true;
int PreviousTime;
const int interval = 40; //update every 20 seconds
char publishString[40];

void setup() {

  Spark.variable("Current_T", &tempFi, INT);
  Spark.variable("Uptime",publishString, STRING);
  Spark.function("ledon", ledon);
  Spark.function("ledoff", ledoff);

  PreviousTime = Time.now() - interval - 1;
}

void dht22_wrapper() {
	DHT22.isrCallback();
}

void loop() {
    DHT22.acquire();
    while (DHT22.acquiring()){
	    int result = DHT22.getStatus();
    }
    
    if (Time.now() - PreviousTime > interval){
      PreviousTime = Time.now();
      tempF = DHT22.getHumidity(); //baro.getTemperature()*9/5+32;
      tempFi = (int) tempF;//add humidity?
      tempupdate = true;
      sparkPub(millis());
      
    }
}


void sparkPub(unsigned long now) {
    unsigned nowSec = now/1000UL;
    unsigned sec = nowSec%60;
    unsigned min = (nowSec%3600)/60;
    unsigned hours = (nowSec%86400)/3600;
    unsigned days = (nowSec/86400);
    sprintf(publishString,"%u days, %u:%u:%u",days,hours,min,sec);
    //Spark.publish("Uptime",publishString);
}

int ledon(String args2){
    ledonoff = true;
    tempupdate = true;
    return 10;
}

int ledoff(String args2){
    ledonoff = false;
    return 20;
}

Any suggestions on how to resolve this would be appreciated. I also have a Core and have never had this issue and so am wondering if it is a bug or something. Of course, I would not deny user error as well. :smile:

Thank you!

1 Like

Okay, this keeps happening and so there is something else going on. Here is newer code that shows the same symptom:

// This #include statement was automatically added by the Spark IDE.
#include "idDHT22/idDHT22.h"


int idDHT22pin = D4; //Digital pin for comunications
void dht22_wrapper(); // must be declared before the lib initialization
idDHT22 DHT22(idDHT22pin, dht22_wrapper);

double tempF;
int tempFi;
int dhtstat;
boolean ledonoff = true;
boolean tempupdate = true;
int PreviousTime;
const int interval = 40; //update every 20 seconds
char publishString[40];

void setup() {

  Spark.variable("Current_T", &tempFi, INT);
  Spark.variable("DHT", &dhtstat, INT);
  Spark.variable("Uptime",publishString, STRING);
  Spark.function("ledon", ledon);
  Spark.function("ledoff", ledoff);

  PreviousTime = Time.now() - interval - 1;
}

void dht22_wrapper() {
	DHT22.isrCallback();
}

void loop() {
    DHT22.acquire();
    while (DHT22.acquiring());
    int result = DHT22.getStatus();
    switch (result){
        
		case IDDHTLIB_OK:
			dhtstat = 0;
			break;
		case IDDHTLIB_ERROR_CHECKSUM:
			dhtstat = 1;
			break;
		case IDDHTLIB_ERROR_ISR_TIMEOUT:
			dhtstat = 2;
			break;
		case IDDHTLIB_ERROR_RESPONSE_TIMEOUT:
			dhtstat = 3;
			break;
		case IDDHTLIB_ERROR_DATA_TIMEOUT:
			dhtstat = 4;
			break;
		case IDDHTLIB_ERROR_ACQUIRING:
			dhtstat = 5;
			break;
		case IDDHTLIB_ERROR_DELTA:
			dhtstat = 6;
			break;
		case IDDHTLIB_ERROR_NOTSTARTED:
			dhtstat = 7;
			break;
		default:
			dhtstat = 8;
			break;
	}
    
    if (Time.now() - PreviousTime > interval){
      PreviousTime = Time.now();
      tempF = DHT22.getHumidity(); //baro.getTemperature()*9/5+32;
      tempFi = (int) tempF;//add humidity?
      tempupdate = true;
      sparkPub(millis());
      
    }
}


void sparkPub(unsigned long now) {
    unsigned nowSec = now/1000UL;
    unsigned sec = nowSec%60;
    unsigned min = (nowSec%3600)/60;
    unsigned hours = (nowSec%86400)/3600;
    unsigned days = (nowSec/86400);
    sprintf(publishString,"%u days, %u:%u:%u",days,hours,min,sec);
    //Spark.publish("Uptime",publishString);
}

int ledon(String args2){
    ledonoff = true;
    tempupdate = true;
    return 10;
}

int ledoff(String args2){
    ledonoff = false;
    return 20;
}

I have a hunch what the problem might be. Could you try commenting out the Spark.variable and Spark.function calls in setup() and see if that helps?

Thanks :smile:
mat.

No sorry, it is still doing it. I am going to do some further testing to see if I can identify what is causing this. I assume that it is something in my code.

@JL_678, being the author of the idDHT22 library port, I HIGHLY recommend dropping the library in favor of the PIETTECH_DHT library available on the web IDE. It doesn’t hang like idDHT22 can. Once you’ve done that, then you can look at the flashing problem again. :smile:

1 Like

@peekay123 in my enthusiasm to get the sensor up and running, I mistakenly missed that. I just updated the code with the new library and everything is working much better. One question, should that old library be removed to avoid issues like this? Just a thought.

The net result is that the issue is resolved. I will update the title. Thank you!

@JL_678, I tried to remove it but as long as it is used, I can’t. I did put a warning in the description but that’s all I could do!

1 Like