Giter VIP home page Giter VIP logo

uptime-library's Introduction

Uptime Library

With the uptime library for Arduino boards and compatible systems you can read the time passed since device startup, without the 49 days overflow limitation of the millis() function.

Usage

Example 1: Device Uptime

#include "uptime_formatter.h"

void setup() {
  // connect at 115200 so we can read the uptime fast enough
  Serial.begin(115200);
}

void loop() {
  //uptime_formatter::get_uptime() returns a string 
  //containing the total device uptime since startup in days, hours, minutes and seconds
  Serial.println("up " + uptime_formatter::getUptime());

  //wait 1 second
  delay(1000);
}

Output:

up 0 days, 0 hours, 0 minutes, 56 seconds
up 0 days, 0 hours, 0 minutes, 57 seconds
up 0 days, 0 hours, 0 minutes, 58 seconds
up 0 days, 0 hours, 0 minutes, 59 seconds
up 0 days, 0 hours, 1 minutes, 0 seconds
up 0 days, 0 hours, 1 minutes, 1 seconds
up 0 days, 0 hours, 1 minutes, 2 seconds
up 0 days, 0 hours, 1 minutes, 3 seconds
up 0 days, 0 hours, 1 minutes, 4 seconds
up 0 days, 0 hours, 1 minutes, 5 seconds
up 0 days, 0 hours, 1 minutes, 6 seconds
up 0 days, 0 hours, 1 minutes, 7 seconds
up 0 days, 0 hours, 1 minutes, 8 seconds
up 0 days, 0 hours, 1 minutes, 9 seconds
#include "uptime.h"

void setup() {
  // connect at 115200 so we can read the uptime fast enough
  Serial.begin(115200);
}

void loop() {
  //If you do not want to use the string library
  //you can get the total uptime variables
  //and format the output the way you want.
  
  //First call calculate_uptime() to calculate the uptime
  //and then read the uptime variables.
  uptime::calculateUptime();
  
  Serial.print("days: ");
  Serial.println(uptime::getDays());
  
  Serial.print("hours: ");
  Serial.println(uptime::getHours());
  
  Serial.print("minutes: ");
  Serial.println(uptime::getMinutes());
  
  Serial.print("seconds: ");
  Serial.println(uptime::getSeconds());
  
  Serial.print("milliseconds: ");
  Serial.println(uptime::getMilliseconds());

  Serial.print("\n");
  
  //wait 1 second
  delay(1000);
}

Output:

days: 0
hours: 0
minutes: 23
seconds: 16
milliseconds: 23

days: 0
hours: 0
minutes: 23
seconds: 17
milliseconds: 23

days: 0
hours: 0
minutes: 23
seconds: 18
milliseconds: 23

uptime-library's People

Contributors

yiannisbourkelis avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.