Particle photon uptime

Hi

What is the best way to check the uptime of a particle photon? I have seen the API call, Device OS API | Reference Documentation | Particle but this is something i will need to flash into the device, right?

I would like to see this in the console, or if there is any cloud API i can check that retrieves the uptime of my device, without messing with the running code.

Thanks :slight_smile:

Uptime is not something that’s available from the cloud side for a number of reasons. It is available on-device by making the System.uptime() call but you’d have to do something to make this available to the cloud. For example, exposing it with a Particle.variable or publishing the value.

None of those options would make it visible in the console, since you can’t customize the views in the console.

The reason is that in order to have an accurate uptime, you only have a few options:

  • Ask the device when you want it, which takes data and time
  • Have the device send it out continuously, which uses a lot of data
  • Guess, which may be inaccurate if the device has gone offline

Also, for connected devices, the uptime may be less useful than the time the device was last heard from.

It really all depends how accurate you need the uptime to be, whether you care if the device is offline or not, and how many data operations you want to devote to maintaining the value. It’s all use-specific tradeoffs.

hi,
Not sure if this will help but…

Here is a HTML which obtaining the UPTIME of one of my Photon. I tested it by checking uptime before and after reset and is working as expected.
it’s also gonna trigger spark/device/diagnostics/update event so you gonna see them in console as well.

code:

<!DOCTYPE html>
<html>
<p style="background: radial-gradient(#ffeb3b, transparent)">uptime: <span id="uptime"></span></p>
<button onclick="ask()" id="myBtn" style="background: radial-gradient(#e6704b, transparent);font-size: 24px;border-radius: 20px;border: 3px solid red">click me :)</button>

<body style="font-size: 31px;">
<head>
<style>
html{
background-color: blue; 
}				
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script>
<script type="text/javascript">
const askUrl = "https://api.particle.io/v1/diagnostics/Your_devId_here/update?access_token=Your_access_token_here";
const getRespUrl = "https://api.particle.io/v1/diagnostics/Your_devId_here/last?access_token=Your_access_token_here";
        
function ask(){
   fetch(askUrl,  {method: 'POST'})
        .then((resp) => resp.json())
        .then(function(data){ 
         console.log("full data", data); 
         get_resp();
       })
       .catch(function(error) {
       console.log(error);            
     }); 
}
     
function get_resp(){
   fetch(getRespUrl,  {method: 'GET'})
       .then((resp) => resp.json())
       .then(function(data){ 
        console.log("data", data); 
        console.log("uptime", data.diagnostics.payload.device.system.uptime);  
        var dt2 = new Date();
        var uptime = moment(dt2);
        uptime.subtract(data.diagnostics.payload.device.system.uptime, 'seconds');
        document.getElementById("uptime").innerHTML = uptime;
       })
       .catch(function(error) {
        console.log(error);            
    }); 
}
        
//setInterval(function() {
  //ask();
//}, 2000);  
//ask();
      
    </script>
  </head>
  <body>
 
</body>
</html>

results:

resources: