I have a php script that runs well.


include_once "lib/m2x.php";

$api_key = "API KEY";
$feed_id = "FEED ID";
$stream  = "something";

$m2x = new M2X($api_key);

$data = array(
  'value' => 992.23,
  'unit'  => array('label' => 'Celsius')
$response = $m2x->feeds()->update_stream('FEED ID', $stream, $data);


However, I want to be able to update the 'value' variable from my raspberry pi, then rerun the script to send that data. Is there a way in python to update this variable (getting data in from GPIO) then run the php script?

Thanks, Mihir

  • 1
    M2X has a Python library, it would be much easier to just rewrite the script in Python. – user8894 Apr 20 '14 at 6:45
  • what stops you from sudo apt-get install php5 and then running your script on Raspberry? – lenik Apr 20 '14 at 9:15
  • @DanNixon thanks! I just noticed that they have a python library. I'll see if I can use that instead. It'll probably save me a lot of time :) – user2888826 Apr 20 '14 at 17:09
  • @lenik The problem with that is I need to continously change a variable within the script, then re-run it. – user2888826 Apr 20 '14 at 17:10

You can call the php Script using python's os.system:

import os
value = 992.23
os.system("php /path/to/your/file.php %s"%(value))

in you php file, just specify the value as given per command line:

'value' => $argv[1],
| improve this answer | |
  • 1
    Did it work? If so, consider accepting the answer. – Bex Apr 21 '14 at 8:23

Not the answer you're looking for? Browse other questions tagged or ask your own question.