GUI-O Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Assign a number to "ni" through a variable

    Scheduled Pinned Locked Moved
    Comments & Feedback
    2
    3
    262
    Loading More Posts
    • 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.
    • S
      Sato
      last edited by

      Hello,
      How to assign a number to the widget "ni" through a variable
      mqttClient.publish(&In[0], "@ni1 VAL:1234\n\r"); // works, but not what I need

      byte tmp = 27;
      mqttClient.publish(&In[0], "@ni3 VAL:tmp\n\r"); // not work
      mqttClient.publish(&In[0], "@ni3 VAL:&tmp\n\r"); // not work

      String strtmp = "81";
      mqttClient.publish(&In[0], "@ni2 VAL:&strtmp\n\r");// not work

      How can this be done?

      Best Regards

      K 1 Reply Last reply Reply Quote 0
      • K
        kl3m3n @Sato
        last edited by kl3m3n

        @sato Hello,

        One way (you can adapt the buffer size to your needs and you should also check the return value of snprintf):

        int val = 1234;
        char buf[50];
        snprintf(buf, 50, "@ni1 VAL:%d\n\r", val);
        
        mqttClient.publish(&In[0], buf);
        

        You could also build a String object:

        String str = "@ni1 VAL:" + String(val) + "\n\r";
        
        mqttClient.publish(&In[0], &str[0]);
        

        Regards,
        kl3m3n

        S 1 Reply Last reply Reply Quote 0
        • S
          Sato @kl3m3n
          last edited by

          Hello @kl3m3n

          This works and is simpler. You are the best!

          String str = "@ni1 VAL:" + String(val) + "\n\r";
          mqttClient.publish(&In[0], &str[0]);

          Best regards

          1 Reply Last reply Reply Quote 0
          • K kl3m3n referenced this topic on
          • First post
            Last post