# RESOLVED - New Photon refusing to flash

**URL:** <https://community.particle.io/t/resolved-new-photon-refusing-to-flash/13317>\
**Category:** Troubleshooting\
**Created:** [July 15, 2015, 10:38pm UTC](https://community.particle.io/t/resolved-new-photon-refusing-to-flash/13317 "2015-07-15T22:38:46Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![JL\_678](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/jl_678/32/4391_2.png) [@JL\_678](https://community.particle.io/u/JL_678)\
**Post date:** [July 15, 2015, 10:38pm UTC](https://community.particle.io/t/resolved-new-photon-refusing-to-flash/13317/1 "2015-07-15T22:38:46Z")

</div>

**_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/](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.

```auto
// 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. 😄

Thank you!

---

<div class="post-metadata">

**Author:** ![JL\_678](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/jl_678/32/4391_2.png) [@JL\_678](https://community.particle.io/u/JL_678)\
**Post date:** [July 15, 2015, 11:31pm UTC](https://community.particle.io/t/resolved-new-photon-refusing-to-flash/13317/2 "2015-07-15T23:31:47Z")

</div>

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

```auto
// 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;
}

```

---

<div class="post-metadata">

**Author:** ![mdma](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/mdma/32/1924_2.png) [@mdma](https://community.particle.io/u/mdma)\
**Post date:** [July 15, 2015, 11:39pm UTC](https://community.particle.io/t/resolved-new-photon-refusing-to-flash/13317/3 "2015-07-15T23:39:18Z")

</div>

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 😄  
mat.

---

<div class="post-metadata">

**Author:** ![JL\_678](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/jl_678/32/4391_2.png) [@JL\_678](https://community.particle.io/u/JL_678)\
**Post date:** [July 16, 2015, 1:45am UTC](https://community.particle.io/t/resolved-new-photon-refusing-to-flash/13317/4 "2015-07-16T01:45:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![peekay123](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/peekay123/32/810_2.png) [@peekay123](https://community.particle.io/u/peekay123)\
**Post date:** [July 16, 2015, 1:51am UTC](https://community.particle.io/t/resolved-new-photon-refusing-to-flash/13317/5 "2015-07-16T01:51:34Z")

</div>

@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. 😄

---

<div class="post-metadata">

**Author:** ![JL\_678](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/jl_678/32/4391_2.png) [@JL\_678](https://community.particle.io/u/JL_678)\
**Post date:** [July 16, 2015, 2:01am UTC](https://community.particle.io/t/resolved-new-photon-refusing-to-flash/13317/6 "2015-07-16T02:01:51Z")

</div>

@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!

---

<div class="post-metadata">

**Author:** ![peekay123](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/peekay123/32/810_2.png) [@peekay123](https://community.particle.io/u/peekay123)\
**Post date:** [July 16, 2015, 2:12am UTC](https://community.particle.io/t/resolved-new-photon-refusing-to-flash/13317/7 "2015-07-16T02:12:16Z")

</div>

@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!
