Skip to main content

Renogy Bluetooth SDK for Python

Project description

RenogyBT for Python SDK

RenogyBT is a Python SDK designed for Modbus communication with Renogy products. This project provides functionality to communicate with Renogy devices via Bluetooth.

Installation

Ensure your Python version is 3.6 or above. You can install the required dependencies using the following command:

pip install renogy-modbus-lib-python

Usage

Initialization

First, initialize the EnhancedModbusClient class to scan and connect to devices:

from modbus_bt_pkg.src.renogy_lib_python import EnhancedModbusClient

async def main():
    client = EnhancedModbusClient(slave_address=0xFF)
    devices = await client.scan_devices()
    # Select and connect to a device
    success = await client.connect(selected_device['address'])

Data Retrieval

Once connected, you can use the following methods to retrieve battery raw data and status information:

response = await client.get_hole_original_data()

status = await client.get_status()

Example

import asyncio
import sys
import os

from renogy_lib_python.modbus_comm import EnhancedModbusClient
async def main():
    client = EnhancedModbusClient(slave_address=0xFF) 
    connected = False
    choices = ["battery","controller"]
    try:
        # start scanning for devices
        devices = await client.scan_devices()  
        if len(devices):
            print("\nList of available devices:")
        for i, dev in enumerate(devices, 1):
            print(f"{i}. {dev['name']} ({dev['address']})")
            
        if devices:
            # select a device to connect 
            choice = int(input("\nPlease select the device type to connect (1 battery- 2 controller):"))
            if 1 <= choice <= len(choices):
                selected_type = choices[choice - 1]
            else:
                print("Input out of range, please try again")
                return
            while True:         
                try:
                    choice = int(input("\nPlease enter the device number to connect (1-{}): ".format(len(devices))))
                    if 1 <= choice <= len(devices):
                        selected_device = devices[choice - 1]
                        break
                    else:
                        print("Input out of range, please try again")
                except ValueError:
                    print("Invalid input, please enter a number")
            
            success = await client.connect(selected_device['address'])
            connected = success
            print(f"\nconnect status: {'success' if success else 'failture'}")
            
            if success:
                while True:
                    # send read command: get data
                    print("get data")
                    response = await client.get_hole_original_data(DeviceType=selected_type)
                    print(response)

                    # send write command: set data
                    print("get status")
                    response = await client.get_status(DeviceType=selected_type)
                    print(response)
                    choice = int(input("continue or exit? 1.continue 2.exit\n"))
                    if choice==1:
                        continue
                    else:
                        break
    except Exception as e:
        print(f"catch exception:{str(e)}")
    finally:
            if connected:
                await client.disconnect()
    
if __name__ == "__main__":
    asyncio.run(main())

Features

  • Device Scanning : Use the scan_devices method to scan nearby Bluetooth devices.
  • Device Connection : Use the connect method to connect to the selected device.
  • Data Retrieval : Use the get_hole_original_data and get_status methods to obtain raw data and status information from the device.

License

This project is licensed under the Renogy License. For more details, please refer to the https://www.renogy.com.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

renogy_modbus_lib_python-0.1.8.tar.gz (13.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

renogy_modbus_lib_python-0.1.8-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file renogy_modbus_lib_python-0.1.8.tar.gz.

File metadata

File hashes

Hashes for renogy_modbus_lib_python-0.1.8.tar.gz
Algorithm Hash digest
SHA256 7a9edfed809fdf577580fbeec879f00c0922e3b04f9278aee9bda3908941c56c
MD5 6e57b05d240cf899358a39adb64b5bec
BLAKE2b-256 3e3b9a47a1790997fbf7a116fd7e6ea5ff49f83d66f04f3c42420359e5472368

See more details on using hashes here.

File details

Details for the file renogy_modbus_lib_python-0.1.8-py3-none-any.whl.

File metadata

File hashes

Hashes for renogy_modbus_lib_python-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 d6a385e12bf29a1a4105f74452f5dd313582b807d481ee7ea7be053987fd998b
MD5 6cdfa55108eaf36b9d03316c179d502d
BLAKE2b-256 f4c3343579734247924e3afa5c2f8a708ff1b61e40b88b362695e6f8eabe29ad

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page