2

So first of all I have 2 Servers:

  1. Raspberry pi
  2. Linux Debian server

The pi has a script that displays the current Temperature in a room.

This is the script :

#!/bin/bash
i2cset -y 1 0x48 0xEE
dte=$(date +%Y-%m-%d)
tme=$(date +%H:%M:%S)
hexraw=$(i2cget -y 1 0x48 0xAA w)
msb=$(echo ${hexraw:4:2})
lsb=$(echo ${hexraw:2:1})
dec=$(printf "%d\n" "0x$msb$lsb")
temp=$(echo "scale=1; $dec/16" | bc)

echo $temp
exit

Displaying the temperature on the pi's website works fine. But then I have another script on the linux server that takes the value of the pi's script:

#!/bin/bash
x=$(ssh [email protected] sudo /home/pi/CurrTemp;)
echo $x

This works too. But when I want to display the Temp on my Linux server website(with shell_exec()) it doesn't work. The var_dump is empty.

PHP:

I've tried to write it with a "sudo".

I've changed the script owner to root.

1 Answer 1

2

ssh authentication does not work since the web server can't (and should) access your ssh keys.

You have to options (where the latter is definitely preferred!):

  • Create another ssh key for the web server on the Debian server and add to allowed_keys on the PI. You may restrict the key to allow only that command.

  • Create a little web service on the PI and output the temperature in plain text, xml, json or whatever. The use file_get_contents() to obtain the file over HTTP, like this using a plain text file:

temperature.php on raspberry pi:

<?php

echo shell_exec('/home/pi/CurrTemp');

temperature.php on Debian:

<?php

$temperature = file_get_contents('http://172.16.248.210/temperature.php');

echo $temperature;
6
  • Excuse me I forgot to mention that I already created a RSA key on the both sides. Do you mean writing the output of my "pi's" script in an json file ?
    – Poteito
    Commented Mar 27, 2015 at 16:04
  • No, you should output the value over HTTP. Just echo. Use plain text for first tests.
    – hek2mgl
    Commented Mar 27, 2015 at 16:08
  • So you mean i should ignore the one script on my linux server and put the output of the currTemp in HTTP ? and if yes how does it work ?
    – Poteito
    Commented Mar 27, 2015 at 16:48
  • On the pi's site im using .htaccess could that block the communication ?
    – Poteito
    Commented Mar 27, 2015 at 20:15
  • why don't you test this? I can't answer this, since I can't access your pi.
    – hek2mgl
    Commented Mar 27, 2015 at 20:16

Your Answer

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

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