Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Running from boot
#1
I am trying to run a DS18B20 temp sensor to trigger a relay. My code works in Thonny on a Rasp Pi4b. I am using sudo crontab -e and adding:
@reboot python /home/pi/DS18B20SensorRelay.py

The path shown is correct. While the program runs in Thonny, it won't run at sudo reboot. In the terminal I get the following message:

Running at boot
Traceback (most recent call last):
from w1thermsensor import W1ThermSensort
Import Error: No module named w1thermsensor.

I loaded the module again in it seemed to load correctly. The program still runs in Thonny. Not sure what is going on.
PS I loaded a simple LED blink program and it ran at boot, so the problem has to be with the w1thermister module.

My code starts like this:
import RPi.GPIO as GPIO
from w1thermsensor import W1ThermSensor
import time

the rest is the code to turn on the rely at a certain temp.

Appreciate any help. Like does the w1thermsensor module have to be in a certain directory. I just let it load and let Pi decide.
Reply
#2
you could add to your .bashrc script
Reply
#3
(Nov-03-2020, 03:19 AM)Larz60+ Wrote: you could add to your .bashrc script

I appreciate your help, but I'm very new to Python and pi and I'm not sure what a .baschrc script is. I've seen bash mentioned somewhere but I'd be lost. I'll try to look up what I can about bash scripts. Thanks for the shout.
Reply
#4
that only applies if you are using Linux. It's not related to python, but can be used to start programs upon boot (if you are running bash shell).

This looks like a pretty good tutorial: https://medium.com/@tzhenghao/a-guide-to...c52e466b1c

you can also google for '.bashrc tutorial' which will show several video tutorials as well
Reply
#5
Thanks I did a little reading on my own and discovered a bit a bout bash the how it uses the GNU core utilities. I didn't see anything on .bashrc so appreciate you pointing me in the right direction.
Reply
#6
(Nov-02-2020, 08:59 PM)Murray6301 Wrote: I loaded the module again in it seemed to load correctly. The program still runs in Thonny. Not sure what is going on.
PS I loaded a simple LED blink program and it ran at boot, so the problem has to be with the w1thermister module.
Thonny comes with own build Python version.
This Python version will not be used when you do @reboot python(now it will use OS python version).
So two ways try to give path to where Thonny's python version is placed.
Or install w1thermsensor to OS Python version pip install w1thermsensor.
From command line test python -V or python3 -V,same with pip pip3 -V it most point to a Python 3.6+ version as Python 2 is dead💀

Using OS python:
@reboot python3 /home/pi/DS18B20SensorRelay.py &
Using Thonny python:
@reboot path_to_thonny/python /home/pi/DS18B20SensorRelay.py &
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Script won't run at boot ebolisa 6 2,474 Mar-21-2020, 08:18 PM
Last Post: ebolisa
  Console crash after boot. friendlymegalomaniac 1 2,555 Apr-07-2018, 05:44 PM
Last Post: wavic
  find my system is single boot or dual boot using python Sachin_d 2 2,768 Nov-02-2017, 09:29 AM
Last Post: Sachin_d

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020