Is it possible to send an object with LoRa E32 device?

Home Forums The libraries hosted on the site EByte LoRa e32 UART devices sx1262/sx1268 Is it possible to send an object with LoRa E32 device?

Viewing 9 reply threads
  • Author
    Posts
    • #6400
      ludophot
      Participant

        Hello,

        in your tutorial, you indicate that we can send as desired: Json and structure.
        is it possible to send an object?

        thank you

      • #6404
        Renzo Mischianti
        Keymaster

          Hi Ludophot,

          you can send a structure that in C is the equivalent of an object.

          For example

          
              struct Message {
                  char type[5] = "TEMP";
                  char message[8] = "Kitchen";
                  byte temperature[4];
              } message;
           
              *(float*)(message.temperature) = 19.2;
           
              ResponseStatus rs = e32ttl.sendFixedMessage(0,3,4,&message, sizeof(Message));
              Serial.println(rs.getResponseDescription());
          
          

          I think this is what you need.

          you can find more information in this article, with a complete sender sketch and receiver.

          Ebyte LoRa E32 device for Arduino, esp32 or esp8266: power saving and sending structured data Part 5

          pay attention to the receive of part of the strucure, very usefully to manage different type of object.

           

          Bye Renzo

        • #6418
          ludophot
          Participant

            thank you

            ok

            <span lang="en">I have two questions about structures:
            
            the first one.
            
            I create a structure</span>

            <span class="hljs-class"><span class="hljs-keyword">struct</span> <span class="hljs-title">Badge</span> {</span> char *Name; int octet1; int octet2; int octet3};

             

            <span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">main</span><span class="hljs-params">(<span class="hljs-keyword">void</span>)</span> </span>{

            struct Badge badge_Ref("",<span class="hljs-class">0x00,0x00,0x00);</span>

            <span class="hljs-class"><span class="hljs-keyword">struct</span> <span class="hljs-title">Badge</span> badge1("equipe1",0x00,0x00,0x00);</span>

            <span class="hljs-class"><span class="hljs-keyword">struct</span> <span class="hljs-title">Badge</span> badge2("equipe2",0x00,0x00,0x00);</span>

            <span class="hljs-class"><span class="hljs-keyword">struct</span> <span class="hljs-title">Badge</span> badge3("equipe3",0x00,0x00,0x00);</span>

            <span class="hljs-keyword">return</span> <span class="hljs-number">0</span>;

            }

             

            <span lang="en">then I create a pointer array :
            
            Badge* p_Badge[NOMBREDEBADGEMAX] = {NULL};
            void tableauPointeurBadge()
            {
            p_Badge[0] = &badge1;
            p_Badge[1] = &badge2;
            p_Badge[2] = &badge3;
            
            }</span>

            I would like to automate the array with a loop, to do something like that :

            <span lang=”en”>Badge* p_Badge[NOMBREDEBADGEMAX] = {NULL};
            void tableauPointeurBadge()
            {
            </span>

            for(int i=0 ;i<(badge1.getNbOccurences()-1); i++)

            <span lang=”en”>{</span>

            <span lang=”en”></span><span lang=”en”>p_Badge[i] = &badge[i];

            }</span>

            I hope to be explicit.

             

            the second question. by imagining having a hundred transmitters that transmit structures to a single receiver. isn’t there a risk of data loss I imagine that this is where the TYPE of structure should be used

             

            thank you

             

          • #6419
            ludophot
            Participant

              I repeat my question ……

              I have two questions about structures:
              the first one.
              I create a structure

              struct Badge {
              char *Name;
              int octet1;
              int octet2;
              int octet3;
              };

              Badge badge1("",0x7B, 0x1B, 0x5B);
              Badge badge2("",0x7B, 0x1D, 0x5C);
              Badge badge3("",0x7B, 0x1C, 0x5B);
              Badge badge4("",0x7C, 0x1B, 0x5B);
              Badge badge5("",0x7D, 0x1B, 0x5B);
              Badge badge6("",0x7E, 0x1B, 0x5B);

              then I create a pointer array :

              Badge* p_Badge[NOMBREDEBADGEMAX] = {NULL};

              void tableauPointeurBadge()
              {
              p_Badge[1] = &badge1;
              p_Badge[2] = &badge2;
              p_Badge[3] = &badge3;
              }

              I would like to automate the array with a loop, to do something like that :

              Badge* p_Badge[NOMBREDEBADGEMAX] = {NULL};

              void tableauPointeurBadge()
              {
              for(int i;i<nb_occurrence;i++)
              {p_Badge[1] = &badge[i];}

              hope to be explicit.

              the second question. by imagining having a hundred transmitters that transmit structures to a single receiver. isn’t there a risk of data loss I imagine that this is where the TYPE of structure should be used

              thank you

            • #6420
              ludophot
              Participant

                here is the code of my structure on the transmitter side

                struct Badge_Transmition{
                const char *type=NULL;
                String *message = NULL;
                };

                struct Badge_Transmition E_Badge;
                E_Badge.type ="TECH_LAVAGE"; //definition du type
                E_Badge.message =&numeroBadge;

                ResponseStatus rs = e32ttl100.sendFixedMessage(0, 0, 0x17,&E_Badge,sizeof(Badge_Transmition));

                here is the code of my structure on the receiver side

                //structure
                struct Badge_Transmition{
                char type[20];
                String message;
                };

                if (e32ttl.available() > 1){
                char type[20]; // first part of structure
                ResponseContainer rs = e32ttl.receiveInitialMessage(sizeof(type));
                String typeStr = rs.data;

                Serial.println(typeStr);
                if (typeStr=="TECH_LAVAGE"){
                ResponseStructContainer rsc = e32ttl.receiveMessage(sizeof(Badge_Transmition));
                struct Badge_Transmition R_Badge = *(Badge_Transmition*) rsc.data;

                you look good ?

              • #6424
                Renzo Mischianti
                Keymaster

                  Hi Ludopoth,

                  first you can’t create a structure with pointer

                  
                  struct Badge_Transmition{
                  const char *type=NULL;
                  String *message = NULL;
                  };
                  

                  but size must be fixed

                  
                  struct Badge_Transmition{
                  char[10] type;
                  char[20] message;
                  };
                  

                  the pointer size is about 2byte, but the content is in another area.

                  The receive device must have the same fixed size structure.

                  The rest of the code seems correct.

                  Give me a feedback Bye Renzo.

                • #6432
                  ludophot
                  Participant

                    thank you  ! 🙂

                    for the subject #6419  for the subject. Do you have an idea ?

                  • #6440
                    Renzo Mischianti
                    Keymaster

                      Hi Ludophot,

                      yes, I think you can refer this post to create the array of element/structure

                      More than one pcf8574 expander

                       

                      I think It’s quite difficult to lost packet, because E32 have 512byte of buffer and the max packet size is 58byte, and when you read the buffer you remove the messages from that, so you can grab 512/58 >= 8 messages before read the buffer.

                      I’m quite sure that you read the message in less than millisecs.

                      Bye Renzo

                    • #6446
                      ludophot
                      Participant

                        hello ,

                        I can’t send / receive a String in a structure. I don’t have to understand everything in my opinion. do you have to transform the string into an array?

                        Can you give me an example with a structure containing a String?

                        thank you

                      • #6458
                        Renzo Mischianti
                        Keymaster

                          Hi Ludophot,

                          String isn’t a fixed size variable, so you can’t predeterminate the size of the sctrucure, try to copy String to fixed size char

                          char msg[10];
                          string mystr = "hello";
                          
                          strcpy(msg, mystr.c_str());

                           

                          Give me a feedback..

                           

                          Bye Renzo

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