OSError: [Errno 90] EMSGSIZE
-
Hi everyone, I am working on a project.
When I send a bytestring to LoRa I get a error because my bytestring is to long.Does someone know how I can resolve this problem?
import pycom import machine import time from machine import Pin import socket from network import LoRa import binascii import array from machine import PWM ############### LoRa Connectie ############### lora = LoRa(mode=LoRa.LORAWAN, region=LoRa.EU868) app_eui = binascii.unhexlify('70B3D57ED003B935') app_key = binascii.unhexlify('D0258B34705B17B2DD2C87CA07CA5D68') lora.join(activation=LoRa.OTAA, auth=(app_eui, app_key), timeout=0) # wait until the module has joined the network while not lora.has_joined(): time.sleep(2.5) print('Not joined yet...') print('Network joined!') ############### Weightsensor ############### def main(): while True: adc = machine.ADC() # create an ADC object apin = adc.channel(pin='P16') # create an analog pin on P16 val = apin() low = apin() # read an analog value high = apin() # read an analog value if val < 20: print(val) print("Weight is good") binaryString = bin(low) print(binaryString) time.sleep(2.5) if val > 20: print(val) print("Weight is to high") binaryString = bin(high) print(binaryString) time.sleep(2.5) # 50% duty cycle at 38kHz. pwm = PWM(3, frequency=78000) # use PWM timer 0, with a frequency of 5KHz # create pwm channel on pin P12 with a duty cycle of 50% pwm_c = pwm.channel(0, pin='P20', duty_cycle=1.0) pwm_c.duty_cycle(0.3) # change the duty cycle to 30% s = socket.socket(socket.AF_LORA, socket.SOCK_RAW) s.setsockopt(socket.SOL_LORA, socket.SO_DR, 5) s.setblocking(False) s.send(bytes(high)) if __name__ == "__main__": main() -
@Zino-Henderickx The pyaload size of a Lora message depends on the spreading factor, and ranges e.g. for EU868 between 51 and 222 bytes, for US915 between 11 and 222 bytes . How long is the byte strings you attempt to send, and which spreading factor are you using?
-
@Zino-Henderickx you should probably use
ustructto pack your value rather thanbytesdirectly on a float. Don’t have a device at hand to test, but I suspect the latter sends a text version of the float, which can be quite long.It shouldn’t be a problem at DR5 though. Log the size and contents of your payload, it should be informative.
-
@Zino-Henderickx Just spotted the reason:
the line:
s.send(bytes(high))
sends bytes(high), which is a bytearray with the number of bytes, which is given by the value of high. So if high is 1000, it will create a 1000 bytes long object.
You may use str(high).endcode(), or use struct.pack() as @jcaron mentioned. -
@jcaron Yes I will try that. Thanks for the advice!
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