Script doensn't working on a router without Wireless

Hi everyone, i want help on this script, it is suppose to, if there is a wireless interface on router execute the command, and if does not exists wireless interface it just set the mock variable value. The problem is that the script is failing in "on-erro" part. Can you guys help? A router with Wireless interface it works fine ( tested on 951Ui-2HnD) but on a router without Wireless it does'nt (RouterBOARD 750G r3)

wireless_stats

:local registeredclients;
:local overalltxccq;
:local channel2;
:local noisefloor;
:local identity [/ip hotspot get 0 name];
:local wifistatus;

{
:do {
:if ([:len [/interface wireless find ]]>0) do={/interface wireless monitor wlan1 once do={
:set wifistatus $"status"
:set registeredclients $"registered-clients"
:set overalltxccq $"overall-tx-ccq"
:if ([:typeof $overalltxccq] = "nil") do={
:set overalltxccq 0
}
:set channel2 $channel
:set noisefloor $"noise-floor"
}} on-error={ :set wifistatus "disabled"};
}

Can wifistatus be set on a non wireless equiped device? It seems to me that it is a property on the wlan interface.

yep, when running this on a non wireless equiped device it returns "No wireless interface found"
{
:do {
:if ([:len [/interface wireless find ]]>0) do={:put "wireless found"}} on-error={:put "No wireless interface found"};
}

on-error needs to be connected to the :do block, not the :if command
My routers that do not have wifi accept the wireless command with out error so I do get: No active wifi interfaces
Also use code tags <> button while posting to more easy see the structure of your code (using tab)
Since this code is wrapped in square brackets [], you can just cut and past it for testing it out.

[
:local wifistatus
:do {
	:if ([:len [/interface wireless find ]]>0) do={
		:put "wifi interface found"
	} else={
		:put "No active wifi interfaces"
	}
} on-error={
	:put "Router does not support that command"
}
]

Thanks for answering, so I tryed to use you code with my needs but I still getting error when runnning it. It says syntax erro in the “once do” line, do you know why?

[
:do {
	:if ([:len [/interface wireless find ]]>0) do={
			/interface wireless monitor wlan1 once do={
 				:set wifistatus $"status"
 				:set registeredclients $"registered-clients"
 				:set overalltxccq $"overall-tx-ccq"
 					:if ([:typeof $overalltxccq] = "nil") do={
 						:set overalltxccq 0
				}
 				:set channel2 $channel
 				:set noisefloor $"noise-floor"
				}
	} else={
		:put "No active wifi interfaces"
	}
} on-error={
	:put "Router does not support that command"
}
]

You need to declare variable before using set.
I have no wifi router at the moment, so can not test it fully, but this runs without error on my test router:

[
:local wifistatus
:local registeredclients
:local overalltxccq
:local channel2
:local noisefloor
:do {
	:if ([:len [/interface wireless find ]]>0) do={
			/interface wireless monitor wlan1 once do={
 				:set wifistatus $"status"
 				:set registeredclients $"registered-clients"
 				:set overalltxccq $"overall-tx-ccq"
 					:if ([:typeof $overalltxccq] = "nil") do={
 						:set overalltxccq 0
				}
 				:set channel2 $channel
 				:set noisefloor $"noise-floor"
				}
	} else={
		:put "No active wifi interfaces"
	}
} on-error={
	:put "Router does not support that command"
}
]