Logging and Reporting Utilities for Rainforest Automation's Raven and EMU-2 Smart Meter Energy Monitors
Initial Coding Development by: Hamed Ghafarshad and Viet Than Ly
Development Extended by: Yutien Ren
Managed by: Dr. Michael Klopfer, Dr. Sergio Gago, Prof. G.P. Li
California Plug Load Research Center (CalPlug), California Institute of Telecommunications and Information Technology (Calit2), University of California, Irvine
CalPlug acknowledges the support of Southern California Edison for the development of this work as part of the "EnergyChannel" project.
Copyright (c) Regents of the University of California, 2018
This is a set of multi-threaded logging scripts written in Python 3 and tested in Ubuntu 16.04 that allows a Rainforest Automation Raven and EMU-2 smart meter HAN interface devices using their XML API (https://rainforestautomation.com/wp-content/uploads/2014/02/raven_xml_api_r127.pdf).
The reporter code as written provides 3 functions (available in the reporter directory):
-
Meter to SQL - the meter data will be stored locally in a mySQL database (tested with MySQL 5.5)
-
Meter to SQL then SQL to MQTT - the use of an addon script provides repeating of the local database to and MQTT broker
-
Meter to MQTT - direct reporting of reported values to an MQTT broker. This effort is similar to https://github.com/stormboy/node-raven but in Python versus node.
Included is a script that reads from a broker and if an updated entry is passed to the broker, these are read, parsed, and inserted in a Mongo DB database (in the recorder directory).
For the SQL logging capability, a pre-made SQL database with a pair of tables named "instantaneous_demand" and "run_info" is required. The structure of the tables is as follows:
-
The "instantaneous_demand" table has columns for time, demand, multiplier, divisor, run (designated run name), and hash.
-
The "run_info" table has columns for "name (run name which matches the data in "instantaneous_demand" table), hash, meter_id, time.
WARNING: As the SQL logging scripts can read a point every 5-10 seconds from the meter, extended runs of these scripts can lead to large database sizes. If this script is run on a low power device, performance can degrade with time unless there is another script or operation that is used to purge or archive historic entries. You are warned! Occasionally a parsing error will show up for the first read, ignore this. Reading will be OK after this first issue.
- Log into the Calit2 MQTT server(cpmqtt1) using the following credentials:
- Open the mongo shell
- Enter command "use pulses"
- Enter "db.InstantaneousDemandTest.find()" to see all records posted from the Meter to SQL to MQTT add-on. Enter "db.InstantaneousDemandTest1.find()" to see all records posted from the direct Meter to MQTT script.
- Refer to MongoDB documentation for a list of commands to access specific records
- Make sure the Raven stick or Rainforest Automation unit is on and attached to a USB port
- Open the reporter directory inside of python-raven
- Run the the "run.py" script with the following command : sudo python3 run.py
- A query prompt will ask you to type in the appropriate name of the run
- The script will begin sending data to SQL after a 3 2 1 countdown.
- In the case that the Raven / Rainforest Automation unit is not found, the terminal will display "searching..." repeatedly
- If it is found successfully, then the rows of data read from the unit and added to the SQL database will display on the screen sequentally.
- To start the server to collect data from the MQTT broker to MongoDB, log on to the Calit2 MQTT server(cpmqtt1).
- Open the smartmeter directory
- Run the server script with the following command: sudo python3 serverMqtt.py
- On a successful connection to the MQTT broker, the terminal will display "Connected with result 0"
- In a seperate terminal execute the run.py script explained under Meter to SQL script instructions
- Open another terminal
- Open python-raven/reporter directory
- Run the loggerMqtt.py script with the following command : sudo python3 loggerMqtt.py
- On a successful connection to the MQTT broker, the terminal will display "Connected with result 0"
- Data that are successfully pushed to MQTT will display on the terminal running loggerMqtt.py
- Data that is pushed to MongoDB will display on the terminal running serverMqtt.py
Note: This script posts instantaneous demand, current summation delivered and current summation recieved along with a meter Mac ID to a MongoDB table named "InstantaneousDemandTest1".
- To start the server to collect data from the MQTT broker to MongoDB, log on to the Calit2 MQTT server(cpmqtt1).
- Open the smartmeter directory
- Run the server script with the following command: sudo python3 serverMqttR.py
- On a successful connection to the MQTT broker, the terminal will display "Connected with result 0"
- Open a seperate terminal
- Open the python-raven/recorder directory
- Run the direct_mqtt_run.py script with the following command: sudo python3 direct_mqtt_run.py
- On a successful connection to the MQTT broker, the terminal will display "Connected with result 0"
- Rows of data that are sent from the broker should begin displaying on the terminal.
Data Visualizer for Internal Usage (main.py data_retriever.py auto_box.py simple_visualizer_v2.py visualizer_internal_v2.py)
Note: This Visualizer is only for interval usage. It may be polished later if necessary and be converted into an .exe or .app file for different OS.
- Open main.py
- Fill in the credentials for db and retrieved keys
- Run main.py
- Graph will be the first user in the db with auto-generated lower and upper bound for time interval
- Auto-Complete and Cascade-View for user search box
- Switch user by clicking Change User
- After changing time interval, click draw to get graph of the user in the time interval
- Reset to get defualt graph for the current user in the defualt time interval which bounded by min and max date of record