1

I have a php script that runs well.

<?php

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

closed as off-topic by lenik, syb0rg, Piotr Kula, Jivings May 1 '14 at 16:19

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question does not appear to be specific to the Raspberry Pi within the scope defined in the help center." – lenik, syb0rg, Piotr Kula, Jivings
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    M2X has a Python library, it would be much easier to just rewrite the script in Python. – Dan Nixon 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
6

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],
  • 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.