Editing code for more fan levels

Can @Setq help to advise on which areas of the code to adjust for more fan steps? I’m looking at 0%, 20%, 40%, 60%, 80% and 100%… this is to help a more granulated approach to the cooling solution and to help balance acoustics if possible…

Editing the file misc.py by inputing the command sudo nano /usr/bin/rockpi-sata/misc.py

change lv2dc = {'lv3': 100, 'lv2': 75, 'lv1': 50, 'lv0': 25}
to lv2dc = {'lv4': 100, 'lv3': 80, 'lv2': 60, 'lv1': 40, 'lv0': 20}

add conf['fan']['lv4'] = cfg.getfloat('fan', 'lv4')
to after conf['fan']['lv3'] = cfg.getfloat('fan', 'lv3')

changing the following values:
conf['fan']['lv0'] = 35
conf['fan']['lv1'] = 40
conf['fan']['lv2'] = 45
conf['fan']['lv3'] = 50
conf['fan']['lv4'] = 55

Also remember to edit the conf file to add lv4

Anything else I am missing?

Hello, eskimo

There’s nothing missing. That’s all.

What do I need to modify or add if I want to display fan speed in % on the oled display together with CPU/mem usage?

Prefer in the format “Fan Speed: 50%”…

Modify the gen_pages function of oled.py

What’s the arguments needed to display? I can’t really figure it out what calls to make… (I’m an architect, not a programmer… lol)

edit: after modifying the misc.py, now the OLED display only shows loading…

I’ll add it when I have time, and I’ll let you know.

I figured it out after like 50 trial and errors… reproducing what i did below for those who also want to display the fan speed on your oled…

i added import fan to the header portion, then changed the gen_pages() to this:

def gen_pages():
    fanspeed = fan.get_dc()
    pages = {
        0: [
            {'xy': (0, -2), 'text': misc.get_info('up'), 'fill': 255, 'font': font['11']},
            {'xy': (0, 10), 'text': misc.get_cpu_temp(), 'fill': 255, 'font': font['11']},
            {'xy': (0, 21), 'text': misc.get_info('ip'), 'fill': 255, 'font': font['11']},
        1: [
            {'xy': (0, -2), 'text': misc.get_info('cpu'), 'fill': 255, 'font': font['11']},
            {'xy': (0, 10), 'text': misc.get_info('men'), 'fill': 255, 'font': font['11']},
            {'xy': (0, 21), 'text': 'Fan Speed: {}%'.format(fanspeed), 'fill': 255, 'font': font['11']},
        2: put_disk_info()
1 Like

Thank you for sharing.

@setq, wanna check with you if it is possible to independently control the fan speed of the cpu?

Quad Sata hat been running more than a day now… noticed that the “Uptime” display on the oled will get cut off to show "1day 10:" and the balance text is all cut off… i think the script command may not be effectively crimping the uptime output correctly…

suggest replace
uptime | sed 's/^.* up \+\(.\+\), \+[0-9] user.*$/\\1/' | awk '{printf \"Uptime: %s\", $0}'
uptime | cut -c 14- | cut -b -12 | sed 's/day/d/g;s/\:/h/g' | awk '{print "Uptime: " $1 $2 $3 "m"}'

the second command will give me an output of "Uptime: 1d,9h14m" which should fit into the display even up to 100days uptime… havent tested it out yet though, maybe will test it over the weekend… @setq maybe can give some comments on this?

EDIT: DO NOT USE THE ABOVE… IT CRASHED THE SYSTEM HARD! still need to figure out what went wrong…

edit2: did a tiny python script to debug where it went wrong… forgotten some syntax…
uptime | cut -c 14- | cut -b -12 | sed 's/day/d/g;s/\:/h/g' | awk '{print \"Uptime: \" $1 $2 $3 \"m\"}'

Thank you for your advice.

It can be controlled independently, and I’ll add it in the next version.

To reply to myself… i found a more elegant solution after poking around python script and shell commands (i never did programming in my life, EVER)…

uptime2 = subprocess.getoutput("uptime -p | sed 's/day,/d/g;s/hour,/h/g;s/minutes/m/g;s/minute/m/g' | awk '{print \"Uptime: \" $2 $3,$4 $5 $6 $7}'")

which properly outputs Uptime: 1h 39m and should also catch the day portion…

explanation thought process:

  • uptime -p command produces up 1 hour, 45 minutes as opposed to having to parse the full output from just uptime alone.
  • using sed command to replace day, with d, hour, with h and minutes/minute with m
  • use awk to piece the whole thing together. will test again when my system hits more than 1day.

Amazing! Thank you for trying.

Hi eskimo.!

So in the file


we can replace:

‘up’: “uptime | sed ‘s/^.* up +(.+), +[0-9] user.*$/\1/’ | awk ‘{printf “Uptime: %s”, $0}’”,


‘up’: “uptime -p | sed ‘s/day,/d/g;s/hour,/h/g;s/minutes/m/g;s/minute/m/g’ | awk ‘{print "Uptime: " $2 $3,$4 $5 $6 $7}’”,

Just checking with you, so i don’t do anything ‘stupid’ on my setup…!

U might wanna hold off changing for a while first till I can get it tested on my nas… been having strange reboots occuring almost daily around 5-7am…

edit: i suspected by strange reboots happen because of watchdog and OMV… disabled watchdog, things seems normal now…

edit2: nope, disabling watchdog doesnt help… still random reboots…

ok, i tested it out on my system, didnt crash… so it should work… here’s the steps:

  1. open the oled.py for edit using sudo nano /usr/bin/rockpi-sata/oled.py
  2. under import fan, add import subprocess
  3. under def gen_pages(): add the line uptime = subprocess.getoutput("uptime -p | sed 's/years,/yr/g;s/year,/yr/g;s/year/yr/g;s/months,/M/g;s/month,/M/g;s/month/M/g;s/weeks,/w/g;s/week,/w/g;s/week/w/g;s/days,/d/g;s/day,/d/g;s/day/d/g;s/hours,/h/g;s/hour,/h/g;s/hour/h/g;s/minutes/m/g;s/minute/m/g' | awk '{print \"Up: \" $2 $3,$4 $5 $6 $7 $8 $9 $10 $11}'")
  4. replace {'xy': (0, -2), 'text': misc.get_info('up'), 'fill': 255, 'font': font['11']},
    with {'xy': (0, -2), 'text': '{}'.format(uptime), 'fill': 255, 'font': font['11']},
  5. reboot

edit: if the text gets too long, can consider replacing “Uptime:” with just “Up:”
edit2: realised that uptime -p also uses weeks months and years for uptime, edited the code to take these into consideration…