Monitoring A Sunny Boy 4000tl Solar Inverter Via Its Bluetooth Interface.
We recently had a 4kW grid-tied solar system installed which used a very well engineered Sunny Boy 4000tl inverter. The electricity company pays us very little for the energy that we produce and charges a lot for the energy that they provide, so it is important to us that we use as much of it as we can when the sun is shining. To this end, we needed a way of knowing how much is energy being produced at any given time without having to run out to the look at the inverter’s display all the time, and, in future, to be able to switch loads on and off automatically.
The inverter does have a Bluetooth interface, but unfortunately the monitoring software (provided free by the manufacturer) runs only on Windows, and while it does produce all sorts of very professional looking graphs and pie charts, it does not provide the required functionallity of being able to read the instantaneous energy by means of a script (not to mention the idea of dedicating a Windows computer to this task … ), and the manufacturer will not release details of the protocol.
Fortunately, Wim ON4AKH has decoded the protocol for some earlier model inverters and written a utility that will read the inverter and send the data to a solar-monitoring webiste and write it to an SQL database; it’s avaliable on his website here
Unfortunately, his script file would not work with the newer model 4000tl inverter, so I decided to rewrite the code to make it more general purpose by removing the SQL and website upload functionallity, and have strengthened some of the error checking and status messages to make it easier to debug scripts for different inverters. I present the code here, along with a script that works with the 4000tl inverter.
As we require a wifi access point at the front of the house and reasonably near to the inverter, a router running OpenWRT logical choice. The TP-LINK TL-WR703n was decided upon as it is cheap and has the required USB port. A powered USB hub was used to provide power to the router and to connect the flash drive and Bluetooth dongle. I suspect that an unpowered hub would also be suitable, as the flash drive and dongle don’t require much current, but I haven’t tried this.
The hardware mounted to a piece of nylon chopping board and suspended out of sight behind a curtain.
At left is the
TL-WR703N router and at right is a powered USB hub which provides 5v power for the router, and connectors for the router’s root-filesystem flash drive, and the tiny Bluetooth dongle which can be seen protruding on the right. The router also provides wi-fi for the front of the house.
The inverter is approximately 8 metres away and through three interior walls and one exterior brick wall; the Bluetooth signals seem to have no problem in penetrating.
- If you intend to run the utility on a TL-WR703N, or on any other router using the Atheros AR7xxx/AR9xxx (ARM) platform, you can use the precompiled binary that is available here
- The required script file is here
- For other platforms, you’ll need to compile from the source code that is available here
- See this article for details on how to set up a cross-compilation environment.
3. Using The
The OpenWRT Bluetooth library and utility packages are required and can be installed by using the
opkg utility. Use the commands:
>opkg update >opkg install bluez-libs bluez-utils
to install these.
To connect to the inverter, its Bluetooth address and its serial number must be specified. The
hcitool utility is used to determine these.
To scan for devices that are in range:
>hcitool scan Scanning ... 00:80:25:A6:77:60 00:87:32:0A:C8:8A
Lists the addresses of two devices which can now be used to determine which one belongs to the inverter and to get its serial number:
>hcitool name 00:80:25:A6:77:60 SMA001d SN: 2130248863 SN2130248863
The SMA indicates that this is a Sunny Boy inverter and its serial number is 2130248863. Due to laziness on my part,
sbread must have the serial number specified in hexidecimal. The calculator applications on Linux and Windows can be used to do the conversion. See here for details, but in this case the serial number is to be specified as 7E:F9:04:9F
With no options, or incorrect options, the
sbread utility displays the help message:
>sbread Usage: sbread -address XX:XX:XX:XX:XX:XX -serial XX:XX:XX:XX [-script /path/to/script] [-v] [-vv] [-d] [-b] Where: -address specifies the bluetooth of the inverter. eg -address 00:80:25:A6:77:60 -serial specifies the serial number of the inverter converted to hexidecimal. eg: Inverter with s/n 2130248863 would be -serial 7E:F9:04:9F -script (optional) specifies the path to the script file. If not present, default script file /etc/sbread.script is used. -d display total energy produced so far today (in kWh), instead of current power -b display both current power and energy produced so far today. eg: 3077,13.40 -v specifies that verbose messages will be displayed while the program runs. Use -vv for very verbose (debug)messages. -h display this help message
The script file,
sbread.script should be placed in the
/etc directory, or else specified with the
The utility can now be run like this:
>sbread -address 00:80:25:A6:77:60 -serial 7E:F9:04:9F 302 >sbread -address 00:80:25:A6:77:60 -serial 7E:F9:04:9F -d 11.90 >sbread -address 00:80:25:A6:77:60 -serial 7E:F9:04:9F -b 308,11.65
The first example displays to
stdout the power currently being produced in watts. Second, with the
-d option, the energy produced so far today in kWh is displayed, and with the
-b option, both the power and energy are displayed.
Zero is returned on success, and if an error occurs, a message is printed to
stderr and non-zero is returned:
>sbread -address 00:80:25:A6:77:60 -serial 7E:F9:04:9F || echo $? ERROR: Timeout reading bluetooth socket 255
-v option can be used to help analyse connection problems
>sbread -address 00:80:25:A6:77:60 -serial 7E:F9:04:9F -v INFO: Inverter address: 00:80:25:A6:77:60 INFO: Inverter serial number: 7E:F9:04:9F INFO: Reading script from: /etc/sbread.script INFO: bluetooth channel: 1 INFO: got our bt address: ERROR: Timeout reading bluetooth socket
The informational messages are printed to
3.4. Running Automatically
In my application I use the perl script sbrun.pl which runs
sbread and uses the
curl utility to send the reading to a webserver by means of a simple HTML form submission.
* * * * * /usr/local/bin/sbrun.pl
runs the script each minute. You may find it useful as the basis for your own custom application and to write the data to an SQL database, or whatever is required.
4. Earlier Model Inverters.
The provided script file works with the model 4000tl inverter, but is unlikely to work with earlier models. For this, you might have success using the script provided with Wim’s distribution available here
If you need to create a new script file, you can use the
-vv option to have debug messages showing the Bluetooth messages that have been sent and received and what is being waited on:
>sbread -address 00:80:25:A6:77:60 -serial 7E:F9:04:9F -vv INFO: Inverter address: 00:80:25:A6:77:60 INFO: Inverter serial number: 7E:F9:04:9F INFO: Reading script from: /etc/sbread.script DEBUG: wait: 7e 1f 00 61 60 77 a6 25 80 00 00 00 00 00 00 00 02 00 00 04 70 00 DEBUG: recv: 7e 1f 00 61 60 77 a6 25 80 00 00 00 00 00 00 00 02 00 00 04 70 00 DEBUG: found DEBUG: Extracting INFO: bluetooth channel: 1 DEBUG: send 7e 1f 00 61 00 00 00 00 00 00 60 77 a6 25 80 00 02 00 00 04 70 00 01 00 00 00 00 01 00 00 00 DEBUG: wait: 7e 22 00 5c 60 77 a6 25 80 00 00 00 00 00 00 00 05 00 60 77 a6 25 80 00 DEBUG: recv: 7e 22 00 5c 60 77 a6 25 80 00 00 00 00 00 00 00 05 00 60 77 a6 25 80 00
The wait, send, and recv strings are specified in the script file, along with several macros. See
sbread.c for the meanings of the macros.
Now, for about $30 in hardware we can monitor the inverter from our computers and phones via a webserver and can still access wifi from the front of the house, and the new setup seems to draw less than 2 watts, so compared to the 14+ watts of the old access point that it replaces, payoff should be in 12 months or so.