Introduction: Nabito - the Open Socket: Smart Meter for EV Charging

About: Systems Distributed is my personal initiative to build, integrate, install and promote distributed systems solutions that are based on open source wherever open source is possible and makes sense.

What is it?

Nabito - the open socket is essentially a smart electricity meter with electricity metering, user authorization, billing capabilities and user management. Currently it's in a very early stage but some core functionalities are already in place.

The control box consists of easy-to-get-online parts and is designed to be an intelligent and yet inexpensive electric socket solution for public and private parking lots for slow charging of electric vehicles. It runs on OrangePi One single-board computer (SCB).

The total cost of this solution is around €50 ($60).

Nabito - the open socket is currently designed for charging on ordinary sockets, in continental Europe it's 230V and 16A, i.e. cca. 3.3kW continuous, this is roughly equivalent or slightly higher than US level 1 charging.

Specs:

  • Single Phase
  • Voltage: 230 V AC
  • Max. current: 16 A
  • Power: 3.3 kW
  • Size: 190x140x70mm
  • Interface: RJ45 LAN connection
  • IP compliance: IP55

Future control boxes will be able to handle higher currents (level 2 charging) as well.

DISCLAIMER: The following build guide is rather crude at the moment (missing wiring diagrams, missing some assembly steps, etc.), I wanted to get it out there as soon as possible, will work on improving it if I see the project is meaningful and has traction. I thought this little control box will be easy to document, but to my surprise there are many small steps that I have taken when building this, so please, if this build guide does not cover everything you need to know or if you have any questions, send me a mail. Thanks for understanding.

Step 1: Why Make It? - the Story

Compare the two pictures above. Not everybody has a private garage to charge their EV securely during night. In fact vast number of people live in apartment buildings and leave their cars in the streets during the night.

I explain all the reasons why I'm making this project in the following blog post:

http://sysdist.com/evs-are-pointless-for-apartment-people

Step 2: What Does It Do?

1. User authentication

Read the QR code with your mobile phone. It will direct you to the web interface.
The web user interface allows users to sign up, log in and use the control box. An admin interface is under construction. Admin can approve, disapprove users.

2. On/Off switching
With a mains relay and a contactor it can switch the outlet socket on/off based on user interaction.

3. Energy metering

The control box measures AC current and logs power usage. Standard metering function.
The energy metering is done per user.

4. Billing

Bills are created for individual users based on their energy usage. Monthly bills will be created later for admin convenience.

Step 3: Components

HW stack:

Total HW cost: $60.16 (52.28)

SW stack:

  • Armbian Linux (Ubuntu based), open source, $0 (all glory to Linus Torvalds + 20k people who worked on Linux kernel + the kind Armbian people who maintain linux images for ARM processors)
  • Postgres DB, open source, $0
  • Git, open source (more glory to Linus), $0
  • Ruby on Rails (RVM, Ruby, Gems), open source, $0
  • Nabito-app: https://github.com/sysdist/nabito-app, open source, $0
  • Arduino script for CT sensor monitoring, $0

Total SW stack cost: $0 (*THUMBS_UP*)

Step 4: The Server: OrangePi One, SD Card, Armbian, Web App

  1. Download Armbian linux image for OrangePi One
    https://www.armbian.com/orange-pi-one/
    You can download the desktop version, if you want to mess around with desktop environment. For this project you only need the server version, because we'll be running an HTTP server and serve it via LAN, no HDMI output is currently required/supported
  2. Use this guide if you want to learn more about Armbian
    https://docs.armbian.com/User-Guide_Getting-Started/
  3. Burn the img file onto the micro SD card with Etcher
    https://etcher.io/
  4. Insert the SD card into the OrangePi One
  5. Connect the LAN cable
  6. Connect the power source and boot the server
  7. Find out the OrangePi's IP address on your local router admin interface (let's say it's gonna be 192.168.1.10)
  8. Connect to the Orange from terminal:
    ssh root@192.168.1.10
  9. Do the initial setup the system asks you
  10. Create an OS user "nabito" or name your user as you like
  11. Add user "nabito" to sudoers
    https://www.digitalocean.com/community/tutorials/how-to-create-a-sudo-user-on-ubuntu-quickstart
    To enable any sudo command without password:
    As root:

    visudo -f /etc/sudoers.d/nabito
    write line:
    %sudo ALL=(ALL) NOPASSWD:ALL
    into the file and save the file

  12. Install the GPIO library
    https://www.instructables.com/id/Orange-Pi-One-Python-GPIO-basic/
  13. Set up the relay script:
    as root:
    cd /usr/local/bin
    git clone https://github.com/sysdist/nabito-os-scripts.git

Once your Linux system is up and running, it's time to prepare the environment for the Nabito application, which runs on Ruby on Rails.

  1. Install postgresql database
    $ sudo apt-get update

    $ sudo apt-get install postgresql postgresql-contrib

  2. configure database user nabito
  3. Install RVM
  4. Install Ruby version 2.4.0 using RVM
  5. Install Rails, version 5.0.2
  6. Clone the nabito application into ~/www/
    $ mkdir ~/www; cd ~/www;
    $ git clone https://github.com/sysdist/nabito-app.git
  7. $ cd nabito-app;
    $ bundle install
  8. $ rake db:setup
  9. $rails server --binding=0.0.0.0 # to run the server
  10. Test if the application loads up: http://192.168.1.10:3000
  11. Server part done!

Step 5: The Current Sensor: Arduino Sketch

  1. Connect the Arduino to your PC/notebook via the USB port
  2. Download Arduino development IDE from arduino.cc
  3. add library from https://github.com/openenergymonitor/EmonLib
    the monitoring logic is based on https://github.com/openenergymonitor/EmonLib
  4. load the sketch below into your arduino
  5. check the values in the serial monitor
