Skip to content

Commit

Permalink
Merge pull request #26 from devfaz/fix-issue-24-source-interval-data-…
Browse files Browse the repository at this point in the history
…read

SHM2 plugin: only read the last/latest dataframe from the socket
  • Loading branch information
AnotherDaniel authored Jan 4, 2024
2 parents 0fe8c59 + 8e1d5dd commit 2cf1a13
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions plugins/sources/SHM2/shm2.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def execute(config, add_data, dostop):
register_sensor_dict('SENSORS_SHM2', SENSORS_SHM2)

# set up listening socket for SHM2 data packets
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) as sock:
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM | socket.SOCK_NONBLOCK, socket.IPPROTO_UDP) as sock:
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind(("", MCAST_PORT))
try:
Expand All @@ -53,7 +53,16 @@ def execute(config, add_data, dostop):
DeviceInfo['manufacturer'] = "SMA"

while not dostop():
emdata = decode_speedwire(sock.recv(608))
data = ''
while True:
try:
chunk = sock.recv(608)
if chunk:
data = chunk
except BlockingIOError:
break

emdata = decode_speedwire(data)
if (emdata.get("protocol", 0) not in [0x6069] or emdata.get("serial") is None):
continue

Expand Down

0 comments on commit 2cf1a13

Please sign in to comment.