Community discussions

MikroTik App
 
kasirivu
just joined
Topic Author
Posts: 5
Joined: Tue Feb 18, 2025 7:51 am
Location: uganda
Contact:

Hotspot Users Expiring Before Their Allocated Time (RouterOS v7.17.2)

Tue Feb 18, 2025 8:16 am

Hello everyone,

I’m facing an issue with my MikroTik Hotspot setup on RouterOS v7. Some of my hotspot users are being disconnected before their assigned expiration time (e.g., 1-day profiles).

Here’s what I’ve configured so far:

Idle Timeout: Set to none.
Keepalive Timeout: Tried various settings, including 10m and 1d.
Session Timeout: Set to 00:00:00 (disabled).
Uptime Limit: Set to the correct duration, such as 1d.
Despite this, users are still expiring prematurely. I’ve also ensured that the router’s time is accurate and synchronized via NTP.

Has anyone else encountered this problem on RouterOS v7? Any advice on what might be causing this or how to resolve it would be greatly appreciated!

on login script
#*****************************************************************************************

:put (",remc,1920,1d,0,,Enable,");
:local validity "1d"; #unit: m=mins, h=hours , d=days
:local price "1920"; #price(for sales report - optional to update)
:local tlimit "1d"; #unit(for sales report - optional to update): m=mins, h=hours , d=days
:local lockmac "YES"; #selection: YES/NO
:local addsales "YES"; #selection: YES/NO

# Modify above script values only
###############################################################################
:local date [ /system clock get date ]; :local time [ /system clock get time ]; :local addtime ($time + $validity); :local days ($addtime / 24h); :local ndays ($days * 24h); :local exptime ($addtime - $ndays); :local comment [ /ip hotspot user get $user comment]; :local hsProfile [/ip hotspot user get $user profile]; :local mac $"mac-address"; :if ([:pic $comment 3] = "/" and [:pic $comment 6] = "/") do={} else={ :local mdays {31;28;31;30;31;30;31;31;30;31;30;31}; :local months {"01"=1;"02"=2;"03"=3;"04"=4;"05"=5;"06"=6;"07"=7;"08"=8;"09"=9;"10"=10;"11"=11;"12"=12}; :local monthr {"jan";"feb";"mar";"apr";"may";"jun";"jul";"aug";"sep";"oct";"nov";"dec"}; :local tday [:tonum [:pick $date 8 10]]; :local tyear [:tonum [:pick $date 0 4]]; :local actmonths {"01"="jan";"02"="feb";"03"="mar";"04"="apr";"05"="may";"06"="jun";"07"="jul";"08"="aug";"09"="sep";"10"="oct";"11"="nov";"12"="dec"}; :local dd [:tonum [:pick $date 8 10]]; :local yy [:tonum [:pick $date 0 4]]; :local month [:pick $date 5 7]; :local year [ :pick $date 0 4 ]; :local mm (:$months->$month); :set dd ($dd+$days); :local dm [:pick $mdays ($mm-1)]; :if ($mm=2 && (($yy&3=0 && ($yy/100100 != $yy)) || $yy/400400=$yy) ) do={ :set dm 29 }; :while ($dd>$dm) do={ :set dd ($dd-$dm); :set mm ($mm+1); :if ($mm>12) do={ :set mm 1; :set yy ($yy+1);}; :set dm [:pick $mdays ($mm-1)]; :if ($mm=2 && (($yy&3=0 && ($yy/100100 != $yy)) || $yy/400400=$yy) ) do={ :set dm 29 }}; :local Tmonth (:$actmonths->$month); :local vdate "$[:pick $monthr ($mm-1)]/"; :if ($dd<10) do={ :set vdate ($vdate."0") }; :set $vdate "$vdate$dd/$yy"; :local zero ""; :if ( [len $tday] = 1) do={:set zero "0";}; /ip hotspot user set comment="$vdate $exptime" [find where name=$user]; :if ($lockmac = "YES") do={ /ip hotspot user set mac-address=$mac [find where name=$user];}; :if ($addsales = "YES") do={ /system script add name="$Tmonth/$zero$tday/$tyear-|-$time-|-$user-|-$price-|-$address-|-$mac-|-$tlimit-|-$hsProfile-|-$comment" owner="$Tmonth$year" source="$Tmonth/$zero$tday/$tyear" comment=mikhmon;};}
###############################################################################

scheduler script
:local hsprofile "24hours"; #hotspot user profile

