Object with buffer protocol required
-
Hi, I was trying to send ASCII txt from Lopy4 to gateway where I now tried to send the ascii txt in packets but based on line by line so that I can easily reconstruct the ascii txt on the receive node/gateway.
I used the code below;
from network import LoRa import socket import ubinascii import struct from time import sleep LORA_FREQUENCY = 915000000 LORA_NODE_DR = 3 lora = LoRa(mode=LoRa.LORAWAN, region=LoRa.AU915) dev_addr = struct.unpack(">l", ubinascii.unhexlify('0024f28c'))[0] nwk_swkey = ubinascii.unhexlify('fce40d8e91545d50e2f914022f66a0cb') app_swkey = ubinascii.unhexlify('c003d97951bf56d7e1ec8d8f0f9d2cee') lora.join(activation=LoRa.ABP, auth=(dev_addr, nwk_swkey, app_swkey)) s.setsockopt(socket.SOL_LORA, socket.SO_DR, LORA_NODE_DR) s = socket.socket(socket.AF_LORA, socket.SOCK_RAW) s.setblocking(True) f = open("SIGN.txt", "rb") n = 30 '''characters_per_packet''' def split(s, n): if len(s) <= n: return [s] else: return split(s[:n], n) + split(s[n:], n) if __name__ == "__main__": while True: line = f.readline() if not line: print("Finished Printing") break send_packet = split(line, n) print(send_packet) s.send(send_packet)But upon execution, I came with the error saying 'Object with buffer protocol required' (error nature attached). I tried to browse for how to build buffer protocol for this program but could not figure out. Any help would be appreciated.
Thank you in advance

-
@phusy012 You supplied a list to send, but send requires a bytearray, bytes-object or string. The function split and the logic you are calling seems not to match. If you want split to return a list of smaller chunks, the you must have send to iterate over these chunks, like:
send_packet = split(line, n) print(send_packet) for packet in send_packet: s.send(packet) -
@robert-hh Thank you so much. Thank you for correcting me. Yes now I am able to send successfully.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login