The Lantern Power Monitor is a Raspberry Pi service, Java Web Service, and Android application that allow you to monitor every electrical breaker in your house, regardless of how many panels or breakers you have.
Go to file
MarkBryanMilligan 6c2b567536
Update README.md
2021-03-24 12:30:29 -05:00
bom Make all of the links actual hyperlinks in excel. 2021-02-11 18:59:42 -06:00
case Add a 3B+ case. 2021-03-10 13:28:00 -06:00
currentmonitor Fix 'lifetime' aggregation. 2021-03-06 23:43:57 -06:00
pcb Added the pcb files. 2021-01-15 16:17:56 -06:00
util Add the static single hub BOM. 2021-02-11 18:52:19 -06:00
zwave Add the static single hub BOM. 2021-02-11 18:52:19 -06:00
.gitignore Initial Commit 2021-01-14 16:28:24 -06:00
LICENSE Initial commit 2021-01-12 21:31:39 -06:00
pom.xml Initial Commit 2021-01-14 16:28:24 -06:00
README.md Update README.md 2021-03-24 12:30:29 -05:00

LanternPowerMonitor

The Lantern Power Monitor is a Raspberry Pi service, Java Web Service, and Android application that allow you to monitor every electrical breaker in your house, regardless of how many panels or breakers you have.

Here's an imgur album showing what this is and how it works:
Lantern Power Monitor - Imgur

The android application is available here:
Lantern Power Monitor - Google Play

You can buy the parts to build a hub or a pre-built hub here:
Lantern Power Monitor - Etsy
If you don't want to buy one of these from me, you can use the bom in the source below to buy the parts yourself (highly recommended)

Index

bom

An excel file that lists every part required to construct a Lantern Power Monitor Hub and links to where each part can be purchased.
I'd much prefer everyone use this bom to get their own parts. Building kits is tedious.

case

STL files and Blender models to print your own case for a Lantern Power Monitor Hub

currentmonitor

Contains all source code for the raspberry pi service and the web service. The raspberry-pi service posts data to the web service which also handles requests for data from the android app.

lantern-currentmonitor

This is the raspberry pi service.

lantern-dataaccess-currentmonitor

A mongodb implementation of the data access for the current monitor service.

lantern-datamodel-currentmonitor

A shared data model used by the raspberry pi service and the web service

lantern-service-currentmonitor

This is the web service (compiles to a war and can most easily be deployed to tomcat)

pcb

Gerber files and the source EasyEDA file for the Lantern Power Monitor Hub pcb.

util

Utility libraries used by the raspberry pi service and the web service.

zwave

This is only tangentially related. A java library for running a zwave controller and a web service that the android app can use to control zwave devices in your home. This isn't currently part of the hub implementation, but in the future the hubs will be able to run a zwave controller.

Ok, how do I run this thing?

The easiest way to run the software on a hub is to download a pre-built SD card image. One can be downloaded here:
hub_1.0.3.zip

Flash this to any micro sd card (4gig or larger) and you're good to go. Fire up the hub and the phone app should be able to connect to it via bluetooth to finish the configuration. The default password on this image is pi/LanternPowerMonitor

When you add the hub to your configuration via the app, you can change where the hub posts data. If you use lanternsoftware.com (the default host), your data will be stored there securely and won't be shared with or sold to anyone. If you really want to run your own server, you're of course welcome to do that instead, instructions are located further down.

