M98 calling a macro with M929 with "+state.time" not working
-
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?
-
@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. -
@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.
-
@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. -
@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.
-
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.
-
-