3

my Python script returns:

python /home/pi/sht/sht31.py
False
True
False
Temperature: 8.10668945312
Humidity: 83.49609375

I need to print humidity and Temperature into an index.php

I tried:

exec('sudo python /home/pi/sht/sht31.py' , $output);
var_dump($output);

but output is:

array(5) { [0]=> string(5) "False" [1]=> string(4) "True" [2]=> string(5) "False" [3]=>       string(26) "Temperature: 8.07464599609" [4]=> string(23) "Humidity: 83.5327148438" }

it is possible to extract only temperature and humidity ?

6
  • 1
    possible duplicate Commented Dec 14, 2019 at 23:13
  • 1
    can you modify the python script? If yes, then I suggest to change it to write out its output in json format. If not, then you have multiple choices. If you know, that temperature is always in the 5th line, split the poutput by '\n', take the fifth entry, explode it by white space and take the second entry Commented Dec 14, 2019 at 23:14
  • 1
    Modifiy the python script to not print the True/False values Commented Dec 14, 2019 at 23:15
  • 1
    I removed true and false but print is similar : array(2) { [0]=> string(25) "Temperature: 8.4912109375" [1]=> string(23) "Humidity: 81.3537597656" } Commented Dec 14, 2019 at 23:20
  • 1
    You have an array with Temperature and Humidity, isn't that what you need? echo $output[3]; for Temperature and echo $output[4]; for Humidity Commented Dec 14, 2019 at 23:38

1 Answer 1

0

You can add this into your code and when you run it add the two files for example: python ex0.py ex0.txt ex1.txt I hope this helps if it doesn't sorry have a great day

from sys import argv
from os.path import exists

script, from_file, to_file = argv 
print ("Copying from %s to %s.") % (from_file, to_file)

in_file=open(from_file)
indata= in_file.read()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.