Browse Source

Merge pull request #928 from betacentauri/main

[rpi] Use tx channel hopping and decrease timeout and increase retries
pull/934/head
Lukas Pusch 2 years ago
committed by GitHub
parent
commit
dbb352801e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      tools/rpi/ahoy.yml.example
  2. 29
      tools/rpi/hoymiles/__init__.py
  3. 3
      tools/rpi/hoymiles/__main__.py

1
tools/rpi/ahoy.yml.example

@ -2,6 +2,7 @@
ahoy: ahoy:
interval: 5 interval: 5
transmit_retries: 5
logging: logging:
filename: 'hoymiles.log' filename: 'hoymiles.log'

29
tools/rpi/hoymiles/__init__.py

@ -297,8 +297,8 @@ class InverterPacketFragment:
class HoymilesNRF: class HoymilesNRF:
"""Hoymiles NRF24 Interface""" """Hoymiles NRF24 Interface"""
tx_channel_id = 0 tx_channel_id = 2
tx_channel_list = [40] tx_channel_list = [3,23,40,61,75]
rx_channel_id = 0 rx_channel_id = 0
rx_channel_list = [3,23,40,61,75] rx_channel_list = [3,23,40,61,75]
rx_channel_ack = False rx_channel_ack = False
@ -332,6 +332,12 @@ class HoymilesNRF:
:rtype: bool :rtype: bool
""" """
self.next_tx_channel()
if HOYMILES_TRANSACTION_LOGGING:
c_datetime = datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")
logging.debug(f'{c_datetime} Transmit {len(packet)} bytes channel {self.tx_channel}: {hexify_payload(packet)}')
if not txpower: if not txpower:
txpower = self.txpower txpower = self.txpower
@ -363,13 +369,13 @@ class HoymilesNRF:
""" """
Receive Packets Receive Packets
:param timeout: receive timeout in nanoseconds (default: 12e8) :param timeout: receive timeout in nanoseconds (default: 5e8)
:type timeout: int :type timeout: int
:yields: fragment :yields: fragment
""" """
if not timeout: if not timeout:
timeout=12e8 timeout=5e8
self.radio.setChannel(self.rx_channel) self.radio.setChannel(self.rx_channel)
self.radio.setAutoAck(False) self.radio.setAutoAck(False)
@ -415,7 +421,7 @@ class HoymilesNRF:
self.radio.setChannel(self.rx_channel) self.radio.setChannel(self.rx_channel)
self.radio.startListening() self.radio.startListening()
time.sleep(0.005) time.sleep(0.004)
def next_rx_channel(self): def next_rx_channel(self):
""" """
@ -433,6 +439,15 @@ class HoymilesNRF:
return True return True
return False return False
def next_tx_channel(self):
"""
Select next channel from hop list
"""
self.tx_channel_id = self.tx_channel_id + 1
if self.tx_channel_id >= len(self.tx_channel_list):
self.tx_channel_id = 0
@property @property
def tx_channel(self): def tx_channel(self):
""" """
@ -612,10 +627,6 @@ class InverterTransaction:
packet = self.tx_queue.pop(0) packet = self.tx_queue.pop(0)
if HOYMILES_TRANSACTION_LOGGING:
c_datetime = datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")
logging.debug(f'{c_datetime} Transmit {len(packet)} | {hexify_payload(packet)}')
self.radio.transmit(packet, txpower=self.txpower) self.radio.transmit(packet, txpower=self.txpower)
wait = False wait = False

3
tools/rpi/hoymiles/__main__.py

@ -128,6 +128,7 @@ def main_loop(ahoy_config):
dtu_name = ahoy_config.get('dtu', {}).get('name', 'hoymiles-dtu') dtu_name = ahoy_config.get('dtu', {}).get('name', 'hoymiles-dtu')
sunset.sun_status2mqtt(dtu_ser, dtu_name) sunset.sun_status2mqtt(dtu_ser, dtu_name)
loop_interval = ahoy_config.get('interval', 1) loop_interval = ahoy_config.get('interval', 1)
transmit_retries = ahoy_config.get('transmit_retries', 5)
try: try:
do_init = True do_init = True
@ -144,7 +145,7 @@ def main_loop(ahoy_config):
sys.exit(999) sys.exit(999)
if hoymiles.HOYMILES_DEBUG_LOGGING: if hoymiles.HOYMILES_DEBUG_LOGGING:
logging.info(f'Poll inverter name={inverter["name"]} ser={inverter["serial"]}') logging.info(f'Poll inverter name={inverter["name"]} ser={inverter["serial"]}')
poll_inverter(inverter, dtu_ser, do_init, 3) poll_inverter(inverter, dtu_ser, do_init, transmit_retries)
do_init = False do_init = False
if loop_interval > 0: if loop_interval > 0:

Loading…
Cancel
Save