Community discussions

MikroTik App
 
cumhureren
just joined
Topic Author
Posts: 11
Joined: Wed Jan 22, 2020 1:29 pm

bandwidth test and telegram message

Sat Jun 19, 2021 6:12 pm

hi there;
my code 's some parts actually working, code does test bandwith but telegram message part is not working,
what am i missing?

thanx for your help




/interface pppoe-client monitor pppoe-out3 once do={

:if ($status != "connected") do={
/interface pppoe-client remove pppoe-out3;

}


:if ($status = "connected") do={
{



:local speedtest [/tool bandwidth-test 5.5.5.1 protocol=tcp user=isp@isp password=1234 direction=receive duration=5s as-value ] ;

:local MyFuncDataToMKbps do={
:local DataOriginal $1
:set DataOriginal ($DataOriginal / 1000)
:local Mbps ($DataOriginal / 1000 * 1000)
:local Kbps ($DataOriginal - $Mbps)
:set Mbps ($Mbps / 1000)

:return ($Mbps."M ".$Kbps."K - bps")
}

:local Rx [$MyFuncDataToMKbps ($speedtest->"rx-10-second-average")]
:local Tx [$MyFuncDataToMKbps ($speedtest->"tx-10-second-average")]
:local Time ([/system clock get date]." ".[/system clock get time])
:put "$Time | Rx: $Rx | Tx: $Tx"


:local DLMb [pick $Rx 0 [:find $Rx "M"]]
:if ($DLMb < 400) do={/tool fetch keep-result=no url="https://api.telegram.org/bot12193453497 ... AMIYE-LINK $Rx "}

}
}
}
}
Last edited by cumhureren on Mon Jun 21, 2021 10:05 am, edited 2 times in total.
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3291
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: bandwitch test and telegram message

Sun Jun 20, 2021 4:10 pm

I have not tested it, so it may still be wrong, but since you do not use code tags, or maybe not tab, you do not see when there is a start { and a stop }

Example
:if ($status = "connected") do={
{
This will fail.

Here is a re post wit code tags and tabs. (also without ; at end of line, not needed)
/interface pppoe-client monitor pppoe-out3 once do={

	:if ($status != "connected") do={
		/interface pppoe-client remove pppoe-out3
	}


	:if ($status = "connected") do={

		:local speedtest [/tool bandwidth-test 5.5.5.1 protocol=tcp user=isp@isp password=1234 direction=receive duration=5s as-value ]

		:local MyFuncDataToMKbps do={
			:local DataOriginal $1
			:set DataOriginal ($DataOriginal / 1000)
			:local Mbps ($DataOriginal / 1000 * 1000)
			:local Kbps ($DataOriginal - $Mbps)
			:set Mbps ($Mbps / 1000)

			:return ($Mbps."M ".$Kbps."K - bps")
		}

		:local Rx [$MyFuncDataToMKbps ($speedtest->"rx-10-second-average")]
		:local Tx [$MyFuncDataToMKbps ($speedtest->"tx-10-second-average")]
		:local Time ([/system clock get date]." ".[/system clock get time])
		:put "$Time | Rx: $Rx | Tx: $Tx"

		:local DLMb [pick $Rx 0 [:find $Rx "M"]]
		:if ($DLMb < 400) do={
			/tool fetch keep-result=no url="https://api.telegram.org/bot12193453497 ... AMIYE-LINK $Rx "
		}

	}
}
 
cumhureren
just joined
Topic Author
Posts: 11
Joined: Wed Jan 22, 2020 1:29 pm

Re: bandwitch test and telegram message

Sun Jun 20, 2021 11:08 pm

telegram part is still not working :(

I have not tested it, so it may still be wrong, but since you do not use code tags, or maybe not tab, you do not see when there is a start { and a stop }

Example
:if ($status = "connected") do={
{
This will fail.

Here is a re post wit code tags and tabs. (also without ; at end of line, not needed)
/interface pppoe-client monitor pppoe-out3 once do={

	:if ($status != "connected") do={
		/interface pppoe-client remove pppoe-out3
	}


	:if ($status = "connected") do={

		:local speedtest [/tool bandwidth-test 5.5.5.1 protocol=tcp user=isp@isp password=1234 direction=receive duration=5s as-value ]

		:local MyFuncDataToMKbps do={
			:local DataOriginal $1
			:set DataOriginal ($DataOriginal / 1000)
			:local Mbps ($DataOriginal / 1000 * 1000)
			:local Kbps ($DataOriginal - $Mbps)
			:set Mbps ($Mbps / 1000)

			:return ($Mbps."M ".$Kbps."K - bps")
		}

		:local Rx [$MyFuncDataToMKbps ($speedtest->"rx-10-second-average")]
		:local Tx [$MyFuncDataToMKbps ($speedtest->"tx-10-second-average")]
		:local Time ([/system clock get date]." ".[/system clock get time])
		:put "$Time | Rx: $Rx | Tx: $Tx"

		:local DLMb [pick $Rx 0 [:find $Rx "M"]]
		:if ($DLMb < 400) do={
			/tool fetch keep-result=no url="https://api.telegram.org/bot12193453497 ... AMIYE-LINK $Rx "
		}

	}
}
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: bandwitch test and telegram message

Mon Jun 21, 2021 3:12 am

bandwitch test and telegram message

correct the title, please
 
cumhureren
just joined
Topic Author
Posts: 11
Joined: Wed Jan 22, 2020 1:29 pm

Re: bandwitch test and telegram message

Mon Jun 21, 2021 10:06 am

bandwitch test and telegram message

correct the title, please
thanx :)
 
cumhureren
just joined
Topic Author
Posts: 11
Joined: Wed Jan 22, 2020 1:29 pm

Re: bandwidth test and telegram message

Wed Jun 23, 2021 3:52 pm

any help?
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: bandwidth test and telegram message

Wed Jun 23, 2021 4:30 pm

Only someone with telegram can help you,
sorry.
 
DerAlSem
just joined
Posts: 7
Joined: Sun Jul 23, 2017 1:25 pm

Re: bandwidth test and telegram message

Sun Jun 27, 2021 9:27 pm

Why do you actually trying to FETCH, not to POST to API? i don't see http-method=post in your tool fetch line.

And AFAIK TG API accepts only JSON, and i doubt you try to send JSON...

Who is online

Users browsing this forum: alexantao and 28 guests