Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
PowerHome Programming
 PowerHome Messageboard : PowerHome Programming
Subject Topic: help with python Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
krommetje
Super User
Super User
Avatar

Joined: December 29 2004
Location: Netherlands
Online Status: Offline
Posts: 695
Posted: March 16 2016 at 05:24 | IP Logged Quote krommetje

Hi all,

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 View krommetje's Profile Search for other posts by krommetje Visit krommetje's Homepage
 
nick7920
Senior Member
Senior Member


Joined: March 04 2008
Location: United States
Online Status: Offline
Posts: 193
Posted: March 20 2016 at 11:52 | IP Logged Quote nick7920

I dont know much about python but cant you just send
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 View nick7920's Profile Search for other posts by nick7920
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: March 23 2016 at 15:58 | IP Logged Quote dhoward

Peter,

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 View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum