Browse Source

[rpi] Use tx channel hopping and decrease timeout

Using only channel 40 for transmits led in some cases to no responses.
pull/928/head
Betacentauri 2 years ago
parent
commit
9acd8c59cd
  1. 29
      tools/rpi/hoymiles/__init__.py

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

Loading…
Cancel
Save