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 4.0k 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!

    T 1 Reply Last reply
    0
    • H Offline
      H 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!

          T Offline
          T 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
          • T 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
            • F Offline
              F 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
              • A Offline
                A 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

                  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
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  15

                  Online

                  12.0k

                  Users

                  11.2k

                  Topics

                  113.4k

                  Posts


                  Copyright 2025 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