| Author |  | 
      
        | krommetje Super User
 
  
  
 Joined: December 29 2004
 Location: Netherlands
 Online Status: Offline
 Posts: 695
 | 
          Hi all,
           | Posted: March 16 2016 at 05:24 | IP Logged |   |  
           | 
 |  
 I am working on a raspberry pi to measure temperatures and want
 python to send the measurements to ph. I have an examplescript:
 I am unable to read multple sensors (DS18b20) for some reason so I
 have to connect all 4 sensors to seperate GPIO's....
   
 first I want to make it work with 1 sensor....
 
 
 
| Code: 
 
    
    | 
      
       | import os
 import glob
 import time
 
 os.system('modprobe w1-gpio')
 os.system('modprobe w1-therm')
 
 base_dir = '/sys/bus/w1/devices/'
 device_folder = glob.glob(base_dir + '28*')[0]
 device_file = device_folder + '/w1_slave'
 
 def read_temp_raw():
 f = open(device_file, 'r')
 lines = f.readlines()
 f.close()
 return lines
 
 def read_temp():
 lines = read_temp_raw()
 while lines[0].strip()[-3:] != 'YES':
 time.sleep(0.2)
 lines = read_temp_raw()
 equals_pos = lines[1].find('t=')
 if equals_pos != -1:
 temp_string = lines[1][equals_pos+2:]
 temp_c = float(temp_string) / 1000.0
 temp_f = temp_c * 9.0 / 5.0 + 32.0
 return temp_c, temp_f
 
 while True:
 print(read_temp())
 time.sleep(10)
 
 |  |  |  
 this code reads gpio4 and takes a temperature measurement every 10
 seconds but can be altered for A longer time. Can the code
 print(read_temp() be replaced by a method to send this to ph using
 an eval formula e.g or another method? I am a newbie on python so
 sorry if the question is "too simple" so to speak....
 
 
  sorry for the typos 
 Edited by krommetje - March 16 2016 at 05:26
 | 
       
        | Back to Top |       | 
       
       
        |  | 
        | nick7920 Senior Member
 
  
 
 Joined: March 04 2008
 Location: United States
 Online Status: Offline
 Posts: 193
 | 
          I dont know much about python but cant you just send
           | Posted: March 20 2016 at 11:52 | IP Logged |   |  
           | 
 |  data to PH by web access from it.
 
 just an idea you will have to see how to play with
 following have not tried it- look into ph_macroparmret
 it will load your data into LOCAL variable and you can
 take it from their.
 
 http://testuser:testpass@123.456.789.1 23:5555/ph-
 cgi/eval?formula=ph_macroparmret("TEST1",read_temp())
 
 
 Nick
 | 
       
        | Back to Top |     | 
       
       
        |  | 
        | dhoward Admin Group
 
  
  
 Joined: June 29 2001
 Location: United States
 Online Status: Offline
 Posts: 4447
 | 
          Peter,
           | Posted: March 23 2016 at 15:58 | IP Logged |   |  
           | 
 |  
 Never really dabbled with Python so cant offer much
 but like Nick says, I would just replace the Python
 "Print" statement with whatever the equivalent call is
 for Python to make a web call (probably the easiest
 way to get data into PowerHome from the Pi).
 
 If the Pi is going to be on the same network as the
 PowerHome machine and has access to a shared "drive"
 or file location, you could then also just have the Pi
 write the value to the shared drive and then use the
 PowerHome File Monitor plugin to trigger on a file
 change and get the data that way.
 
 Dave.
 
 | 
       
        | Back to Top |       | 
       
       
        |  |