requesting help with meta command script
-
i am trying to write a command in config.g where it will write to another file and run it upon start up. the part that i can't wrap my mind around is I need the script to basically turn on access point mode upon start up and if I turn off the machine and turn it back on, it will turn off access point mode and turn on client mode. essentially, I need it to flip-flop everytime i turn off and on the machine. any help would be great. So far, this is what I came up with. can someone please check these and see if it will work?
;/sys/PRINTCODE/globalwifi.g
global wifi=AP ;assign global var to globalwifi.g
;config.g
M98 P"/sys/PRINTCODE/globalwifi.g" ;call globalwifi.g to define wifi variable M98 P"/sys/PRINTCODE/network.g" ;call network.g macro
;/sys/PRINTCODE/network.g
if global.wifi=AP M552 S-1 ;disable networking G4 S4 ; wait 4 sec M552 S0 ; turn off wifi module M552 S1 ; turn on client mode M28 "/sys/PRINTCODE/globalwifi.g" start writing file global wifi=C M29 ;stop writing to file G4 s4 ; wait 4 sec set global.wifi=C if global.wifi=C M552 S-1 ;disable networking G4 S4 ; wait 4 sec M552 S0 ; turn off wifi module M552 S2 ; turn on AP mode M28 "/sys/PRINTCODE/globalwifi.g" start writing file global wifi=AP M29 ;stop writing to file G4 s4 ; wait 4 sec set global.wifi=AP
-
@tekstyle
You need an elif in your macro.
Otherwise the second IF will reverse the first because you've just set the global to C.
Edit:Also you forgot to use SET in a couple of spots
Probably deliberate as you may not be creating the global in config.gif global.wifi=AP M552 S-1 ;disable networking G4 S4 ; wait 4 sec M552 S0 ; turn off wifi module M552 S1 ; turn on client mode M28 "/sys/PRINTCODE/globalwifi.g" start writing file global wifi=C M29 ;stop writing to file G4 s4 ; wait 4 sec set global.wifi=C elif global.wifi=C M552 S-1 ;disable networking G4 S4 ; wait 4 sec M552 S0 ; turn off wifi module M552 S2 ; turn on AP mode M28 "/sys/PRINTCODE/globalwifi.g" start writing file global wifi=AP M29 ;stop writing to file G4 s4 ; wait 4 sec set global.wifi=AP
-
You might also consider checking for the existence of the global so it only runs the code on a cold start, and not if you run M98 P"0:\sys\config.g"
if !exists(global.wifi) M98 P"/sys/PRINTCODE/globalwifi.g" ;call globalwifi.g to define wifi variable M98 P"/sys/PRINTCODE/network.g" ;call network.g macro
-
I never actually knew how to use an "elif" in my coding. it always returned errors when testing. I will implement your changes and see how it goes as I am not at my machine now.
You are correct in having no SET in my config. I purposefully put those in globalwifi.g and call globalwifi.g from config.g upon boot up. the reason being I do not want to overwhelm my config file with too much stuff when I need to refer back to do modifications to it.
@owend said in requesting help with meta command script:
You might also consider checking for the existence of the global so it only runs the code on a cold start, and not if you run M98 P"0:\sys\config.g"
if !exists(global.wifi) M98 P"/sys/PRINTCODE/globalwifi.g" ;call globalwifi.g to define wifi variable M98 P"/sys/PRINTCODE/network.g" ;call network.g macro
just out of curiosity, upon boot up, the only way to define global wifi is with the globalwifi.g file. is this condition necessary if I do not have any global wifi = nnn anywhere in my config? the way I currently have it, global wifi = nn is evoked when globalwifi.g is called during startup where nn can be C or AP depending on what was last written. the config.g will just call for globalwifi.g and it should flip-flop with every start up.
-
@tekstyle
The way you have it is fine.
The check for the globals existence will just avert the swapping of modes if you just re-run config.g instead of doing a system restart -
@owend Thank you for your support. also learned something new!