Code Monkey home page Code Monkey logo

libspeedwire's Introduction

speedwire-lib

Code implementing a SMA Speedwire(TM) access library. It implements a full parser for the sma header and the emeter datagram structure, including obis filtering. In addition, it implements some parsing functionality for inverter query and response datagrams.

The overall speedwire packet format is:

  • The packets start with a 4 byte SMA Signature containing the ascii encoded string "SMA\0".
  • After the signature follows a sequence of tag packets, where each tag packet starts with a tag header followed a sequence of tag payload bytes.
  • The last tag packet is an end-of-data packet with 0 bytes of tag payload and a tag id of 0.

Emeter and inverter speedwire packets follow a standard format consisting of a tag0 packet holding the group id, a data2 packet holding the payload and an end-of-data packet.

+---------------------------------------------------------------------------------+
+      4 Bytes   | SMA Signature "SMA\0"                                          +
+---------------------------------------------------------------------------------+
+  Tag Packet 0                                                                   +
+      2 Bytes   | Tag0 Length            | 4                                     +
+      2 Bytes   | Tag0 ID                | 0x02a0                                +
+      4 Bytes   | Group ID               | 0x00000001                            +
+---------------------------------------------------------------------------------+
+  Tag Packet 1                                                                   +
+      2 Bytes   | Data2 Tag Length       | # of bytes following Data2 Tag ID     +
+      2 Bytes   | Data2 Tag ID           | 0x0010                                +
+      2 Bytes   | Protocol ID            | always encoded for Data2 tag packets  +
+        Bytes   | Data                   | Emeter or inverter data               +
+---------------------------------------------------------------------------------+
+  Tag Packet 2                                                                   +
+      2 Bytes   | End-of-Data Tag Length | 0x0000                                +
+      2 Bytes   | End-of-Data Tag ID     | 0x0000                                +
+---------------------------------------------------------------------------------+

The data part for emeter packets is documented in the official SMA-Emeter(TM) protocol specification:

https://developer.sma.de/fileadmin/content/global/Partner/Documents/SMA_Labs/EMETER-Protokoll-TI-en-10.pdf

The data part for inverter packets is not officially documented. The protocol is based on register IDs that can be read from or written to. libspeedwire provides an implementation for reading register information, writing register information is not implemented. SMA recommends to rely on the documented Modbus API.

+---------------------------------------------------------------------------------+
+  Destination Address                                                            +
+      2 Bytes   | Susy ID                | Destination devices susy id           +
+      4 Bytes   | Serial Number          | Destination devices serial number     +
+      2 Bytes   | Control                | unknown semantics                     +
+---------------------------------------------------------------------------------+
+  Source Address                                                                 +
+      2 Bytes   | Susy ID                | Source devices susy id                +
+      4 Bytes   | Serial Number          | Source devices serial number          +
+      2 Bytes   | Control                | unknown semantics                     +
+---------------------------------------------------------------------------------+
+  Inverter Protocol                                                              +
+      2 Bytes   | Error Code             | 0x0000 if no error                    +
+      2 Bytes   | Fragment Counter       | Count down counter for # of packets   +
+      2 Bytes   | Packet ID              | Unique packet identification          +
+      4 Bytes   | Command ID             | see enum Command                      +
+      4 Bytes   | First Register ID      | First Register ID                     +
+      4 Bytes   | Last Register ID       | Last Register ID                      +
+---------------------------------------------------------------------------------+
+  Register Data                                                                  +
+      n Bytes   | Register Data #0 First | see class SpeedwireRawData            +
+      n Bytes   | ...                    |                                       +
+      n Bytes   | Register Data #n Last  |                                       +
+---------------------------------------------------------------------------------+

Useful examples on how to use this library can be found in the accompanying repositories:

The implementation comes with Doxygen comments. Thus you can use Doxygen to create the documentation.

The software comes as is. No warrantees whatsoever are given and no responsibility is assumed in case of failure or damage being caused to your equipment.

The simplest way to build this library together with your code is to checkout this library into a separate folder and use unix symbolic links (ln -s ...) or ntfs junctions (mklink /J ...) to integrate it as a sub-folder within your projects folder.

For example, if you are developing on a Windows host and your projects reside in C:\workspaces:

cd C:\workspaces
mkdir libspeedwire
git clone https://github.com/RalfOGit/libspeedwire
cd ..\YOUR_PROJECT_FOLDER
mklink /J libspeedwire ..\libspeedwire
Now you can start Visual Studio
And in Visual Studio open folder YOUR_PROJECT_FOLDER

And if you are developing on a Linux host and your projects reside in /home/YOU/workspaces:

cd /home/YOU/workspaces
mkdir libspeedwire
git clone https://github.com/RalfOGit/libspeedwire
cd ../YOUR_PROJECT_FOLDER
ln -s ../libspeedwire
Now you can start VSCode
And in VSCode open folder YOUR_PROJECT_FOLDER

Further information regarding the SMA-Inverter(TM) datagrams can be found in various places on the internet:

https://github.com/SBFspot/SBFspot
https://github.com/Rincewind76/SMAInverter
https://github.com/ardexa/sma-rs485-inverters
https://github.com/dgibson/python-smadata2/blob/master/doc/protocol.txt
https://github.com/peterbarker/python-smadata2

The code has been tested against the following environment:

OS: CentOS 8(TM), IDE: VSCode (TM)
OS: Windows 10(TM), IDE: Visual Studio Community Edition 2019 (TM)

You will need to open your local firewall for udp packets on port 9522.

libspeedwire's People

Contributors

mincequi avatar ralfogit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

libspeedwire's Issues

Question: speedwire vs energy meter vs inverter protocol

Hi there,
i adapted once your libspeedwire for integration with SBFspot.
Just our of curiosity:
how do all these protocols relate together?
Is speedwire used by both: energy meter AND inverter?
Is production data of an inverter also multicasted (like the energy meter does)?

Thanks a lot already! :)

Support for Home Manager data stream

In an effort to make sense of the SMA Sunny Home Manager 2.0's data stream towards the SMA EV Charger (and trying to convince it to modulate its output accordingly) I did some data logging and spelunking in https://github.com/danieltwagner/speedwire-parse

Now that that's complete I realize that it's largely overlapping with what you already determined for the energy meter, though there are some additional messages and I haven't determined any addressing, as seems to be referenced in your repo. I do see a sender ID (maybe susy id?) and serial number but nothing to determine the recipient... unless I'm missing something.

Anyhow, long story short, would you accept a PR that adds some relevant constants? I haven't yet looked closely at what would be required but figure it can't be too bad based on what I'm seeing here

const ObisData ObisData::PositiveActivePowerTotal (0, 1, 4, 0, MeasurementType::EmeterPositiveActivePower(), Wire::TOTAL);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.