ERROR: Couldn't determine iptables version

root@tubzpi:~# journalctl -u fan
-- Journal begins at Fri 2023-05-12 01:25:01 BST, ends at Sat 2023-05-13 16:20:5                                                                                        3 BST. --
May 12 10:52:00 tubzpi.xyz systemd[1]: Started Custom fan script.
May 12 10:52:01 tubzpi.xyz fan.py[167896]: 34.9c: <40 : choosing fan reg 0x7
May 12 10:52:05 tubzpi.xyz fan.py[167896]: 34.3c: <40 : choosing fan reg 0x7
May 12 10:52:09 tubzpi.xyz fan.py[167896]: 34.9c: <40 : choosing fan reg 0x7
May 12 10:52:13 tubzpi.xyz fan.py[167896]: 34.3c: <40 : choosing fan reg 0x7
May 12 10:52:17 tubzpi.xyz fan.py[167896]: 34.3c: <40 : choosing fan reg 0x7
May 12 10:52:21 tubzpi.xyz fan.py[167896]: 34.9c: <40 : choosing fan reg 0x7
May 12 10:52:25 tubzpi.xyz fan.py[167896]: 34.3c: <40 : choosing fan reg 0x7
May 12 10:52:29 tubzpi.xyz fan.py[167896]: 34.3c: <40 : choosing fan reg 0x7
May 12 10:52:33 tubzpi.xyz fan.py[167896]: 34.3c: <40 : choosing fan reg 0x7
May 12 10:52:37 tubzpi.xyz fan.py[167896]: 34.3c: <40 : choosing fan reg 0x7
May 12 10:52:41 tubzpi.xyz fan.py[167896]: 34.3c: <40 : choosing fan reg 0x7
May 12 10:52:45 tubzpi.xyz fan.py[167896]: 34.9c: <40 : choosing fan reg 0x7
May 12 10:52:45 tubzpi.xyz fan.py[167896]: Traceback (most recent call last):
May 12 10:52:45 tubzpi.xyz fan.py[167896]:   File "/root/fan/fan.py", line 44, i                                                                                        n setrgb
May 12 10:52:45 tubzpi.xyz fan.py[167896]:     bus.write_byte_data(addr,0x00,0xf                                                                                        f)
May 12 10:52:45 tubzpi.xyz fan.py[167896]: OSError: [Errno 121] Remote I/O error
May 12 10:52:45 tubzpi.xyz fan.py[167896]: During handling of the above exceptio                                                                                        n, another exception occurred:
May 12 10:52:45 tubzpi.xyz fan.py[167896]: Traceback (most recent call last):
May 12 10:52:45 tubzpi.xyz fan.py[167896]:   File "/root/fan/fan.py", line 115,                                                                                         in <module>
May 12 10:52:45 tubzpi.xyz fan.py[167896]:     setrgb(rgb[0],rgb[1],rgb[2],rgb[3                                                                                        ])
May 12 10:52:45 tubzpi.xyz fan.py[167896]:   File "/root/fan/fan.py", line 55, i                                                                                        n setrgb
May 12 10:52:45 tubzpi.xyz fan.py[167896]:     print("setrgb [0]:" + exc_tuple[0                                                                                        ] + " [1]:" + exc_tuple[1] + " [2]:" + exc_tuple[2])
May 12 10:52:45 tubzpi.xyz fan.py[167896]: TypeError: can only concatenate str (                                                                                        not "type") to str
May 12 10:52:45 tubzpi.xyz systemd[1]: fan.service: Main process exited, code=ex                                                                                        ited, status=1/FAILURE
May 12 10:52:45 tubzpi.xyz systemd[1]: fan.service: Failed with result 'exit-cod                                                                                        e'.

Can you print the content of fan.py or send a link? There seems to be a bug inside, probably due to a changed API when it tries to get the rgb for >35 °C or so.

1 Like

Sorry for the late reply,

import smbus
import time
import os
import sys
from datetime import datetime
from array import *

def setfanspeed(oVal):
    try:
        bus.write_byte_data(addr, fan_reg, oVal)
    except:
        exc_tuple = sys.exc_info()
        print("setfanspeed [0]:" + exc_tuple[0] + " [1]:" + exc_tuple[1] + " [2]:" + exc_tuple[2])

