From 9acd8c59cd662d329e2aa6431f43e8939eae22b1 Mon Sep 17 00:00:00 2001 From: Betacentauri Date: Sat, 6 May 2023 12:03:52 +0200 Subject: [PATCH 1/2] [rpi] Use tx channel hopping and decrease timeout Using only channel 40 for transmits led in some cases to no responses. --- tools/rpi/hoymiles/__init__.py | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/tools/rpi/hoymiles/__init__.py b/tools/rpi/hoymiles/__init__.py index 210bed65..688e271d 100644 --- a/tools/rpi/hoymiles/__init__.py +++ b/tools/rpi/hoymiles/__init__.py @@ -297,8 +297,8 @@ class InverterPacketFragment: class HoymilesNRF: """Hoymiles NRF24 Interface""" - tx_channel_id = 0 - tx_channel_list = [40] + tx_channel_id = 2 + tx_channel_list = [3,23,40,61,75] rx_channel_id = 0 rx_channel_list = [3,23,40,61,75] rx_channel_ack = False @@ -332,6 +332,12 @@ class HoymilesNRF: :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: txpower = self.txpower @@ -363,13 +369,13 @@ class HoymilesNRF: """ Receive Packets - :param timeout: receive timeout in nanoseconds (default: 12e8) + :param timeout: receive timeout in nanoseconds (default: 5e8) :type timeout: int :yields: fragment """ if not timeout: - timeout=12e8 + timeout=5e8 self.radio.setChannel(self.rx_channel) self.radio.setAutoAck(False) @@ -415,7 +421,7 @@ class HoymilesNRF: self.radio.setChannel(self.rx_channel) self.radio.startListening() - time.sleep(0.005) + time.sleep(0.004) def next_rx_channel(self): """ @@ -433,6 +439,15 @@ class HoymilesNRF: return True 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 def tx_channel(self): """ @@ -612,10 +627,6 @@ class InverterTransaction: 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) wait = False From 72d044bcf647a3dab8fb43742449f7ad3bcc6c44 Mon Sep 17 00:00:00 2001 From: Betacentauri Date: Sat, 6 May 2023 12:05:21 +0200 Subject: [PATCH 2/2] [rpi] Add config for transmit retries and increase to 5 so that all channels are tried once --- tools/rpi/ahoy.yml.example | 1 + tools/rpi/hoymiles/__main__.py | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/rpi/ahoy.yml.example b/tools/rpi/ahoy.yml.example index 6efb28ae..00d52511 100644 --- a/tools/rpi/ahoy.yml.example +++ b/tools/rpi/ahoy.yml.example @@ -2,6 +2,7 @@ ahoy: interval: 5 + transmit_retries: 5 logging: filename: 'hoymiles.log' diff --git a/tools/rpi/hoymiles/__main__.py b/tools/rpi/hoymiles/__main__.py index cb5ecf2b..3589de1a 100644 --- a/tools/rpi/hoymiles/__main__.py +++ b/tools/rpi/hoymiles/__main__.py @@ -128,6 +128,7 @@ def main_loop(ahoy_config): dtu_name = ahoy_config.get('dtu', {}).get('name', 'hoymiles-dtu') sunset.sun_status2mqtt(dtu_ser, dtu_name) loop_interval = ahoy_config.get('interval', 1) + transmit_retries = ahoy_config.get('transmit_retries', 5) try: do_init = True @@ -144,7 +145,7 @@ def main_loop(ahoy_config): sys.exit(999) if hoymiles.HOYMILES_DEBUG_LOGGING: 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 if loop_interval > 0: