Migrating from from wiringpi to pigpio. This increases the sample rate by a factor of 3 and will allow creation of a board that can monitor over 30 breakers with a single raspberry pi.

This is based on pi4j 2.0 which is in a beta status.  I have fixed a few bugs in a local version of pi4j 2.0 to get it to work but I haven't submitted those changes to pi4j yet.

This change requires a migration to Java 11 and will *NOT* be backwards compatible.  Upgrading to this hub software will require that java 11 and pigpio be installed on the hub.  This can be done from an ssh session with the following commands:

apt-get update
apt-get install openjdk-11-jre-headless
apt-get install pigpio

Alternatively, you can download a new sd image, reflash your sd card, and re-adopt your hub.
This commit is contained in:
Mark Milligan
2022-04-29 14:59:56 -05:00
parent 079206fcd7
commit c8319d6369
50 changed files with 637 additions and 412 deletions

View File

@@ -1,31 +1,31 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.lanternsoftware.currentmonitor</groupId>
<artifactId>lantern-dataaccess-currentmonitor</artifactId>
<packaging>jar</packaging>
<version>1.0.0</version>
<version>1.1.0</version>
<name>lantern-dataaccess-currentmonitor</name>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<parent>
<groupId>com.lanternsoftware.currentmonitor</groupId>
<artifactId>currentmonitor</artifactId>
<version>1.1.0</version>
</parent>
<dependencies>
<dependency>
<groupId>com.lanternsoftware.currentmonitor</groupId>
<artifactId>lantern-datamodel-currentmonitor</artifactId>
<version>1.0.0</version>
<version>${cm.version}</version>
</dependency>
<dependency>
<groupId>com.lanternsoftware.rules</groupId>
<artifactId>lantern-datamodel-rules</artifactId>
<version>1.0.0</version>
<version>${rules.version}</version>
</dependency>
<dependency>
<groupId>com.lanternsoftware.util</groupId>
<artifactId>lantern-util-dao-mongo</artifactId>
<version>1.0.0</version>
<version>${util.version}</version>
</dependency>
<dependency>
<groupId>org.mindrot</groupId>
@@ -56,8 +56,8 @@
<optimize>true</optimize>
<showDeprecation>true</showDeprecation>
<encoding>UTF-8</encoding>
<source>1.8</source>
<target>1.8</target>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
<plugin>

View File

@@ -54,6 +54,7 @@ public interface CurrentMonitorDao {
String getAuthCodeForEmail(String _email, TimeZone _tz);
Account authCodeToAccount(String _authCode);
AuthCode decryptAuthCode(String _authCode);
String exchangeAuthCode(String _authCode, int _acctId);
Account putAccount(Account _account);
Account getAccount(int _accountId);

View File

@@ -90,6 +90,9 @@ public class MongoCurrentMonitorDao implements CurrentMonitorDao {
updateEnergySummaries(minute);
}
proxy.delete(DirtyMinute.class, new DaoQuery());
if (!proxy.exists(Sequence.class, null)) {
proxy.save(new Sequence());
}
}
public void shutdown() {
@@ -303,7 +306,7 @@ public class MongoCurrentMonitorDao implements CurrentMonitorDao {
TimeZone tz = getTimeZoneForAccount(_accountId);
Date month = DateUtils.getStartOfMonth(range.getStart(), tz);
Date end = DateUtils.getEndOfMonth(range.getEnd(), tz);
while (month.before(end)) {
while ((month != null) && month.before(end)) {
statuses.computeIfAbsent(month, _m->new ArchiveStatus(_accountId, _m, 0));
month = DateUtils.addMonths(month, 1, tz);
}
@@ -326,6 +329,8 @@ public class MongoCurrentMonitorDao implements CurrentMonitorDao {
TimeZone tz = getTimeZoneForAccount(_minute.getAccountId());
BreakerConfig config = getConfig(_minute.getAccountId());
BreakerGroup group = CollectionUtils.getFirst(config.getBreakerGroups());
if (group == null)
return;
Date day = DateUtils.getMidnightBefore(_minute.getMinuteAsDate(), tz);
DebugTimer t2 = new DebugTimer("Updating energy", logger);
EnergySummary energy = getEnergySummary(_minute.getAccountId(), group.getId(), EnergyViewMode.DAY, day);
@@ -412,13 +417,13 @@ public class MongoCurrentMonitorDao implements CurrentMonitorDao {
putEnergySummary(summary);
}
private void updateChargeSummary(BreakerConfig _config, EnergySummary _energySummary, TimeZone _tz) {
public void updateChargeSummary(BreakerConfig _config, EnergySummary _energySummary, TimeZone _tz) {
Date lookback = null;
for (BillingPlan p : CollectionUtils.makeNotNull(_config.getBillingPlans())) {
Date cycleStart = p.getBillingCycleStart(_energySummary.getStart(), _tz);
if (cycleStart.after(_energySummary.getStart()))
cycleStart = DateUtils.addMonths(cycleStart, -1, _tz);
if ((lookback == null) || cycleStart.before(lookback))
if ((lookback == null) || ((cycleStart != null) && cycleStart.before(lookback)))
lookback = cycleStart;
}
if (lookback != null) {
@@ -462,7 +467,7 @@ public class MongoCurrentMonitorDao implements CurrentMonitorDao {
Date yearMonthStart = yearStart;
Set<String> monthSummaryIds = new HashSet<>();
Date loopEnd = DateUtils.addDays(yearEnd, 1, _tz);
while (yearMonthStart.before(loopEnd)) {
while ((yearMonthStart != null) && yearMonthStart.before(loopEnd)) {
Date billingStart = plan.getBillingCycleStart(yearMonthStart, _tz);
if (DateUtils.isBetween(billingStart, yearStart, yearEnd))
monthSummaryIds.add(ChargeSummary.toId(rootGroup.getAccountId(), plan.getPlanId(), rootGroup.getId(), EnergyViewMode.MONTH, billingStart));
@@ -691,6 +696,11 @@ public class MongoCurrentMonitorDao implements CurrentMonitorDao {
return (account == null)?null:toAuthCode(account.getId(), account.getAuxiliaryAccountIds());
}
@Override
public String exchangeAuthCode(String _authCode, int _acctId) {
return null;
}
public String toAuthCode(int _acctId, List<Integer> _auxAcctIds) {
if (_acctId < 1)
return null;
@@ -777,6 +787,8 @@ public class MongoCurrentMonitorDao implements CurrentMonitorDao {
if (entity == null)
return false;
Account acct = getAccountByUsername(aes.decryptFromBase64ToString(_key));
if (acct == null)
return false;
acct.setPassword(_password);
putAccount(acct);
proxy.delete("password_reset", new DaoQuery("_id", _key));