Community discussions

MikroTik App
 
mikrc
just joined
Topic Author
Posts: 1
Joined: Tue Feb 28, 2023 8:43 pm

Solar Powered Automatic POE Script

Tue Mar 28, 2023 7:05 pm

Hello,
I have a remote, solar-powered site with a RB5009(POE version). The 5009 is fully powered from the 5.5mm DC jack, from a DC-DC 24-56V converter. My battery system voltage is 24V, and I'm also feeding that battery voltage into the 2-pin connector of the 5009 as a voltage reference for running my script.

So far, I have built several working scripts, used to turn ON POE when the batteries are getting a good charge from solar, and turn OFF when the battery voltage drops off at night (I don't need to run my camera and AP at night). By simply adjusting the turn on/off voltage, I can prioritize which devices turn on, given the state of battery charge.

The scripts seem to be working ok, but this is my first attempt at a script, and I was wondering if you could take a look at my script to see if there are any blatant errors or no-nos. Could you please have a look, and tell me if I need to make any corrections? Again, I have one of these scripts set up for each POE port device, and they are driven by a scheduler that runs them every 5 to 10 minutes, staggered, so they don't all run at the same time.

Thank you in advance!

Here's the script:

# Name the Device Connected to Port
:local portdevice "Mast Camera"
# Define which port to control
:local ethport LAN5
# Define what battery voltage device will turn on at
:local cutinvolts 28.2
# Define what battery voltage POE will be disabled at
:local shutoffvolts 25.4
# Define the earliest hour POE will be turned on
:local ontimeearliest 6
# Define the latest hour POE will be turned on
:local ontimelatest 12

#Gather System Information
:local voltmeter [/system/health get [find name=2pin-voltage] value]
:local poestatus;
/interface ethernet poe monitor $ethport once do={:set poestatus $"poe-out-status";}
:local thistime [/system clock get time]
:local thishour [:pick $thistime 0 2]

#Argument to turn POE OFF
:if ($voltmeter <= $shutoffvolts && $poestatus = "powered-on") do={
/interface ethernet poe set poe-out=off $ethport;
:log info message=("$portdevice POE Disabled, Voltage = $voltmeter")}

#Argument to turn POE ON
:if (($voltmeter >= $cutinvolts) && ($poestatus = "disabled") && ($thishour >= $ontimeearliest) && ($thishour <= $ontimelatest)) do={
/interface ethernet poe set poe-out=forced-on $ethport;
:log info message=("$portdevice POE Enabled, Voltage = $voltmeter")}
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Solar Powered Automatic POE Script

Wed Mar 29, 2023 12:25 am

DC-DC 24-56V
Useless power dispersion... often cameras go also @24V....

28.2 ?
25.4 ?
RouterOS do not support floating numbers...
This are IPs....

test on terminal code

[] > :put 28.2
28.0.0.2
[] > :put 25.4
25.0.0.4
When you pick the hours, if are "06", is a string, must be converted to a number.

I do not have any RB5009UPr+S+IN to check how the system healt is get from script.

revised but not tested code

#!!! ROS v7.4+ only

:local portdevice     "Mast Camera" ; # Name the Device Connected to Port
:local ethport        "LAN5"        ; # Define which port to control
:local cutinvolts     "28.2"        ; # Define what battery voltage device will turn on at
:local shutoffvolts   "25.4"        ; # Define what battery voltage POE will be disabled at
:local ontimeearliest 6             ; # Define the earliest hour POE will be turned on
:local ontimelatest   12            ; # Define the latest hour POE will be turned on
/system
:local thishour       [:tonum [:pick [clock get time] 0 2]]
# must be tested if return a string or not...
:local voltmeter      [health get [find where name="2pin-voltage"] value]

/interface ethernet poe
:local poestatus      ([monitor $ethport once as-value]->"poe-out-status")

# Argument to turn POE OFF
:if (($voltmeter <= $shutoffvolts) and ($poestatus = "powered-on")) do={
    set $ethport poe-out="off"
    :log info "$portdevice POE Disabled, Voltage = $voltmeter"
}

# Argument to turn POE ON
:if (($voltmeter >= $cutinvolts) and ($poestatus = "disabled") and ($thishour >= $ontimeearliest) and ($thishour <= $ontimelatest)) do={
    set $ethport poe-out="forced-on"
    :log info "$portdevice POE Enabled, Voltage = $voltmeter"
}
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3169
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: Solar Powered Automatic POE Script

Wed Mar 29, 2023 1:06 am

Values on a RB5009 with PoE (v7.9beta4):
  
  0:
    .id: *10
    name: poe-out-consumption
    type: W
    value: 1.6
  1:
    .id: *11
    name: cpu-temperature
    type: C
    value: 47
  2:
    .id: *1BBD
    name: board-temperature1
    type: C
    value: 37
  3:
    .id: *1C21
    name: jack-voltage
    type: V
    value: 50.2
  4:
    .id: *1C22
    name: 2pin-voltage
    type: V
    value: 0
  5:
    .id: *1C23
    name: poe-in-voltage
    type: V
    value: 0
edit: see @rexextend's example above.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Solar Powered Automatic POE Script

Wed Mar 29, 2023 1:11 am

Thanks @Amm0

already return with "."???
Is a mess... RouterOS do not provide floating point values... better provide the value like 274 for 27.4V

As a string "12.4" is bigger than "24"

@mikrc
The 5009 is fully powered from the 5.5mm DC jack
What???

Why you check 2pin-voltage instead of jack-voltage???
Too much contraddiction.....................................


"normalization" of the voltage.
for example "24.3"
contain a dot "."?
if not add "0" at the end
if yes pick before and after the dot with find and join the values
convert to number what you obtain,
now you have dV and 243 are comparable with 235 dV
iis only "24"? the added 0 at the end converted all to number give 240 dV
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3169
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: Solar Powered Automatic POE Script

Wed Mar 29, 2023 1:20 am

Your script seems to works (well runs, I don't have PoE used things RN). Yeah it's jack-voltage. But confusing, that's doesn't 5.5/2.1 doesn't have "2-pins". And then you run into the no floats problem...

And, yeah, I'd forgot the [find where name...] trick myself and saw your updated your post since yeah "get" just returns an array
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Solar Powered Automatic POE Script

Wed Mar 29, 2023 1:25 am

Too much contraddictions..........................
seems to come from ChatGPT...
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3169
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: Solar Powered Automatic POE Script

Wed Mar 29, 2023 1:25 am

And, yes, it's a string type. Sorry I used my YAML script to format.
:put [:typeof [/system/health get [find where name="jack-voltage"] value]]
 str
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Solar Powered Automatic POE Script

Wed Mar 29, 2023 1:28 am

Don't worry, it's perfectly understandable.
Better than my english...
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3169
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: Solar Powered Automatic POE Script

Wed Mar 29, 2023 1:28 am

seems to come from ChatGPT...
It's getting harder to tell. But the RB5009 with PoE likely is a little to new for the robots to know. ;)

And /system/health isn't your beginner-friendly scripting task...
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Solar Powered Automatic POE Script

Wed Mar 29, 2023 1:31 am

Amm0, try this and you understand....

test code

{
:local testa 24.5
:local testb "24.5"
:put ($testa < $testb)
:put ($testa > $testb)
:put ($testa = $testb)
:put [:typeof $testa]
:put [:typeof $testb]
:put ($testa != $testb)
}
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3169
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: Solar Powered Automatic POE Script

Wed Mar 29, 2023 1:38 am

Is this a test to see if I'm a robot?

Oh I know that "casts" into an "ip" type, not a string...

It about "time" they fix this...

{
:local testa 524.5
:local testb "524.5"
:put ($testa < $testb)
:put ($testa > $testb)
:put ($testa = $testb)
:put [:typeof $testa]
:put [:typeof $testb]
:put ($testa != $testb)
}
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Solar Powered Automatic POE Script

Wed Mar 29, 2023 1:42 am

Time?
This is new...

test code

{
:local testa 524.5
:put [:typeof $testa]
:put $testa
}
Also the result is nice......


So... I deduce that:

"Function" / Hack to convert seconds to "RouterOS time elapsed":

deduced code

{
:local seconds 666666
:local time [[:parse ":return $seconds.000"]]
:put $time 
}
Result:
1w17:11:06

is the same for
:put [:totime 666666]
:lol: :lol: :lol:
Last edited by rextended on Wed Mar 29, 2023 2:07 am, edited 5 times in total.
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3169
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: Solar Powered Automatic POE Script

Wed Mar 29, 2023 1:46 am

Yeah if the digits with "." are below 255, then "ip" type. If not, then "time" assuming milliseconds. Super fun one.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Solar Powered Automatic POE Script

Wed Mar 29, 2023 2:08 am

It's time to go to sleep for me, bye.
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3169
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: Solar Powered Automatic POE Script

Wed Mar 29, 2023 2:20 am

It's time to go to sleep for me, bye.
Yeah that "timestamp" comes up. ;)
:put ([:timestamp] + [/system/health get [find where name="jack-voltage"] value] - [:timestamp])
(could be cleaner since you lose some time while it get the value – but I have work to actually do myself)

Who is online

Users browsing this forum: No registered users and 14 guests