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

    How to use the string to use it static const *in

    Scheduled Pinned Locked Moved
    Comments & Feedback
    2
    5
    250
    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,
      Instead of writing the tokens in the code, I would like to save the token Out and the token In in two files in SPIFFS. On startup I read from the file the line of the token into a variable of type String, but I haven't succeeded yet, it gives conversion error on compilation. Does anyone know how to do it?

      // file content:
      cbbb726f-1e9b-4da2-a121-acf2da1f6d98

      String inToken = "";
      file = SPIFFS.open("/inToken.txt");//file in SPIFFS
      while (file.available()) {
      inToken = file.readStringUntil('\n'); // read line with the token
      }
      //---static const char *In = "cbbb726f-1e9b-4da2-a121-acf2da1f6d98"

      static const char *In = inToken; // compile error
      file.close();

      Thanks
      Regards

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

        @sato said in How to use the string to use it static const *in:

        static const char *In = inToken

        Hello,

        just use "String inToken..." directly, e.g.:

        mqttClient.publish(&inToken[0], ...)
        

        or

        mqttClient.publish(inToken.c_str(), ...)
        

        You can apply the same principle to "String outToken" that you read from a file.

        You can drop "In" and "Out" variables...

        Best regards,
        kl3m3n

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

          Thank You, @kl3m3n

          Will try it tomorrow

          Best regards

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

            Hi @kl3m3n,

            Thanks for the tip, it works well

            Best regards

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

              @Sato Great!

              Best regards,
              kl3m3n

              1 Reply Last reply Reply Quote 0
              • First post
                Last post