B4J Library wmSMA - read data from an SMA Sunny Boy inverter [B4X][Class]

Purpose:
To connect to and read data (such as the current solar power production) from an SMA Sunny Boy inverter. The Sunny Boy must have been added to your LAN or WLAN - see https://www.sma-sunny.com/en/servic...th-built-in-wifi-to-a-local-wireless-network/ for instructions.

Code ported from Python to B4X: https://github.com/Dymerz/SMA-SunnyBoy#
B4Xlib and demo project attached.

Public methods (all of them contain IDE help and examples):
- Initialize: initialises the class
- B4XLibInfo: only document dependencies, additional jars, etc
- Connect: establishes a new connection
- Disconnect: logs out and clears the connection
- IsConnected: returns whether or not we are connected to the Sunny Boy
- GetValue: fetches one of the DATA... values (see below)
- GetUnit: fetches the unit of measurement for one of the DATA... values
- GetAllValues: fetches ALL the DATA... values
- GetLogger: fetches the solar production within a DateTime range

Properties:
SerialNumber: returns the Sunny Boy's serial number (after successfully having used one of the Get... methods)

DATA... values:
- device_error
- device_state
- device_warning
- ethernet_counter_status
- ethernet_dns
- ethernet_gateway
- ethernet_ip
- ethernet_netmask
- ethernet_status
- injection_time
- power_ab
- power_amp
- power_b
- power_current
- power_total
- productivity_day
- productivity_total
- server_dns
- server_gatewy
- server_ip
- server_netmask
- service_time
- tide_ab
- voltage_ab
- wlan_dns
- wlan_gateway
- wlan_ip
- wlan_netmask
- wlan_scan_status
- wlan_status
- wlan_strength

Library dependencies (all are internal libraries):
JavaObject, [j]OkHttpUtils2, Json

Notes:
- IMPORTANT FOR B4J NON-UI APPS, AS PER https://www.b4x.com/android/forum/threads/resumablesub-dont-work.89719 : see 'StartMessageLoop' and 'StopMessageLoop' in the demo program.
- Tested with B4A and B4J, assumed to be B4I-compatible as well (but not tested or even tried).

MIT License for the original Python code:
Copyright (c) 2020 Urbain Corentin

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
 

Attachments

  • wmSMA.b4xlib
    6 KB · Views: 41
  • wmSMAdemo.zip
    7.3 KB · Views: 49
Top