Now that the service is running on the pi, how do I configure everything in the android app?

  1. Create your panel in the "Configure Panels" page from the main menu. Before you have your hub connected, there will be no place to select a hub and port for each breaker. Don't worry, we'll get to that later.

  2. With your hub plugged in and running for at least 30 seconds or so, go into the "Configure Hubs" page from the main menu. In here you'll see a status of "Scanning for Hubs..." (if you're on at least 1.0.7 of the app). If you're in range of your hub and its service is running, the app should find it pretty quickly (less than 15 seconds). If this is the first hub you've added, it will prompt you for your wifi credentials. After that, it will send via bluetooth the hub index (so it knows which hub it is), host (so it knows where to post data), auth code (so it knows which account it is and can post data), the encrypted wifi credentials, and finally a command to reboot.

  3. After your hub reboots, it should acquire an ip from your router, start the service, and try to start posting data. The hubs will try to auto-calibrate your voltage to 120V too, but if your AC/AC transformer is not plugged in, it will notice that and not try to auto-calibrate. It will continue to try to auto-calibrate each time you restart the hub until it does so succesfully.

  4. Now that your hub is in the app, you need to go back into your panel and map each space to the port that you plugged the CT into. So say you put a CT on space 4, and you plugged that CT into port 7 on your hub, in your panel config, select space 4 and at the bottom, select hub 0 and port 7.

  5. After you have your ports mapped, the hub does not currently pick up that change automatically. I will make it do that eventually, but for right now, you need to restart your hub one more time. (You can do this via bluetooth, but it's probably easier to just yank the power and plug it back in)

  6. After that second restart, you should start seeing data. If you're not getting data in your app, the hub probably was not able to get a wifi connection. You can pull the last 10 lines of the log file and network details from the hub via bluetooth on the hub config page to troubleshoot.

Ok, but I don't like doing things the easy way.

First, you and I will get along just fine. Second, do a reactor build from the root folder:

~/LanternPowerMonitor$ mvn clean install

raspberry pi service

The compiled service will be at LanternPowerMonitor/currentmonitor/lantern-currentmonitor/target/lantern-currentmonitor.jar
This is a shaded jar that contains all of the required components to function. It must be copied to /opt/currentmonitor on the pi.

After that, you need to install wiring-pi:

sudo apt-get install wiringpi

You also need to have java 1.8 or newer installed.

Create a configuration file at /opt/currentmonitor/config.json
Use the format below to get started

{
	"hub": 0,
	"host": "https://lanternsoftware.com/currentmonitor",
	"auto_calibration_voltage": 120.0,
	"needs_calibration": true
}

To install the current monitor service, use a service file like the one below:

[Unit]
Description=Current Monitor
After=syslog.target network.target

[Service]
Type=simple

User=root
Group=root

WorkingDirectory=/opt/currentmonitor

ExecStart=/opt/java/jdk1.8.0_231/bin/java -cp /opt/currentmonitor/lantern-currentmonitor.jar com.lanternsoftware.currentmonitor.MonitorApp

[Install]
WantedBy=multi-user.target

You may need to change the path of your jdk, but lantern-currentmonitor.jar must be installed at /opt/currentmonitor
Move your currentmonitor.service file to /etc/systemd/system/ and enable the service

sudo mv currentmonitor.service /etc/systemd/system/
sudo systemctl enable currentmonitor

After you do all of this and have the service running, the app still won't be able to connect to the service via bluetooth due to a bug in bluez in the raspbian OS.
To fix this, you must manually recompile bluez after changing some of the source. (Ready to just download that SD image yet?)
In the file gatt-helpers.c, in the method bt_gatt_exchange_mtu, change the line

id = bt_att_send(att, BT_ATT_OP_MTU_REQ, pdu, sizeof(pdu), mtu_cb, op, destroy_mtu_op);<br>

to

id = bt_att_send(att, BT_ATT_OP_MTU_RSP, pdu, sizeof(pdu), mtu_cb, op, destroy_mtu_op);<br>

I need to submit this fix to the bluez project, but I haven't taken the time yet.

web service

So you don't trust me with your data, eh? No worries, I get it. Here's how you run your own server.

After your reactor build, the compiled war will be at LanternPowerMonitor/currentmonitor/lantern-service-currentmonitor/target/lantern-service-currentmonitor-1.x.x.war That can be deployed to tomcat. The 'host' parameter in the raspberry pi config.json file needs to point to wherever you deploy the service so your hubs post the data to your server instead of the official lantern software one.
I'd recommend a valid dns entry and an ssl certificate, but, it's up to you, you're already knee deep in "I'll do what I want" territory here.

Before you deploy it, you need to generate a config file that contains the mongodb credentials.
There is a file at lantern-service-currentmonitor/src/test/java/com/lanternsoftware/currentmonitor/CreateMongoConfig.java that can do this for you.
Place the generated config file in /opt/tomcat (which is where I have tomcat installed). If you want it to be read from somewhere else, you can modify the paths in LanternFiles.java

The last thing you need is a private aes key to encrypt user auth tokens. One of those can be generated with CreateAuthKey.java.
I realize these instructions aren't complete, but if you're going down this path, I suspect you sort of already know what you're doing, so hopefully that's enough to point you in the right direction.