The tools in this folder (and subfolders) provide the ability to communicate with Hoymiles micro-inverters.
They require the hardware setup described below.
The tools are still quite rudimentary, as the communication behaviour is not yet fully understood.
This is part of an ongoing group effort, and the knowledge gained so far is the result of a crowd effort that started at [1].
Thanks go to all who contributed, and are continuing to contribute, by providing their time, equipment, and ingenuity!
ahoy.py
has been successfully tested with the following setup
- RaspberryPi Model 2B, 4B (any model should work)
- NRF24L01+ Radio Module connected as described, e.g., in [2] (Instructions at [3] should work identically, but [2] has more pretty pictures.)
- or the PaHoy board
- TMRh20's 'Optimized High Speed nRF24L01+ Driver' [3], installed
as per the instructions given in [4]
- Python Library Wrapper, as per [5]
- or the easy way, using pyRF24[6]
Either you make use of the way proposed in the following, using the NRF24 Python Wrapper and the 'Optimized High Speed nRF24L01+ Driver' OR you just use pip and let it install pyRF24.
- If you go with pyRF24, all that needs to be done is installing pyRF24 as described in [6]. Please be aware that not all examples provided in this repo are prepared to use pyRF24. It might be nescessary to adjust the imports from RF24 to pyRF24 to get them running. Once you installed pyRF24, go on at 'Required python modules'
- If you go with the RF24 wrapper, do the following steps
You have to install the NRF24 Python Library, as a Dependency for the Raspberry Pi Version of Ahoy.
To do that correctly, I have contacted the developer of NRF24 via github Python 3 Wrapper not installing properly #845 as I could not get the Python Wrapper for NRF24 to be built.
- Install Raspberry Pi OS lite x86 with raspberry pi imager
- Connect nrf24 module to raspberry pi (as described in github)
- Login with user pi
- Execute
sudo apt update && sudo apt -y upgrade
- Execute
sudo raspi-config
and- Select "Expand filesystem" in "Advanced Options"
- Activate "SPI" in "Interface Options"
- "Finish" to exit
raspi-config
Tool, reboot YES!
- Login as pi user again
sudo apt install cmake git python3-dev libboost-python-dev python3-pip python3-rpi.gpio
sudo ln -s $(ls /usr/lib/$(ls /usr/lib/gcc | \
tail -1)/libboost_python3*.so | \
tail -1) /usr/lib/$(ls /usr/lib/gcc | \
tail -1)/libboost_python3.so
git clone https://github.com/nRF24/RF24.git
cd RF24
export RF24_DRIVER=SPIDEV
rm Makefile.inc #just to make sure there is no old stuff
mkdir build && cd build
cmake ..
make
sudo make install
cd ../pyRF24
rm -r ./build/ ./dist/ ./RF24.egg-info/ ./__pycache__/ #just to make sure there is no old stuff
python3 -m pip install --upgrade pip
python3 -m pip install .
python3 -m pip list #watch for RF24 module - if its there its installed
cd ..
cd examples_linux/
python3 getting_started.py # to test and see whether RF24 class can be loaded as module in python correctly
If there are no error messages on the last step, then the NRF24 Wrapper has been installed successfully.
The description above does not work on Debian 11 (bullseye) 64 bit operating system. Please check first, if you have Debian 11 (bullseye) 64 bit operating system installed:
uname -a
search for aarch64lsb_release -d
cat /etc/debian_version
There are 2 possible solutions to install the RF24 wrapper:
1. Solution:
sudo apt install cmake git python3-dev libboost-python-dev python3-pip python3-rpi.gpio
sudo ln -s $(ls /usr/lib/$(ls /usr/lib/gcc | \
head -1)/libboost_python3*.so | \
tail -1) /usr/lib/$(ls /usr/lib/gcc | \
head -1)/libboost_python3.so
git clone https://github.com/nRF24/RF24.git
cd RF24
rm -rf build Makefile.inc
./configure --driver=SPIDEV
edit
Makefile.inc
with your prefered editor e.g. nano or viold:
CPUFLAGS=-marm -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard CFLAGS=-marm -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard -Ofast -Wall -pthread
new:
CPUFLAGS= CFLAGS=-Ofast -Wall -pthread
continue now
make
sudo make install
cd pyRF24
rm -r ./build/ ./dist/ ./RF24.egg-info/ ./__pycache__/ #just to make sure there is no old stuff
python3 -m pip install --upgrade pip
python3 -m pip install .
python3 -m pip list #watch for RF24 module - if its there its installed
2. Solution:
sudo apt install git python3-dev libboost-python-dev python3-pip python3-rpi.gpio
git clone --recurse-submodules https://github.com/nRF24/pyRF24.git
cd pyRF24
python3 -m pip install . -v # this step takes about 5 minutes on my RPI-4 !
If you have problems with your radio module from ahoi, e.g.: cannot interpret received data,
please try to reduce the speed of your radio module!
Add the following parameter to your ahoy.yml configuration file in "nrf" section:
spispeed: 600000
(0.6 MHz)
Some modules are not installed by default on a RaspberryPi, therefore add them manually:
pip install crcmod pyyaml paho-mqtt SunTimes
Local settings are read from ahoy.yml
An example is provided as ahoy.yml.example
The following command will run the communication tool, which will try to contact the inverter every second on channel 40, and listen for replies.
Whenever it sees a reply, it will decoded and logged to the given log file.
$ sudo python3 -um hoymiles --log-transactions --verbose --config /home/dtu/ahoy.yml | tee -a log2.log
Python parameters
-u
enables python's unbuffered mode-m hoymiles
tells python to load module 'hoymiles' as main app
The application describes itself
python3 -m hoymiles --help
usage: hoymiles [-h] -c [CONFIG_FILE] [--log-transactions] [--verbose]
Ahoy - Hoymiles solar inverter gateway
optional arguments:
-h, --help show this help message and exit
-c [CONFIG_FILE], --config-file [CONFIG_FILE]
configuration file
--log-transactions Enable transaction logging output
--verbose Enable debug output
To enable mqtt payload injection, this must be configured per inverter
...
inverters:
...
- serial: 1147112345
mqtt:
send_raw_enabled: true
...
This can be used to inject debug payloads The message must be in hexlified format
Use of variables:
tttttttt
expands to current time like we know from our80 0b
command
Example injects exactly the same as we normally use to poll data
$ mosquitto_pub -h broker -t inverter_topic/command -m 800b00tttttttt0000000500000000
This allows for even faster hacking during runtime
If you want to run directly from the start, you might want to install it as a service. Depending on if you want to run it once a user is logged in or as soon as the system is booted, two service examples are included. ahoy.service allows you to start it as a user service upon login. ahoy_system.service allows you to start it as a system service already before login without user interaction.
Use basic command line tools to get an idea what you recorded. For example:
$ cat log2.log
[...]
2022-05-02 16:41:16.044179 Transmit | 15 72 22 01 43 78 56 34 12 80 0b 00 62 3c 8e cf 00 00 00 05 00 00 00 00 35 a3 08
2022-05-02 17:01:41.844361 Received 27 bytes on channel 3: 95 72 22 01 43 72 22 01 43 01 00 01 01 44 00 4e 00 fe 01 46 00 4f 01 02 00 00 6b
2022-05-02 17:01:41.886796 Received 27 bytes on channel 75: 95 72 22 01 43 72 22 01 43 02 8f 82 00 00 86 7a 05 fe 06 0b 08 fc 13 8a 01 e9 15
2022-05-02 17:01:41.934667 Received 23 bytes on channel 75: 95 72 22 01 43 72 22 01 43 83 00 00 00 15 03 e8 00 df 03 83 d5 f3 91
2022-05-02 17:01:41.934667 Decoded: 44 string1= 32.4VDC 0.78A 25.4W 36738Wh 1534Wh/day string2= 32.6VDC 0.79A 25.8W 34426Wh 1547Wh/day phase1= 230.0VAC 2.1A 48.9W inverter=114171230143 50.02Hz 22.3°C
[...]
A brief example log is supplied in the example-logs
folder.
- Ability to talk to multiple inverters
- MQTT gateway
- understand channel hopping
configurable polling intervaldone: interval ist configurable in ahoy.yml- commands
- picture of setup!
- python module
- ...
- [1] https://www.mikrocontroller.net/topic/525778
- [2] https://tutorials-raspberrypi.de/funkkommunikation-zwischen-raspberry-pis-und-arduinos-2-4-ghz/
- [3] https://nrf24.github.io/RF24/index.html
- [4] https://nrf24.github.io/RF24/md_docs_linux_install.html
- [5] https://nrf24.github.io/RF24/md_docs_python_wrapper.html
- [6] https://github.com/nRF24/pyRF24