Computing stuff tied to the physical world

Accessing the SMA inverter via Bluetooth

In Software on Nov 6, 2012 at 00:01

As pointed out in recent comments, the SMA solar PV inverter can be accessed over Bluetooth. This offers various goodies, such as reading out the daily yield and the voltage / power generation per MPP tracker. Since the SB5000TL has two of them, and my panels are split between 12 east and 10 west, I am definitely interested in seeing how they perform.

Besides, it’s fun and fairly easy to do. How hard could reading out a Bluetooth stream be?

Well, before embarking on the JeeNode/Arduino readout, I decided to first try the built-in Bluetooth of my Mac laptop, which is used by the keyboard and mouse anyway.

I looked at a number of examples out there, but didn’t really like any of ’em – they looked far too complex and elaborate for the task at hand. This looked like a wheel yearning to be re-invented… heh ;)

The trouble is that the protocol is fully packetized, checksummed, etc. The way it was set up, this seems to also allow managing multiple inverters in a solar farm. Nothing I care about, but I can see the value and applicability of such an approach.

So what it comes down to is to send a bunch of hex bytes in just the right order and with just the right checksums, and then pulling out a few values from what comes back by only decoding what is relevant. Fortunately, the Nanode SMA PV Monitor project on GitHub by Stuart Pittaway already did much of this (and a lot more).

I used some templating techniques (in good old C) which are probably worth a separate post, to generate the proper data packets to connect, initialise, login, and ask for specific results. And here’s what I got – after a lot of head-scratching and peering at hex dumps:

    $ make
    cc -o bluesman main.cpp
    ./bluesman
    ha!
    logged in
    daily yield: 2886 Wh @ Sun Jun 29 15:38:03     394803
    total generated power: 75516 W
    AC power: 432 W
    451f: DC voltage = 181.00 V
    451f: DC voltage = 142.62 V
    DC voltage
    251e: DC power = 252 W
    251e: DC power = 177 W
    DC power
    done

The clock was junk at the time, but as you can see there are some nice bits of info in there.

One major inconvenience was that my 11″ MacBook Air tended to crash every once in a while. And in the worst possible way: hard kernel panic -> total reboot needed -> all unsaved data lost. Yikes! Hey Apple, get your stuff solid, will ya – this is awful!

The workaround appears to be to disable wireless and not exit the app while data is coming in. Sounds awfully similar to the kernel panics I can generate by disconnecting an FTDI USB cable or BUB, BTW. Needless to say, these disruptions are extremely irritating while trying to debug new code.

Next step… getting this stuff to work on an ATmega – stay tuned!

  1. I think Apple makes some nice stuff, but my MacBook tends to kernel panic and reboot whenever the batteries of my bluetooth Magic Mouse run low and—I suppose—connection is intermittent..

  2. Glad my original logic/code came in useful!

    Getting it all working on ATmega is not too bad, but I find that the ethercard library causes hangups every couple of days. I’m posting to PV data to several external sites (pvoutput, solarstats.co.uk, etc.)

    This link has some great examples of using cheap bluetooth modules and re-flashing them to make them more useful…

    http://byron76.blogspot.com/2011/09/upgrade-your-bluetooth-module.html

    • Thanks (and thanks for sharing).

      Yes, the EtherCard library can be finicky. It appears to be a problem with the Stash allocations, if they don’t get released they will eventually run out. Which in turn can happen when Ethernet replies don’t come in. I’ve been able to get better results by spacing the Ethernet requests further apart and thus giving the library more time to wait for replies. Another drastic solution I’ve seen is to restart the ATmega periodically, say every few hours.

      Thanks also for the Bleutooth reflashing posts. I had seen those, but didn’t want to go through all the trouble.

  3. “Stay tuned”.. We will! Wouldn’t it be a solution to bypass the bluetooth sending process by connecting a Jeenode directly to the inverter (serial port RS485)- Except that it requires a dedicated interface (sold here for instance: http://www.invertershop.net/inverter-accessories/sma/490/sma-rs485-interface-for-smc-tl-10-and-hv-models?c=122)… Probably not so hard to duplicate?

    • Yes – RS485 would also have been an option. I started out with Bluetooth because the original plan was to avoid adding hardware altogether and read it out through the Mac Mini server located one floor below. Haven’t looked into RS485 much yet, but that interface cost seems a bit over the top indeed.

Comments are closed.