Git Product home page Git Product logo

solar-hybrid-inverter-monitor's Introduction

Solar Inverter USB Driver + Monitoring Dashboard

No need to cut cables or connect to adaptors, Just plug the USB cable and play with your inverter

This is an Solar inverter monitoring and controlling system for hybrid inverters, Following are the main components in the system.

  • Solar Inverter driver program to communicate with USB serial port (Python)
  • Python Flask based REST API to expose the data
  • ReactJS based web portal (PWA) for monitoring and controlling the inverter

Tested Solar inverters

Currently we have tested this on

  • Sako Isun 3KW

Architecture

image

Supported compute devices

  • Raspberry pi
  • Orange pi
  • Any Unix device

Hardware setup

  • Use the USB cable provided with the inverter or any appropriate USB cable
  • Connect the USB cable to any of the supported device
  • Install the pre-requisite mentioned in the following install steps
  • Run the tools/check-inverter.py script to connection between inverter and the compute device
  • For any issues check the Troubleshoot section

How it works

Most of the Hybrid(Chinees) inverters comes with the following Serial interface

Bus 001 Device 002: ID 0665:5161 Cypress Semiconductor USB to Serial

For this VendorID and ProductID there are several UPS and inverter devices using this serial com device. But this device had no drivers for Raspberry pi, So when the inverter is connected to a Raspberry pi(or similar) compute device , it detects as a USB block storage device

/dev/usb/hiddev0

not as a USB serial communication device.

i:e

/dev/ttyS0 or /dev/USB0

To establish communication between the inverter and the compute device we had to use pyUSB approach described in here. For the basic working principles of Inverter - Compute device (Raspberry pi) communication check the above article.

Another important piece of the puzzle was to find out the communication protocol. This document from a random generous Czech inverter site.

Without this, Decoding the values sent from inverter was a challenge

and the meanings of

  • QPIGS: Device general status parameters inquiry

and

  • QMOD: Device Mode inquiry

were like greek!

Once the communication is established it's was just a matter of routing the data to client application (React app) to present the data.

We use Flask to implement REST API and ReactJS, MUI , React Query in the UIs.

Install

Most of the Raspberry pi & Orange Pi variations doesn't come with pip pre-installed, Hence we have to run this

  • Use the installation methods specify in the official doc

  • or use sudo apt-get install python3-pip

Install the Python USB communication library

  • python3 -m pip install pyusb

This is required for the following crc16 library

  • sudo apt-get install python3-dev

CRC16 is used to generate the 2 byte CRC, CRC is a way of detecting accidental changes in data storage or transmission

| Note: This only works upto python 3.9 versions, If you have a latest version of Python 3.10+, This will not work

  • python3 -m pip install crc16

Add a Udev rule as shown below, This is required to allow communicating with the USB device for none-sudoers users. Example file is given in

references/99-knnect.rules

in this repo

  • sudo vim /etc/udev/rules.d/99-<any-name>.rules

example

sudo cp references/99-knnect.rules /etc/udev/rules.d/

Restart the Udev admin to apply the changes

  • sudo udevadm control --reload-rules && sudo udevadm trigger

Deploying the REST API

Need following 2 packages

python -m pip install flask gunicorn

Accessing from anyway

Currently this only support monitoring through the local network, If you want to monitor or control the device through internet, Then you need to expose the APIs through Choreo (It's free) like API proxy service or Buy a Blynk subscription and publish data to blynk.

Troubleshoot

  • Use
sudo lsusb

to check whether the Serial Communication device has been detected by the operating system if so it show show as

Bus 001 Device 002: ID 0665:5161 Cypress Semiconductor USB to Serial

in the output of lsusb command

Similar projects

TODO

  • Improve UI
  • Currently you need to set battery discharge current rate (i:e 240Ah set to 240A)
  • Max PV power and voltage values

Protocol Docs

Web UI

image

image

TODO:

solar-hybrid-inverter-monitor's People

Contributors

tmkasun avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

solar-hybrid-inverter-monitor's Issues

QinHeng Electronics HL-340 USB-Serial adapter

my sako sunon pro has QinHeng Electronics HL-340 USB-Serial adapter instead of mentioned Cypress Semiconductor USB to Serial module.
this is the output i get when i run this code

hi@raspberrypi:~/solar-hybrid-inverter-monitor $ python tools/check-inverter.py connected to: /dev/ttyUSB0
True
0
Traceback (most recent call last):
  File "tools/check-inverter.py", line 18, in <module>
    ser.write(bytes.fromhex(START))
AttributeError: type object 'str' has no attribute 'fromhex'

JK BMS monitoring and commands

ubuntu@ubuntu:~$ jkbms -p C8:47:8C:E2:A0:2E -n "JK-B1A20S15P" -P JK02 -c getInfo
Command: getInfo - BLE Device Information inquiry
--------------------------------------------------------------------------------
Parameter          Value                Unit
header             55aaeb90
record_type        03
record_counter     56
device_model       JK-B1A20S15P
hardware_version   10.XG
software_version   10.07
up_time            348D4H59M60S
power-on_times     5
device_name        JK-B1A20S15P
device_passcode    1234
manufacturing_date 220702
serial_number      2032809436
passcode           0000
user_data          Input Userdata
setup_passcode     123456

ubuntu@ubuntu:~$ jkbms -p C8:47:8C:E2:A0:2E -n "JK-B1A20S15P" -P JK02 -c getCellData

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.