#include "EmonLib.h"// Include Emon Library
EnergyMonitor emon1;
// Create an instance
void setup()
{
  Serial.begin(9600);
  emon1.current(0, 30);             // Current: input pin, calibration.
}
void loop()
{
  double Irms = emon1.calcIrms(1480);  // Calculate Irms only
  Serial.print(Irms);             // Irms
  Serial.println(";0.0;0.1;0.4;1.2;2.5;"); //dummy values for now
  delay(100); 
}

Step 6: Wiring: Mains Cables

Wire the mains cables like in the first picture.

The black cable denotes the line, the yellow/green denotes neutral.

Yes, I know, the ground is not present in the box and it's a safety issue, in the next versions of Nabito, the control box will be properly grounded, I promise.

Step 7: Wiring: Arduino and the CT Sensor

Wire the Arduino with the CT sensor according to the following manual:

https://learn.openenergymonitor.org/electricity-monitoring/ct-sensors/how-to-build-an-arduino-energy-monitor-measuring-current-only

You need:

  • Arduino (you can use any Arduino: Uno, Nano, Mega, whichever you like, as long as it has an ADC)
  • 10uF capacitor
  • 2x 10kOhm resistors
  • 3 jumper cables
  • 3.5mm female jack socket
  • CT sensor 30A/1V

I soldered the wires directly with the resistors and the capacitor, I know it's nasty and a clean soldering job with on a PCB would be nicer, but for prototype purposes, this is enough for now.

Step 8: Wiring: Arduino and OrangePi

Connect Arduino to the OrangePi via the USB port, this way it serves as a serial port and a power supply for the Arduino. This is not ideal, I know, UART connection is probably better for a number of reasons, but for simplicity's sake, I used the USB for basic wiring config.

Step 9: Wiring Everything Together

  1. Clamp the CT sensor on the mains line going out of the mains relay
  2. Connect the LAN cable and power source for OrangePi.
  3. Screw in the junction box lid
  4. And you're done wiring/assembling!

Step 10: Running and Testing

  1. Connect Nabito to mains power supply and your network via the LAN cable
  2. connect a small load (e.g. a table lamp) to the outlet socket

  3. Figure out Nabito's IP from your router

  4. ssh into Nabito
  5. start your application:
    $ cd ~/www/nabito-app
    $ rails server --binding=0.0.0.0
  6. point your browser to Nabito_IP:3000
  7. Login with admin user:
    login: admin@example.com
    pass: changeme
  8. go to socket 1 and press the button "switch on"
  9. the lamp should switch on
  10. leave it on for a couple of minutes
  11. then switch it off thru the web GUI
  12. go to -> Menu -> Billing
    you should see a record of your last energy use while the lamp was on

Step 11: The Conclusion, Issues and Product Roadmap

My main reason for doing this project was to see, if you can create a relatively cheap smart meter with secure user authorization. The moment I realized you can get OrangePi SCBs for as cheap as 8Euros, I started experimenting with it.

It turns out OrangePi can run an HTTP server (Ruby on Rails + Puma + Nginx) rather smoothly and can log energy use number no problem. I had the control box running for 30 days in a row and everything worked fine.

The fact that you can have a smart meter control box for €50 ($60) is quite cool in my view.

Issues:

  • currently tested on relatively small loads (max 2kW): lamps, soldering iron, kettle
  • the mains relay is rated at 10A, to take advantage of higher currents, we'll need to add a heavier-duty contactor, I have one from Aliexpress for 5Euros, which is single-phase, rated at 25A, will test it and update this guide afterwards
  • the OrangePi processor can get quite hot (50-60 degrees Celsius), since this is a closed box, there is no air ventilation, this needs to be considered if you would install the box in a place where it gets a lot of direct sunlight or in very warm climates. Beware of fire hazard, be safe!
  • the web GUI functionality is currently quite basic, so expect bugs and report them to me via Github ;)
  • each control box functions as a standalone isolated HTTP server, which is not ideal if you were to install e.g. a couple of them in a private residential parking area, a client-server, or even better client-cloud config would be better, but we are not there yet ;)
  • no outside LED indicators if the OrangePi is working ok, if it's successfully connected to the interwebs
  • if the internet connection is down, the out socket won't work

Opportunities:

  • serve higher currents, up to 60A probably
  • serve more phases (2-phase, 3-phase)
  • include a proper chargin outlet (CHADEMO/CSS/Tesla plug, etc.), but this would raise the cost of the control box substantiallyt, additional logic for communication with the EV would be required
  • client-server, client-cloud configurations
  • RFID/NFC/ user authorization with a swipe card or mobile NFC, mobile BLE authorization
  • WIFI (use e.g. OrangePi Zero: it has no HDMI, which is good since HDMI output is not used in Nabito, has wifi, can be powered with ordinary mobile phone charger)
  • more precise energy metering (ready-made AC monitoring module)
  • develop GUI functionalities: better graphs, user management, custom APIs for billing engines, monthly bills via emails
  • LDAP/Active directory integration for large companies that want to enable mass adoption on their workplace premises
  • build custom Armbian images, which would contain the whole SW stack and be just ready to go
  • the CPU won't be doing much most of the time, so you could mine bitcoins at some very small rate or do some other blockchain fancy stuff (anything possible,really, it's just a linux box :-P )
  • since the box is quite cheap and open source, it could be mass-adopted, with small business installing and managing it locally

More EV related theory and applications on the Systems distributed website!