# Photon quit after 1st message to dashboard.particle.io

**URL:** <https://community.particle.io/t/photon-quit-after-1st-message-to-dashboard-particle-io/12531>\
**Category:** Troubleshooting\
**Created:** [June 13, 2015, 2:34am UTC](https://community.particle.io/t/photon-quit-after-1st-message-to-dashboard-particle-io/12531 "2015-06-13T02:34:18Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![cdrodriguez](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/cdrodriguez/32/5588_2.png) [@cdrodriguez](https://community.particle.io/u/cdrodriguez)\
**Post date:** [June 13, 2015, 2:34am UTC](https://community.particle.io/t/photon-quit-after-1st-message-to-dashboard-particle-io/12531/1 "2015-06-13T02:34:18Z")

</div>

Hi there. I have swapped out a photon for a core in a project that I have had running for a couple of months now. After modifying the onewire and dallastemp libraries I have gotten the code to compile and work seemingly fine except it fails to publish after its first round post bootting. That is if I reboot I get one set of data on [dashboard.particle.io](http://dashboard.particle.io) or by subscribing from the cli. Since the code work flawlessly on my core I am wondering if I am missing something that is photon specific. Also BTW have the core running a different task on the same network now and have had not problems with publishing. Thanks in advance for your help.

---

<div class="post-metadata">

**Author:** ![kennethlimcp](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@kennethlimcp](https://community.particle.io/u/kennethlimcp)\
**Post date:** [June 13, 2015, 2:43am UTC](https://community.particle.io/t/photon-quit-after-1st-message-to-dashboard-particle-io/12531/2 "2015-06-13T02:43:44Z")

</div>

@cdrodriguez, when you say quit, can you be more specific to what happened?

Also, if your code can be shared, that will help a lot 🙂

---

<div class="post-metadata">

**Author:** ![cdrodriguez](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/cdrodriguez/32/5588_2.png) [@cdrodriguez](https://community.particle.io/u/cdrodriguez)\
**Post date:** [June 13, 2015, 3:09am UTC](https://community.particle.io/t/photon-quit-after-1st-message-to-dashboard-particle-io/12531/3 "2015-06-13T03:09:07Z")

</div>

Hi Kenneth. Thanks so much for responding. What I mean by quit is that it would not publish anything more, everything else continued to worked fine, e.g. spark.variable, spark.function. As for the code here is an excerpt:

```auto
//Spark Publish Variables and settings
int TTL = 60; // time to live
unsigned long LastPublish = Time.now()-TTL;
int TTL = 60; // time to live
unsigned long LastPublish = Time.now()-TTL;

int SumpSensorVal = 0;
char DoorState[20] = "UNKOWN";
double CurrentTemp = 0.0;

void setup() {
    ...
}

void loop() {
    
//... Get the values and strcpy(DoorState, "OPEN"); or strcpy(DoorState, "CLOSED");

// Publish the variables    
if(Time.now() >= (LastPublish + TTL)){
    
    Spark.publish("Garage_Temp", String(CurrentTemp), TTL, PRIVATE);
    Spark.publish("Garage_Door", DoorState, TTL, PRIVATE);
    Spark.publish("SumpSensor", String(SumpSensorVal), TTL, PRIVATE);
    
    LastPublish = Time.now();
}

}

```

---

<div class="post-metadata">

**Author:** ![kennethlimcp](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@kennethlimcp](https://community.particle.io/u/kennethlimcp)\
**Post date:** [June 13, 2015, 3:15am UTC](https://community.particle.io/t/photon-quit-after-1st-message-to-dashboard-particle-io/12531/4 "2015-06-13T03:15:33Z")

</div>

for a quick test can we try:

```auto
unsigned long old_time = millis();

void loop() {
    
//... Get the values and strcpy(DoorState, "OPEN"); or strcpy(DoorState, "CLOSED");

// Publish the variables    
if(milis() - old_time >= 2000){
    
    Spark.publish("Garage_Temp", String(CurrentTemp), TTL, PRIVATE);
    Spark.publish("Garage_Door", DoorState, TTL, PRIVATE);
    Spark.publish("SumpSensor", String(SumpSensorVal), TTL, PRIVATE);

    old_time = millis();
    }

}

```

---

<div class="post-metadata">

**Author:** ![cdrodriguez](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/cdrodriguez/32/5588_2.png) [@cdrodriguez](https://community.particle.io/u/cdrodriguez)\
**Post date:** [June 13, 2015, 3:57am UTC](https://community.particle.io/t/photon-quit-after-1st-message-to-dashboard-particle-io/12531/5 "2015-06-13T03:57:02Z")

</div>

That did the trick! Thank you so much. I have been struggling to figure this out for a while. Is the issue with Time.h?

---

<div class="post-metadata">

**Author:** ![cdrodriguez](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/cdrodriguez/32/5588_2.png) [@cdrodriguez](https://community.particle.io/u/cdrodriguez)\
**Post date:** [June 13, 2015, 4:23am UTC](https://community.particle.io/t/photon-quit-after-1st-message-to-dashboard-particle-io/12531/6 "2015-06-13T04:23:11Z")

</div>

Would this work to avoid the wrap around at about 49 Days

```auto
void loop() { 
      // check for millis() wrap around   
     if(millis() < old_time){old_time = millis();}
     // Other code follows
}

```

---

<div class="post-metadata">

**Author:** ![kennethlimcp](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@kennethlimcp](https://community.particle.io/u/kennethlimcp)\
**Post date:** [June 13, 2015, 5:43am UTC](https://community.particle.io/t/photon-quit-after-1st-message-to-dashboard-particle-io/12531/7 "2015-06-13T05:43:21Z")

</div>

Ha. i was suspecting that…

If you want to debug, print out `Time.now()` and use it accordingly in your code 😄

---

<div class="post-metadata">

**Author:** ![cdrodriguez](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/cdrodriguez/32/5588_2.png) [@cdrodriguez](https://community.particle.io/u/cdrodriguez)\
**Post date:** [June 13, 2015, 6:14am UTC](https://community.particle.io/t/photon-quit-after-1st-message-to-dashboard-particle-io/12531/8 "2015-06-13T06:14:33Z")

</div>

> [@kennethlimcp](#):
>
> Time.now()

So I took your suggestion, what is interesting is that Time.now() returns on its first call  
2507222946 and 1434175356 on its second from which point on it seems to be behaving.

```auto
unsigned long LastPublish = millis();
unsigned long CurrentTime = Time.now();

void setup() {
Time.zone(-7);
CurrentTime = Time.now();} // Doesn't seem to matter whether this is here or not

void loop() {

// Publish the variables    
if(millis() - LastPublish >= 5000){
      
        CurrentTime = Time.now();
        Spark.publish("TimeNow", String(CurrentTime), TTL, PRIVATE);
        LastPublish = millis();
    }

}

```

the 1st publish was 2507222946  
the 2nd publish was 1434175356  
the 3rd was 1434175361  
the 4th was 1434175366

and so on ...

---

<div class="post-metadata">

**Author:** ![cdrodriguez](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/cdrodriguez/32/5588_2.png) [@cdrodriguez](https://community.particle.io/u/cdrodriguez)\
**Post date:** [June 13, 2015, 7:20am UTC](https://community.particle.io/t/photon-quit-after-1st-message-to-dashboard-particle-io/12531/9 "2015-06-13T07:20:56Z")

</div>

I wonder if the fact that time is int32 rather uint32 is where I am running into a problem [https://community.particle.io/t/time-class-and-signed-unix-time](https://community.particle.io/t/time-class-and-signed-unix-time) & [[Solved/Fixed] Time.now() in setup() gives bad time after power on](https://community.particle.io/t/solved-fixed-time-now-in-setup-gives-bad-time-after-power-on/9098) however that really doesnt explain why the code I have works fine on a core but fails on a photon

---

<div class="post-metadata">

**Author:** ![harrisonhjones](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/harrisonhjones/32/4132_2.png) [@harrisonhjones](https://community.particle.io/u/harrisonhjones)\
**Post date:** [June 13, 2015, 5:28pm UTC](https://community.particle.io/t/photon-quit-after-1st-message-to-dashboard-particle-io/12531/10 "2015-06-13T17:28:45Z")

</div>

Use EllapsedMillis! (It’s in the libraries section in the WebIDE. Add it to your project). Code would look like this:

```auto
elapsedMillis tmrUpdate;                        
unsigned long updateInterval = 4000;        
 
// Other Variables

void setup() {
    // ... Setup code
    tmrUpdate = 0;
}

// Other awesome functions

void loop() 
{
    
    //... Get the values and strcpy(DoorState, "OPEN"); or strcpy(DoorState, "CLOSED");

    // Publish the variables    
    if(tmrUpdate > updateInterval){
    
        Spark.publish("Garage_Temp", String(CurrentTemp), TTL, PRIVATE);
        Spark.publish("Garage_Door", DoorState, TTL, PRIVATE);
        Spark.publish("SumpSensor", String(SumpSensorVal), TTL, PRIVATE);

        tmrUpdate = 0;
    }

}

```

---

<div class="post-metadata">

**Author:** ![cdrodriguez](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/cdrodriguez/32/5588_2.png) [@cdrodriguez](https://community.particle.io/u/cdrodriguez)\
**Post date:** [June 16, 2015, 9:56pm UTC](https://community.particle.io/t/photon-quit-after-1st-message-to-dashboard-particle-io/12531/11 "2015-06-16T21:56:41Z")

</div>

Thanks, I will definitely try this out. I just wonder what the issue is between the core and photon with Time.now().

---

<div class="post-metadata">

**Author:** ![cdrodriguez](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/cdrodriguez/32/5588_2.png) [@cdrodriguez](https://community.particle.io/u/cdrodriguez)\
**Post date:** [June 19, 2015, 5:57pm UTC](https://community.particle.io/t/photon-quit-after-1st-message-to-dashboard-particle-io/12531/12 "2015-06-19T17:57:35Z")

</div>

Hi Harrison. Thanks for the suggestion and example code it worked great. I modified a little so as to allow for multiple variable publishing

```auto
elapsedMillis tmrUpdate;                        
unsigned long updateInterval = 1000;        
int VTP = 1; // Variable to Publish

// Other Variables

void setup() {
    // ... Setup code
    tmrUpdate = 0;
}

// Other awesome functions

void loop() 
{
    
    //... Get the values 

    // Publish the variables    
    if(tmrUpdate > updateInterval){
    
        switch(VTP){
            case 1: 
                VTP++; Spark.publish("Name1", String(Variable1), TTL, PRIVATE);
                tmrUpdate = 0; break;
            case 2: 
                VTP++; Spark.publish("Name2", String(Variable2), TTL, PRIVATE);
                tmrUpdate = 0; break;

            //...
            case N: 
                VTP=1; Spark.publish("NameN", String(VariableN), TTL, PRIVATE);
                tmrUpdate = 0; break;
    }

}

```
