E220 LoRa Receive-Intervall and MycroPython and Arduino Env communication (UnicodeError:)

Home Forums The libraries hosted on the site EByte LoRa e22 UART devices sx1262/sx1268 E220 LoRa Receive-Intervall and MycroPython and Arduino Env communication (UnicodeError:)

Viewing 23 reply threads
  • Author
    Posts
    • #29230
      woto
      Participant

        Hello,
        I use the following to receive data:

        
        while True:
            if lora.available() > 0:
               code, value = lora.receive_message()
               print(ResponseStatusCode.get_description(code))
        
               print(value)
               time.sleep(2)
        

        My question is, what is the time.sleep(2) for?

        I have noticed that if I send data within 2sec, then I get an error message in the Thonny IDE or the data is lost.

        And what happens if several transmitters send data at the same time?

        Kind regards,
        woto

      • #29232
        Renzo Mischianti
        Keymaster

          Hi Woto,
          if you don’t add the sleep time, the processor gets 100% of usage and can freeze.

          If you receive more than one message, the messages are stored in the buffer of E220, and when you read them, you receive the two messages at once.

          Bye Renzo

        • #29268
          woto
          Participant

            Hi Renzo,

            if the transmitter sends within 2sec, then the Micropython programme as receiver is terminated with the error unicode-error at line 636 in lora_e220.py.
            What could be the reason for this? The message is only a few bytes long:
            “Hello World! 1”. The next message is then “Hello World! 2” and so on.

            best regards
            Woto

          • #29272
            Renzo Mischianti
            Keymaster

              Please, paste the complete error stack trace..
              Bye Renzo

            • #29289
              woto
              Participant

                Hi Renzo,
                excuse me for the late answer.

                I will do it today in the evening.

                best regards,
                woto

              • #29291
                woto
                Participant

                  Hi Renzo,
                  I have now found a little time to reproduce the error.

                  When I send a message every second I get the following message in the Thonny editor:

                  Traceback (most recent call last):
                    File "<stdin>", line 127, in <module>
                    File "/lib/LoraWanE220/lora_e220.py", line 636, in receive_message
                  UnicodeError: 

                  Maybe you can help me.

                  best regards
                  Woto

                • #29294
                  Renzo Mischianti
                  Keymaster

                    Hi Woto,
                    It seems that there is a character that’s not encoded correctly, which kind of message do you send?
                    Bye Renzo

                  • #29297
                    woto
                    Participant

                      Hi Renzo,

                      I send with the following command:
                      e220ttl.sendFixedMessage(0, DESTINATION_ADDL, 18, DateTimeStr + " ,Hello, world?" + String (i));

                      The variable DateTimeStr is:

                      DateTime nowTime = MCP7940.now(); // get the current time
                      String DateTimeStr = String(nowTime.year()) + "." + String(nowTime.month()) + "." + String(nowTime.day()) + " " + String(nowTime.hour()) + ":" + String(nowTime.minute()) + ":" + String(nowTime.second());
                      
                      OWN_ADDH = 0x00
                      OWN_ADDL = 0x01
                      i is an integer
                      

                      If I send all 6s, everything is fine. Only if I send every second does this message appear and the programme stops.

                    • #29303
                      Renzo Mischianti
                      Keymaster

                        But you send from Arduino env and receive in MicroPython env?
                        Bye Renzo

                      • #29308
                        woto
                        Participant

                          Hi Renzo,
                          yes, that’s right.

                          best regards
                          Woto

                        • #29309
                          woto
                          Participant

                            The sender is a ATTiny1616 and the receiver is a Rapsberry Pi pico.

                            • This reply was modified 1 year, 8 months ago by woto.
                          • #29351
                            g0730n
                            Participant

                              Do you have FEC on or off?

                            • #29361
                              woto
                              Participant

                                Hi g0730n,
                                I do not know “FEC”. What does it mean?

                              • #29366
                                g0730n
                                Participant

                                  I’ve been experimenting some with data corruption on my setup sending between arduino and pi pico(micropython).

                                  Factors to consider:

                                  1. Timing
                                  2. Forward Error Correction
                                  3. “ReceiveMessageUntil()”, i have experimented with this setting as i was receiving two messages packed into one… eg. “Msg0Msg1”, using this setting seems to help??

                                  If both devices are powered up at same time, and one LoRa begins receiving half way through the senders transmission, it will only receive half the message, hence corrupted data. I have only noticed this happening with FEC off, but more testing needed.

                                  Once I’m able to log into forum here on my computer I will post my code for the working setup I’m putting together.

                                  I am using bare ATMEGA328P chip on arduino side, and pi pico on the other side.

                                • #29363
                                  woto
                                  Participant

                                    ok, I read
                                    https://mischianti.org/ebyte-lora-e32-micropython-exploring-library-2/
                                    now.

                                    I think it is on, because the Default-Value is ON.

                                  • #29415
                                    woto
                                    Participant

                                      Hi g0730n,

                                      thanks for answer.
                                      I will test the function “ReceiveMessageUntil()”. Maybe it could help me.

                                    • #29468
                                      Renzo Mischianti
                                      Keymaster

                                        I also pin this discussion, and if I find some time, I retrieve all devices and do some tests.
                                        Give me feedback on your test.
                                        Thanks, Renzo

                                      • #29612
                                        woto
                                        Participant

                                          Hello,
                                          I would now like to switch off the FEC in the Python programm.
                                          How can I do this?

                                          Thanks Woto

                                        • #29615
                                          woto
                                          Participant

                                            Hello,
                                            I now have data issued to me.
                                            In lora_e220.py, I insert on line 636 (before data = data.decode(‘utf-8’):
                                            print (data)

                                            If I receive all 4s, I get the following output:
                                            b’0212024.2.2 15:14:25 5cm’
                                            After 4s the next output:
                                            b’0212024.2.2 15:14:29 19cm’

                                            If I receive every second, Data looks like this:
                                            b’0212024.2.2 16:59:58 7cm\xf00212024.2.2 16:59:59 19cm’

                                            After “7cm” it says \xf0. What does that mean?

                                            • This reply was modified 1 year, 8 months ago by woto.
                                            • This reply was modified 1 year, 8 months ago by woto.
                                          • #29619
                                            woto
                                            Participant

                                              Hello,

                                              When I enter the following in the Thonny IDE, I get an error message:

                                              >>> b'\xf0'.decode()
                                              Traceback (most recent call last):
                                                File "<stdin>", line 1, in <module>
                                              UnicodeError: 
                                              >>> 

                                              I think the problem is the character \xf0.
                                              This does not seem to be a Unicode character. Unfortunately, µPython does not allow you to specify a second parameter in the decode() function, e.g. data.decode('UTF-8','ignore').

                                              This does not work.
                                              But how can this be solved?

                                              • This reply was modified 1 year, 8 months ago by woto.
                                            • #29622
                                              Renzo Mischianti
                                              Keymaster

                                                Hi woto,
                                                I must do some check, but someone uses this approach to clean the str

                                                
                                                x.encode('utf-8','ignore').decode("utf-8")
                                                

                                                But I must check It.
                                                Bye Renzo

                                              • #29623
                                                woto
                                                Participant

                                                  Hi Renzo,
                                                  I tried it, but it does not work. I get the following error in der Thonny-IDE:

                                                  >>> b'0212024.2.2  15:26:34  3cm\xf60212024.2.2  15:26:35  22cm'.encode('utf-8','ignore').decode("utf-8")
                                                  Traceback (most recent call last):
                                                    File "<stdin>", line 1, in <module>
                                                  AttributeError: 'bytes' object has no attribute 'encode'
                                                  >>>
                                                • #29624
                                                  woto
                                                  Participant

                                                    Hi renzo,
                                                    I think I have a solution for myself, maybe for others too.
                                                    I have created a new static method in the class LoraE220:

                                                    @staticmethod
                                                     def _cleanData(_data):
                                                         data = bytes(_data)
                                                            
                                                         ret_values = []
                                                         ret_arr = bytearray(ret_values)
                                                            
                                                         for i in range(len(_data)):
                                                             if _data[i] <= 127 :
                                                                 ret_arr.append(_data[i])
                                                         return ret_arr

                                                    This methode is called before the decode function:

                                                    str_ret = LoRaE220._cleanData(data)
                                                    
                                                    data = str_ret.decode('utf-8')
                                                    msg = data

                                                    Now the decoding function works and if I define a separator for the sender, I can separate the messages from each other.

                                                    • This reply was modified 1 year, 8 months ago by woto.
                                                    • #30876
                                                      g0730n
                                                      Participant

                                                        I will keep this in mind.

                                                    • #29644
                                                      Renzo Mischianti
                                                      Keymaster

                                                        Hi Woto,
                                                        thanks. It’s very interesting and helpful.
                                                        I’m going to examine the situation, but with your help, I think It will become simpler.
                                                        Thanks again, Renzo.

                                                    Viewing 23 reply threads
                                                    • You must be logged in to reply to this topic.
                                                    Exit mobile version