Duet3D Logo Duet3D
    • Tags
    • Documentation
    • Order
    • Register
    • Login

    M98 calling a macro with M929 with "+state.time" not working

    Scheduled Pinned Locked Moved Solved
    Beta Firmware
    3
    6
    267
    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.
    • NeoDueundefined
      NeoDue
      last edited by NeoDue

      I am trying to create a log file after boot. For this, I have added a 10s pause at the end of config.g, followed by an M98 command:

      ; [... a whole config.g here ...]
      
      G4 P10000
      M98 P"/macros/Wartung/M122 in Logfle schreiben.g"
      

      The macro "M122 in Logfle schreiben.g" called is rather simple:

      M929 P{"/sys/log/M122_Log"^{+state.time}^"-"^{state.msUpTime}^".txt"} S3
      M122
      M591 D0
      M591 D1
      M929 S0
      

      With 3.5.0rc2 (unclear if it would have worked before though), I get the following error:

      error in start file macro line 1: in file macro line 1 column 40: M929: expected numeric or enumeration value after '+'
      

      If I start the macro directly, it works perfectly fine as it should... someone help me please: what did I overlook?

      OwenDundefined dc42undefined 2 Replies Last reply Reply Quote 0
      • OwenDundefined
        OwenD @NeoDue
        last edited by

        @NeoDue
        state.time is null until after the network connects.
        This doesn't occur until after config.g exits
        So when you run the macro manually, it has been populated and works.
        When you run it as part of config.g you are trying to do math on a null value.
        You will need to use state.upTime instead.

        NeoDueundefined 1 Reply Last reply Reply Quote 0
        • NeoDueundefined
          NeoDue @OwenD
          last edited by NeoDue

          @OwenD thanks a lot! I did not know that. Is there some way around this? state.uptime gets reset on every boot, therefore this is not necessarily unique.

          Hm... maybe setting a global variable in config.g and adding a loop into daemon.g that only executes when that variable is set (and changes its value when it runs which then means it is only executed once) might do the trick... but I am open to simpler suggestions 😉

          Edit: wait a second... I have a 10s delay before that macro is called, but the Wifi module connects quite a bit earlier than that. Thus it is probably not the Wifi module connecting but rather some task that is called after config.g has finished that populates state.time. But it seems I cannot call that task manually I guess.

          OwenDundefined 1 Reply Last reply Reply Quote 0
          • OwenDundefined
            OwenD @NeoDue
            last edited by

            @NeoDue
            Actually, I was only partially correct.
            state.time is set when a HTTP client connects (such as DWC)
            To get round it depends on whether you must have an accurate time stamp in your file name.

            If not then use the random() function perhaps in conjunction with log() or similar to generate a semi-unique file name.

            If you must have a time stamp...
            It would be possible to connect a pi pico or similar to do the HTTP request.
            You could initiate the request via an IO call in your macro.

            NeoDueundefined 1 Reply Last reply Reply Quote 0
            • dc42undefined
              dc42 administrators @NeoDue
              last edited by

              @NeoDue you could use a loop in daemon.g to wait until state.time is not null, then create the log file. You will also need to use a global variable to make sure it only gets created once.

              Duet WiFi hardware designer and firmware engineer
              Please do not ask me for Duet support via PM or email, use the forum
              http://www.escher3d.com, https://miscsolutions.wordpress.com

              1 Reply Last reply Reply Quote 0
              • NeoDueundefined
                NeoDue @OwenD
                last edited by

                @OwenD @dc42 thank you!

                I think I found another way: the main reason for the timestamp is that it is unique. Now if I create a global variable which I save persistently in a macro file and recall that file within config.g as I do with the xy offset and z axis calibration data and increment that value whenever config.g is executed, I can count all config.g executions (roughly equal to "reboots") in a number and use that in the file name. That should suffice.

                1 Reply Last reply Reply Quote 0
                • NeoDueundefined NeoDue marked this topic as a question
                • NeoDueundefined NeoDue has marked this topic as solved
                • First post
                  Last post
                Unless otherwise noted, all forum content is licensed under CC-BY-SA