# Boron Battery Connected

**URL:** <https://community.particle.io/t/boron-battery-connected/47789>\
**Category:** Firmware\
**Tags:** boron\
**Created:** [February 14, 2019, 3:02pm UTC](https://community.particle.io/t/boron-battery-connected/47789 "2019-02-14T15:02:10Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![rickkas7](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/rickkas7/32/8681_2.png) [@rickkas7](https://community.particle.io/u/rickkas7)\
**Post date:** [February 15, 2019, 10:16pm UTC](https://community.particle.io/t/boron-battery-connected/47789/10 "2019-02-15T22:16:44Z")

</div>

OK, this is a much better way to do it, using the DiagnosticsHelperRK library. I added a new example to the library for power source:

```auto
#include "Particle.h"

#include "DiagnosticsHelperRK.h"

SerialLogHandler logHandler;

unsigned long lastPublish = 0;
int lastPowerSource = -1;

void setup() {
	Serial.begin();
}

void loop() {

	int powerSource = DiagnosticsHelper::getValue(DIAG_ID_SYSTEM_POWER_SOURCE);
	if (powerSource != lastPowerSource) {
		if (millis() - lastPublish >= 1000 && Particle.connected()) {
			lastPublish = millis();

		    // POWER_SOURCE_UNKNOWN = 0,
			// POWER_SOURCE_VIN = 1,
			// POWER_SOURCE_USB_HOST = 2,
			// POWER_SOURCE_USB_ADAPTER = 3,
			// POWER_SOURCE_USB_OTG = 4,
			// POWER_SOURCE_BATTERY = 5

			char buf[128];
			snprintf(buf, sizeof(buf), "powerSource=%d", powerSource);

			Particle.publish("powerSource", buf, PRIVATE);
			Log.info(buf);

			lastPowerSource = powerSource;
		}
	}

}

```

![powerSource](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/0/7/0798af807c3b4ceb267327a813b40aac5bdc1d54.png)

> **[rickkas7/DiagnosticsHelperRK](https://github.com/rickkas7/DiagnosticsHelperRK)**
>
> Library to make getting diagnostic values from user firmware easy - rickkas7/DiagnosticsHelperRK

---

_[View the full topic](https://community.particle.io/t/boron-battery-connected/47789)._
