Sako Isun Inverter USB Driver + Monitoring

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.

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

  • 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-.rules

Restart the Udev admin to apply the changes

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

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

Special Thanks To (tmkasun/solar-hybrid-inverter-monitor)

Convert video files using FFMPEG in Linux

Convert MKV to MP4

ffmpeg -i video_file.mkv output_file.mp4

If you only want to convert MKV to MP4 then you will save quality and a lot of time by just changing the containers. Both of these are just wrappers over the same content so the CPU only needs to do a little work. Don’t re encode as you will definitely lose quality.

It’s very straight forward using ffmpeg:

ffmpeg -i LostInTranslation.mkv -codec copy LostInTranslation.mp4

Here, you are copying the video codec and audio codec so nothing is being encoded.

To convert all MKV files in the current directory, run a simple loop in terminal:

for i in *.mkv; do
    ffmpeg -i "$i" -codec copy "${i%.*}.mp4"
done

Note: If you get an error like this:

opus in MP4 support is experimental, add '-strict -2' if you want to use it.
Could not write header for output file #0 (incorrect codec parameters ?): Experimental feature

use

for i in *.mkv; do
ffmpeg
-i "$i" -codec copy -strict -2 "${i%.*}.mp4" done

 

Convert MP4 to AVI

In order to just copy the video and audio bitstream, thus without quality loss:

ffmpeg -i filename.mkv -c:v copy -c:a copy output.avi

If you want FFmpeg to convert video and audio automatically:

ffmpeg -i filename.mkv output.avi