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. Help to send string as payload

Help to send string as payload

Scheduled Pinned Locked Moved Development
5 Posts 3 Posters 1.4k Views 3 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.
  • Christian RogneC Offline
    Christian RogneC Offline
    Christian Rogne
    wrote on last edited by
    #1

    I am pretty new to programming and Arduino. I have made a temp sensor, and all are OK, but I need to send the value to the controller as a string, or a char. How can I convert the float to a string.

    I have tried with :

    char charVal[6];
    dtostrf(temperature,6,1,charVal);
    send (msg.setSensor(i).set(charVal));

    It converts right, but when I got the readings in the controller I got 20, if the temp actually are 23.

    Please help

    AWIA 1 Reply Last reply
    0
    • Christian RogneC Christian Rogne

      I am pretty new to programming and Arduino. I have made a temp sensor, and all are OK, but I need to send the value to the controller as a string, or a char. How can I convert the float to a string.

      I have tried with :

      char charVal[6];
      dtostrf(temperature,6,1,charVal);
      send (msg.setSensor(i).set(charVal));

      It converts right, but when I got the readings in the controller I got 20, if the temp actually are 23.

      Please help

      AWIA Offline
      AWIA Offline
      AWI
      Hero Member
      wrote on last edited by
      #2

      @Christian-Rogne Hi and welcome.
      You should not be bothered with these conversions as MySensors takes care for you. Look at the "setters" on the API page (scroll far down)

      1 Reply Last reply
      0
      • Christian RogneC Offline
        Christian RogneC Offline
        Christian Rogne
        wrote on last edited by
        #3

        Maybe normally not. The Vera Controller reads the value nicely whatever which type this is. But the Vera are connected to a Control4 controller, this wants the value to be a string or int. I have managed the value to be an int, but then I do not have any decimals. So it would be nice if I could have it to be a string

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

          Are you sure you send a correct value? Did you try printing the char-buffer before sending it?

          dtostrf should be the correct function to use.

          1 Reply Last reply
          0
          • Christian RogneC Offline
            Christian RogneC Offline
            Christian Rogne
            wrote on last edited by
            #5

            I have tried different things, the thing I have changed, is the type of value who would be send from the sensor.
            The default :
            send(msg.setSensor(i).set(temperature,1));

            gives me the following error in Control 4 :

            number 1
            string UPDATE
            parent 26
            room 1
            subcategory 0
            [string "Lua Code"]:120: bad argument #1 to 'SetVariable' (strValue should be a string) (ReceivedFromProxy)
            altid 5;0
            id 40
            temperature 23.5

            I tried to add the lines :

            char charVal[6]; //temporarily holds data from vals
            dtostrf(temperature,6,1,charVal);

            and changed the send to :

            send(msg.setSensor(i).set(charVal));

            But the same happens

            If I cast the temperature to int I got the it, but without decimals

            If I try with :

            String  string = "24,8";
            send(msg.setSensor(i).set(string));
            
            No error in Control4, but the sent temperature is 1
            
            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            25

            Online

            11.7k

            Users

            11.2k

            Topics

            113.1k

            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