0

I wanted to display IP address using MAX7219 and SPI on the startup.

I followed instructions on web page Getting a Python script to run in the background (as a service) on boot. Script is loaded as required, but the process does not start. On the other hand, by starting script manually, everything is OK.

I suspect that problem might be in the fact that script starts before spidev is loaded. Or is there anything else wrong? Can you help me with this?

Here is also code in case you need it:

#!/usr/bin/env python

import max7219.led as led
import time
from subprocess import Popen, PIPE

def run_cmd(cmd):
    p = Popen(cmd, shell=True, stdout=PIPE)
    return(p.communicate()[0].rstrip())

addr = '  ' + run_cmd("ip addr show wlan0 | grep 'inet ' | awk '{print $2}' | cut -d/ -f1")

dots = [False]*(len(addr)-3)

pos=-1
for i in range(0,3):
    pos = addr.find('.', pos+1)
    dots[pos-i-1] = True
addr = addr.replace('.','')

device = led.sevensegment()

pos = 0
while True:
    addrs=addr[-pos:]+addr[:-pos]
    dotss=dots[-pos:]+dots[:-pos]
    for i in range(0,8):
        device.letter(deviceId=0,position=8-i,char=addr[i],dot=dots[i])
    time.sleep(1)
    pos=pos-1
    if pos == -len(addr): pos=0
1

Just add a shellscript code in rc.local to check lsmod | grep -c <your_module_name> greater than zero, and start your python code after it's loaded. or - just load it via modprobe in rc.local.

  • If I understand you right, your answer is not about correcting the described problem but about proposing of a new solution? – Pygmalion Apr 16 '16 at 13:59
  • @Pygmalion yes, the solution is new, but it solves not just this problem, but a packo of similar ones. I fount it myself with a very odd behaviour of some RTL chipset based WiFi USB dongles : it boots, no auto-load of driver, lsusb states the device, iwconfig and ifconfig seems not to be recognizing it. Auto-loading in boot config does not solves the issue! WTF?! But this rc.local tweak works just like a charm... – Alexey Vesnin Apr 16 '16 at 19:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.