Skip to content

Read data from SMA/Sunny Boy inverter. Export to SQLite database, pvoutput, text, ...

Notifications You must be signed in to change notification settings

ez2X8pk61DHkdztgFT6O/SMA-Bluetooth-reader2

Repository files navigation

Code to extract daily and 5 minute yield from an SMA inverter (Sunny Boy) using Bluetooth. I use it on my Synology DSM412+ NAS to store production data in a local SQLite database and to upload it to ...

Based on:

Main files:

sma_sqlite
Read daily and/or 5 minute data and store it incrementally in an SQLite database. Usage: ./sma_sqlite --MAC 01:02:03:04:05:06 --password 0000 --5minute --daily --sqlite /var/share/pv/data.sql

sma_pvoutput: Upload 5 minute values to pvoutput. Usage: ./sma_pvoutput --MAC 01:02:03:04:05:06 --password 0000 --api_key fad4faa1eeafde17d4446b739e813121ff80b928d --sid 12345

sma_txt:
to do: export as text

Note: sma_pvoutput retrieves the timestamp of the latest uploaded value from the pvoutput site. Next, it determines which records need to be uploaded. pvoutput accepts 'historic' records up to 14 days before the current date. sma_pvoutput uses a limit of 12 (--max_days 12) by default and will not try to upload older production records. Production records are uploaded in batches of --max_batch, 30 by default (maximum for free at pvoutput). This means that when sma_pvoutput has not been excuted for a while, it may take multiple executions to upload the backlogged data. Note that pvoutput limits the amount of uploads to 60/hr. When calling sma_pvoutput once every hour, one can easily keep up with the incoming data (12 records 'created' per hour, 30 per batch).

Files can be compiled separately. For sma_txt, the only requirement is the presence of libbluetooth on the system. Compilation is currently done using a script for each program (e.g. sma_sqlite.sh) and is only tested on the DSM412+.

The SMA protocol consists of 2 parts:

  • Level 2 (L2): the communication protocol that seems to have been developed for modems (PPP encoding, checksums).
  • Level 1 (L1): a wrapper around L2; sends L2 information in packets over Bluetooth (which is a reliable, error-checked protocl).

The source consists of the following parts:

L1.cc / L1.h
The L1Packet class handles sending and receiving of L1 packets

L2.cc / L2.h
The L2Packet class handles checksumming and (un)escaping of an L2 packet and its data.

ProtocolManager.cc / ProtocolManager.h ProtocolManager class handles:

  • Sending/receiving of L2 packets over L1 packets
  • Top-level functionality: connect, login, get data, ...

Using the ProtocolManager, interacting with the SMA inverter looks like:

// Start protocol manager
ProtocolManager *pm = new ProtocolManager();
// Connect
if (pm->Connect((char *) "AB:CD:EF:12:34:56"))
{
EXIT_ERR("Error connection to SMA inverter\n");
}
// Login
if (!pm->Logon((char *) "0000")
{
EXIT_ERR("Error logging in to SMA inverter\n");
}
// Get current totals AND SMA time
YieldInfo yi; // yi.TimeStamp, yi.DailyYield, yi.TotalYield, ...
if (pm->GetYieldInfo(yi))
{
EXIT_ERR("Error getting current totals\n");
}
// Get historic daily yield
HistoricInfo hi; // hi.NoRecords, hi.Records[0...NoRecords].TimeStap, hi.Records[0...NoRecords].Value
if (pm->GetHistoricYield(0, yi.TimeStamp, hi, true) != 0)
{
EXIT_ERR("Error reading daily yield data.\n");
}
// Close session pm->Close();

About

Read data from SMA/Sunny Boy inverter. Export to SQLite database, pvoutput, text, ...

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published