# Modify above script values only
###############################################################################
:foreach i in [ /ip hotspot user find where profile=$hsprofile ] do={ :local comment [ /ip hotspot user get $i comment]; :local name [ /ip hotspot user get $i name]; :local gettime [:pic $comment 12 20]; :local getmonth [:pic $comment 0 3]; :local getday [:tonum [:pic $comment 4 6]]; :local getyear [:tonum [:pic $comment 7 11]]; :if ([:pic $comment 3] = "/" and [:pic $comment 6] = "/") do={ :local vmonths {"jan"=1;"feb"=2;"mar"=3;"apr"=4;"may"=5;"jun"=6;"jul"=7;"aug"=8;"sep"=9;"oct"=10;"nov"=11;"dec"=12}; :local tmonths {"01"=1;"02"=2;"03"=3;"04"=4;"05"=5;"06"=6;"07"=7;"08"=8;"09"=9;"10"=10;"11"=11;"12"=12}; :local date [ /system clock get date ]; :local time [ /system clock get time ]; :local dd [:tonum [:pick $date 8 10]]; :local yy [:tonum [:pick $date 0 4]]; :local month [:pick $date 5 7]; :local mm (:$tmonths->$month); :local getmm (:$vmonths->$getmonth); :if (($getyear < $yy) or ($getyear <= $yy and $getmm < $mm) or ($getyear <= $yy and $getmm <= $mm and $getday < $dd) or ($getyear <= $yy and $getmm <= $mm and $getday <= $dd and $gettime < $time)) do={ [ /ip hotspot user remove $i ]; [ /ip hotspot active remove [find where user=$name] ];}}}
###############################################################################
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12861
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Hotspot Users Expiring Before Their Allocated Time (RouterOS v7.17.2)

Tue Feb 18, 2025 10:27 am

When you update something, you have to read the changelogs, otherwise what do you expect?

Even if RouterOS, as it sometimes does, converts or adjusts the various parameters, it cannot be expected to also correct hand-written scripts...

If you had read all the changelogs of RouterOS v6.x.x that you were using up to version 7.17.2 you would know why it doesn't work for you.
viewtopic.php?t=196072

Who wrote that abomination of a so long one-line-script?
Ask whoever created that abomination to patch it for RouterOS 7.17.2
 
FRANKMUNOZAPURE
just joined
Posts: 21
Joined: Thu May 23, 2024 11:57 am

Re: Hotspot Users Expiring Before Their Allocated Time (RouterOS v7.17.2)

Tue Feb 18, 2025 12:24 pm

Friend, I have this script in version 7 and so far it has worked wonderfully for me.
I hope it can help you:
:local comment "IN USE"
:local userprofile [ip hotspot user get [find where name="$user"] profile]

:if ([/ip hotspot user get $user comment]="") do={[/ip hotspot user set $user comment=$comment]}

[/system scheduler 
add comment= [/ip hotspot user profile get [find where name="$userprofile"] name] name=$user on-event="/ip hotspot user remove \"$user\" \r\
  \n/ip hotspot active remove [find user=\"$user\"]\r\
  \n/system scheduler remove [find where name=\"$user\"] \r\
  \n\r\
" interval= [/ip hotspot user profile get [find where name="$userprofile"] session-timeout]]
 
kasirivu
just joined
Topic Author
Posts: 5
Joined: Tue Feb 18, 2025 7:51 am
Location: uganda
Contact:

Re: Hotspot Users Expiring Before Their Allocated Time (RouterOS v7.17.2)

Tue Feb 18, 2025 3:46 pm

When you update something, you have to read the changelogs, otherwise what do you expect?

Even if RouterOS, as it sometimes does, converts or adjusts the various parameters, it cannot be expected to also correct hand-written scripts...

If you had read all the changelogs of RouterOS v6.x.x that you were using up to version 7.17.2 you would know why it doesn't work for you.
viewtopic.php?t=196072

Who wrote that abomination of a so long one-line-script?
Ask whoever created that abomination to patch it for RouterOS 7.17.2
do you have any script to help
 
kasirivu
just joined
Topic Author
Posts: 5
Joined: Tue Feb 18, 2025 7:51 am
Location: uganda
Contact:

Re: Hotspot Users Expiring Before Their Allocated Time (RouterOS v7.17.2)

Tue Feb 18, 2025 3:47 pm

Friend, I have this script in version 7 and so far it has worked wonderfully for me.
I hope it can help you:
:local comment "IN USE"
:local userprofile [ip hotspot user get [find where name="$user"] profile]

:if ([/ip hotspot user get $user comment]="") do={[/ip hotspot user set $user comment=$comment]}

[/system scheduler 
add comment= [/ip hotspot user profile get [find where name="$userprofile"] name] name=$user on-event="/ip hotspot user remove \"$user\" \r\
  \n/ip hotspot active remove [find user=\"$user\"]\r\
  \n/system scheduler remove [find where name=\"$user\"] \r\
  \n\r\
" interval= [/ip hotspot user profile get [find where name="$userprofile"] session-timeout]]
let me try it out thank
 
kasirivu
just joined
Topic Author
Posts: 5
Joined: Tue Feb 18, 2025 7:51 am
Location: uganda
Contact:

Re: Hotspot Users Expiring Before Their Allocated Time (RouterOS v7.17.2)

Thu Feb 20, 2025 1:31 pm

Friend, I have this script in version 7 and so far it has worked wonderfully for me.
I hope it can help you:
:local comment "IN USE"
:local userprofile [ip hotspot user get [find where name="$user"] profile]

:if ([/ip hotspot user get $user comment]="") do={[/ip hotspot user set $user comment=$comment]}