def setRGBEffect(effect):
    try:
        if effect >= 0 and effect <= 4:
            bus.write_byte_data(addr, rgb_effect_reg, effect&0xff)
    except:
        exc_tuple = sys.exc_info()
        print("setRGBEffect [0]:" + exc_tuple[0] + " [1]:" + exc_tuple[1] + " [2]:" + exc_tuple[2])

def setRGBSpeed(speed):
    try:
        if speed >= 1 and speed <= 3:
            bus.write_byte_data(addr, rgb_speed_reg, speed&0xff)
    except:
        exc_tuple = sys.exc_info()
        print("setRGBSpeed [0]:" + exc_tuple[0] + " [1]:" + exc_tuple[1] + " [2]:" + exc_tuple[2])

def setRGBColor(color):
    try:
        if color >= 0 and color <= 6:
            bus.write_byte_data(addr, rgb_color_reg, color&0xff)
    except:
        exc_tuple = sys.exc_info()
        print("setRGBColor [0]:" + exc_tuple[0] + " [1]:" + exc_tuple[1] + " [2]:" + exc_tuple[2])

def setrgb(num,r,g,b):
    try:
        #turn lights off first
        #bus.write_byte_data(addr, rgb_off_reg, 0x00)
        if num >= max_led:
            bus.write_byte_data(addr,0x00,0xff)
            bus.write_byte_data(addr,0x01,r&0xff)
            bus.write_byte_data(addr,0x02,g&0xff)
            bus.write_byte_data(addr,0x03,b&0xff)
        elif num >= 0:
            bus.write_byte_data(addr,0x00,num&0xff)
            bus.write_byte_data(addr,0x01,r&0xff)
            bus.write_byte_data(addr,0x02,g&0xff)
            bus.write_byte_data(addr,0x03,b&0xff)
    except:
        exc_tuple = sys.exc_info()
        print("setrgb [0]:" + exc_tuple[0] + " [1]:" + exc_tuple[1] + " [2]:" + exc_tuple[2])


bus = smbus.SMBus(1)
addr = 0x0d
fan_reg = 0x08
state = 0
temp = 0
level_temp = 0
rgb_effect_reg = 0x04
rgb_speed_reg = 0x05
rgb_color_reg = 0x06
rgb_off_reg = 0x07
max_led = 3
rgb = [0x00, 0x00, 0x00, 0x00]

bus.write_byte_data(addr, rgb_off_reg, 0x00)
time.sleep(1)
setRGBEffect(1)
setRGBSpeed(3)
setRGBColor(4)


while True:
    cmd = os.popen('vcgencmd measure_temp').readline()
    CPU_TEMP = cmd.replace("temp=","").replace("'C\n","")
    temp = float(CPU_TEMP)

    if abs(temp - level_temp) >= 1:
        if temp <= 40:
            level_temp = 40
            fan_speed = 0x7
            rgb = [max_led, 0x00, 0x00, 0xff]
        elif temp <= 45:
            level_temp = 0x7
            fan_speed = 0x7
            rgb = [max_led, 0x1e, 0x90, 0xff]
        elif temp <= 47:
            level_temp = 47
            fan_speed = 0x08
            rgb = [max_led, 0x00, 0xbf, 0xff]
        elif temp <= 49:
            level_temp = 49
            fan_speed = 0x06
            rgb = [max_led, 0x5f, 0x9e, 0xa0]
        elif temp <= 51:
            level_temp = 51
            fan_speed = 0x09
            rgb = [max_led, 0xff, 0xff, 0x00]
        elif temp > 51:
            level_temp = 52
            fan_speed = 0x01
            rgb = [max_led, 0xff, 0x00, 0x00]
        else:
            level_temp = 0
            fan_speed = 0x01
            rgb = [max_led, 0xff, 0xff, 0xff]
            print('Something wrong: choosing fan reg 0x01 instead')
    setfanspeed(fan_speed)
    print(CPU_TEMP + 'c: <' + str(level_temp) + ' : choosing fan reg ' + str(hex(fan_speed)))
    setrgb(rgb[0],rgb[1],rgb[2],rgb[3])
    sys.stdout.flush()
    time.sleep(4)