Python Forum
[split] Check presence of a file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[split] Check presence of a file
#11
Snippsat,
Thank you so much, it works
#! bash/bin/python3  
def read_sensor(sensorID):  
    tempfile = open("/sys/bus/w1/devices/"+ sensorID +"/w1_slave")
    thetext = tempfile.read()
    tempfile.close()
    tempdata = thetext.split("\n") [1].split(" ")[9]
    temperature = float(tempdata[2:])
    temp_sensor = temperature / 1000
    return (temp_sensor)
And:
from mySensorModule import read_sensor
from mySensors import sensorsID
import time

# accessing a dictionary: dict_name[key] = value
sID1 = sensorsID['solar_panel']
sID2 = sensorsID['cyl_bottom']
x = 5
while 1:
    read_sensor(sID1) + x > read_sensor(sID2)
    print("it's Hot!")
    time.sleep(1)
else:
    print("Got it wrong again Dad")
prints "it's hot"
Thank you!! Smile
I can see why you are administrator Big Grin
The next step is GPIO
REGARDS
Paul
Reply
#12
from mySensorModule import read_sensor
from mySensors import sensorsID
import time
 
# accessing a dictionary: dict_name[key] = value
sID1 = sensorsID['solar_panel']
sID2 = sensorsID['cyl_bottom']
x = 5
while True:
    if read_sensor(sID1) + x > read_sensor(sID2):
        print("it's Hot!")
    else:
        print("Got it wrong again Dad")
    time.sleep(1)
Reply
#13
Thanks gontajones
Your code works a treat!!!
I am now adding the RPi.GPIO code, I have resolved the code errors for the moment but the pump is not comming on, and the light has gone out on the relay?
Here is the new code
from mySensorModule import read_sensor
from mySensors import sensorsID
import time
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)
GPIO.setup(25,GPIO.OUT)
# accessing a dictionary: dict_name[key] = value
sID1 = sensorsID['solar_panel']
sID2 = sensorsID['cyl_bottom']
x = 5
try:
    while True:
        read_sensor(sID1) + x > read_sensor(sID2)
        GPIO.output(25,GPIO.HIGH)
        print("it's Hot!")
        time.sleep(1)
    else:
        print("Got it wrong again Dad")
        GPIO.output(25,GPIO.LOW)
   
except KeyboardInterrupt:
    GPIO.cleanup()
I have less understanding of GPIO than pyhon!
Not to sure if I should start another thread as this is a raspi GPIO problem now. Thanks to you guys I am beginning to understand this Smile
Kind regards
Paul
Reply
#14
from mySensorModule import read_sensor
from mySensors import sensorsID
import time
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)
GPIO.setup(25, GPIO.OUT)
# accessing a dictionary: dict_name[key] = value
sID1 = sensorsID['solar_panel']
sID2 = sensorsID['cyl_bottom']
x = 5
try:
    while True:
        # Here you have to use the IF-ELSE
        if read_sensor(sID1) + x > read_sensor(sID2):
            GPIO.output(25, GPIO.HIGH)
            print("it's Hot!")
        else:
            print("Got it wrong again Dad")
            GPIO.output(25, GPIO.LOW)
        time.sleep(1)

except KeyboardInterrupt:
    GPIO.cleanup()
Reply
#15
Hi gontajones
Thanks for looking at my script, I will change mine and test tommorrow (wife home now)
I am trying to find out if it is best to use pythons RPi.GPIO or wiringpi?
Thank you all again for your kind imput
Regards
Paul
Reply
#16
Both modules are very good.
But I've been using RPi.GPIO.
Reply
#17
Hi gontajones
evening here the temperatures have changed my unmodified script still gives "its hot", once modified, it returns the correct reply, but obviously the pump wont start, so I am not sure if the script is working the GPIO's. when I last looked the red light for the relay had gone out, indicating 0 volts I think.
I want this script to check and compare the temperatures at regular intervals, when the first condition is meet I want it to turn on the relay, leaving the relay on until the condition is no longer meet.
Not really understanding this yet, is that what this code does?
Kind regards
Paul
Reply
#18
Quote:Not really understanding this yet, is that what this code does?
Yes!
Are you sure that your relay is powered and it activates with HIGH state (some cases it activates with LOW)?
Reply
#19
Photo 
Hi gontajones
The relay is an eight module 12 volt type, at the moment I am trying to use only one module, the technical description states each module uses 1.5v, I have all 8 modules connected, each is lit up, I have a 240volt lamp attached for the moment to see if the code operates the relay. to the output ports of the relay I have connected the live to the center, and the live out to the right side, (the neutrals are joined seperately)relay setup like in this tutorial, I understand that to use all eight relays I will have to use an external power source. Before the code the small red light on the module was on but dim, I activated the code, the the small red light on the module went bright for a second or so and then went out completely. When I
Quote:gpio readall
in terminal it indicated that all gpio were 1 except "25" which was 0.
I added the "its hot" and "dad got it wrong again" to see if the code worked and the time of sleep otherwise it printed "its hot" non stop until I pressed Ctrl+C !!!
I am now going to remove these parts and see what happens
Kind regards
Paul

ps I have just commented out these parts for now rather than remove them
Reply
#20
pascale, please post your entire code (every file) to let us help you.
Maybe you read)sensor() is not returning what you're expecting.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to "tee" (=split) output to screen and into file? pstein 6 1,406 Jun-24-2023, 08:00 AM
Last Post: Gribouillis
  Split pdf in pypdf based upon file regex standenman 1 2,100 Feb-03-2023, 12:01 PM
Last Post: SpongeB0B
  please check this i wanna use a csv file as a graph xCj11 5 1,506 Aug-25-2022, 08:19 PM
Last Post: deanhystad
  check if a file exist on the internet and get the size kucingkembar 6 1,794 Apr-16-2022, 05:09 PM
Last Post: kucingkembar
  How to split file by same values from column from imported CSV file? Paqqno 5 2,802 Mar-24-2022, 05:25 PM
Last Post: Paqqno
  [split] Results of this program in an excel file eisamabodian 1 1,585 Feb-11-2022, 03:18 PM
Last Post: snippsat
  Code to check folder and sub folders for new file and alert fioranosnake 2 1,952 Jan-06-2022, 05:03 PM
Last Post: deanhystad
  split txt file data on the first column value shantanu97 2 2,447 Dec-29-2021, 05:03 PM
Last Post: DeaD_EyE
  [split] Help- converting file with pyton script eltomassito 6 3,281 Jul-02-2021, 05:29 PM
Last Post: snippsat
  Check last time file was accessed Pavel_47 4 2,843 Jun-01-2021, 05:47 PM
Last Post: Yoriz

Forum Jump:

User Panel Messages

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