[/system scheduler 
add comment= [/ip hotspot user profile get [find where name="$userprofile"] name] name=$user on-event="/ip hotspot user remove \"$user\" \r\
  \n/ip hotspot active remove [find user=\"$user\"]\r\
  \n/system scheduler remove [find where name=\"$user\"] \r\
  \n\r\
" interval= [/ip hotspot user profile get [find where name="$userprofile"] session-timeout]]
let me try it out thank
Handling Missed Scheduler Events After Power Outage on RouterOS 7
I'm running into an issue with scheduler events on my MikroTik router. I have scheduled tasks—such as removing hotspot users at specific times—that are missed when the router is powered off (for example, during a power outage). When the router comes back online, those events are not automatically executed.
My Questions:
Is this a reliable method to catch and execute missed events after a power outage?
Are there any potential pitfalls with iterating over all scheduler events like this?
Can you suggest improvements or alternative approaches that might be more efficient or robust?
Any feedback or suggestions would be greatly appreciated. Thanks in advance for your help!
 
FRANKMUNOZAPURE
just joined
Posts: 21
Joined: Thu May 23, 2024 11:57 am

Re: Hotspot Users Expiring Before Their Allocated Time (RouterOS v7.17.2)

Fri Mar 07, 2025 3:10 pm

:local userprofile [ip hotspot user get [find where name="$user"] profile]
:local limituptime [/ip hotspot user get [find where name="$user"] limit-uptime]
:if ($limituptime = "") do={:log info "El usuario $user no tiene limit-uptime definido."
:set limituptime "0d00:00:00"}
:local utdias 0 
:local uthoras 0 
:local utminutos 0 
:if ([:find $limituptime "d"] != -1) do={
:set utdias [:tonum [:pick $limituptime 0 [:find $limituptime "d"]]]
:set limituptime [:pick $limituptime ([:find $limituptime "d"] + 1) [:len $limituptime]]}
:if ([:find $limituptime ":"] != -1) do={
:set uthoras [:tonum [:pick $limituptime 0 [:find $limituptime ":"]]]
:set limituptime [:pick $limituptime ([:find $limituptime ":"] + 1) [:len $limituptime]]}
:if ([:find $limituptime ":"] != -1) do={
:set utminutos [:tonum [:pick $limituptime 0 [:find $limituptime ":"]]]}
:local tdias $utdias
:local thoras $uthoras
:local tminutos $utminutos
:delay 1s
:local atime [/system clock get time]
:local adate [/system clock get date]
:local expTime [ /system clock get time ]
:local expDate [ /system clock get date ]
:local temp1 [:pick $expDate 0 3]
:local temp2 [:pick $expDate 4 6] 
:local temp3 [:pick $expTime 0 5]
:local mesarray ("jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec")
:local diaarray ("31","28","31","30","31","30","31","31","30","31","30","31")
:local day [:pick $expDate 4 6]
:local monthtxt [:pick $expDate 0 3]
:local year [:pick $expDate 7 11]
:local months ([:find $mesarray $monthtxt])
:local dia ([:pick $diaarray $months])
:local fhora [:pick $expTime 0 2]
:local fminutos [:pick $expTime 3 5]
:local fsegundos [:pick $expTime 6 9]
:local mayormin (($fminutos+$tminutos)-60)
:local mayorhora (($fhora+$thoras)-24)
:if (($fminutos+$tminutos)>59) do={
:set $thoras ($thoras+1)
:set $fminutos ($mayormin)} else={
:set $fminutos ($fminutos+$tminutos)}
:if (($fhora+$thoras)>23) do={
:set expTime ("0".$mayorhora.":".$fminutos.":".fsegundos)
:set $tdias ($tdias+1)} else={
:set expTime (($fhora+$thoras).":".$fminutos.":".fsegundos)}
:if (($day+$tdias)>$dia) do={:if ($months=11) do={
:set months 0; :set year ($year+1)
:set day (($day+$tdias)-$dia)
:local mes ([:pick $mesarray $months])
:set expDate ($mes."/".$day."/".$year)} else={
:set months ($months+1);
:set day (($day+$tdias)-$dia);
:local mes ([:pick $mesarray $months])
:set expDate ($mes."/".$day."/".$year)}} else={
:set day ($day+$tdias)
:local mes ([:pick $mesarray $months])
:set expDate ($mes."/".$day."/".$year)}
:local comment "EN USO DESDE: $adate $atime ==> HASTA: $expDate $expTime"
:if ([ /ip hotspot user get $user comment ]="") do={ [ /ip hotspot user set $user comment="$comment" ]};
[/system scheduler add interval=3m comment="$userprofile" name=$user on-event="/ip hotspot user disable [find name=$user] \r\
 \n/ip hotspot active remove [find user=$user] \r\
 \n/ip hotspot cookie remove [find user=$user] \r\
 \n/system scheduler remove [find name=$user] \r\
 \n\r\ " start-date=$expDate start-time=$expTime]

Hi friend, check to see if it works for you,
PD; You can publish your script in version 6