Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Development
  3. Send a string as a value

Send a string as a value

Scheduled Pinned Locked Moved Development
8 Posts 5 Posters 3.5k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Meister_Petz
    wrote on last edited by
    #1

    Hi,

    is there a way to send a string as the value of a message:

    I would like to do that:

    String test = String(sRead1) + "-" + String(sRead2)+ "-" + String(sRead3); // result: "20.5-1011-2.5"
    gw.send(msg1.set(test));
    

    I did not find a way to get "test" transformed (char, string,...) to get it sent. But interestingly this works:

    gw.send(msg1.set("20.5-1011-2.5"));
    

    so I think there should be a way to get "test" transformed in a format which can be sent.

    Anyone any ideas?

    Many Thanks!

    tekkaT 1 Reply Last reply
    0
    • hekH Offline
      hekH Offline
      hek
      Admin
      wrote on last edited by
      #2

      You should avoid using String on embedded systems (thus we do not have any send for it).

      Have a look at strcpy.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Meister_Petz
        wrote on last edited by
        #3

        do you have an example? Many Thanks!

        1 Reply Last reply
        0
        • M Meister_Petz

          Hi,

          is there a way to send a string as the value of a message:

          I would like to do that:

          String test = String(sRead1) + "-" + String(sRead2)+ "-" + String(sRead3); // result: "20.5-1011-2.5"
          gw.send(msg1.set(test));
          

          I did not find a way to get "test" transformed (char, string,...) to get it sent. But interestingly this works:

          gw.send(msg1.set("20.5-1011-2.5"));
          

          so I think there should be a way to get "test" transformed in a format which can be sent.

          Anyone any ideas?

          Many Thanks!

          tekkaT Offline
          tekkaT Offline
          tekka
          Admin
          wrote on last edited by
          #4

          @Meister_Petz you can always do something like this:

          char Output[13];
          String OutStr = String(sRead1) + "-" + String(sRead2) + "-" + String(sRead3);
          OutStr.toCharArray(Output,13);
          gw.send(msg.set(Output));
          

          but as @hek pointed out, try avoiding it where possible...

          M 1 Reply Last reply
          0
          • tekkaT tekka

            @Meister_Petz you can always do something like this:

            char Output[13];
            String OutStr = String(sRead1) + "-" + String(sRead2) + "-" + String(sRead3);
            OutStr.toCharArray(Output,13);
            gw.send(msg.set(Output));
            

            but as @hek pointed out, try avoiding it where possible...

            M Offline
            M Offline
            Meister_Petz
            wrote on last edited by
            #5

            @tekka
            Many Thanks!
            I'd like to avoid it, but I'm not a developer and so my programing skills are limited ;-)

            1 Reply Last reply
            0
            • fetsF Offline
              fetsF Offline
              fets
              wrote on last edited by
              #6

              @Meister_Petz, you could simply write :

              String OutStr = String(sRead1) + "-" + String(sRead2) + "-" + String(sRead3);
              gw.send(msg.set(OutStr.c_str()));
              
              1 Reply Last reply
              0
              • AWIA Offline
                AWIA Offline
                AWI
                Hero Member
                wrote on last edited by
                #7

                Or just use the character arrays with snprintf

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  Meister_Petz
                  wrote on last edited by
                  #8

                  many thanks! I know it's easy for you - unfortunately not for me. That's why I'm here. ;-)

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  13

                  Online

                  11.7k

                  Users

                  11.2k

                  Topics

                  113.0k

                  Posts


                  Copyright 2019 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • MySensors
                  • OpenHardware.io
                  • Categories
                  • Recent
                  • Tags
                  • Popular