blackfox Geschrieben June 22, 2013 at 23:35 Share Geschrieben June 22, 2013 at 23:35 Hello, I'm testing the weather station with PHP. For WeatherStationWebsite.php I use: <?php require_once('Tinkerforge/IPConnection.php'); require_once('Tinkerforge/BrickletAmbientLight.php'); require_once('Tinkerforge/BrickletHumidity.php'); require_once('Tinkerforge/BrickletBarometer.php'); use Tinkerforge\IPConnection; use Tinkerforge\BrickletAmbientLight; use Tinkerforge\BrickletHumidity; use Tinkerforge\BrickletBarometer; $ipcon = new IPConnection(); $brickletAmbientLight = new BrickletAmbientLight("enG", $ipcon); $brickletHumidity = new BrickletHumidity("eFY", $ipcon); $brickletBarometer = new BrickletBarometer("eUy", $ipcon); $ipcon->connect("localhost", 4223); $illuminance = $brickletAmbientLight->getIlluminance()/10.0; $humidity = $brickletHumidity->getHumidity()/10.0; $air_pressure = $brickletBarometer->getAirPressure()/1000.0; $temperature = $brickletBarometer->getChipTemperature()/100.0; $response = array ( "illuminance" => "Illuminance: $illuminance Lux", "humidity" => "Humidity: $humidity %RH", "air_pressure" => "Air Pressure: $air_pressure mbar", "temperature" => "Temperature: $temperature °C", ); print_r(json_encode($response)); ?> But the result is: {"illuminance":"Illuminance: 1.7 Lux","humidity":"Humidity: 68.6 %RH","air_pressure":"Air Pressure: 1001.318 mbar","temperature":null} What is the correct code to retrieve the temperature from the barometer bricklet? Zitieren Link zu diesem Kommentar Share on other sites More sharing options...
JavaLaurence Geschrieben June 23, 2013 at 09:47 Share Geschrieben June 23, 2013 at 09:47 Is the divide by 100 the problem? What does it produce if you don't divide at all? Zitieren Link zu diesem Kommentar Share on other sites More sharing options...
blackfox Geschrieben June 24, 2013 at 12:54 Autor Share Geschrieben June 24, 2013 at 12:54 I've changed the number into 10.0, 100.0, 1000.0 and 10000.0, but it all gave the same result, then I've removed the division altogether but the result stays on "null". Zitieren Link zu diesem Kommentar Share on other sites More sharing options...
borg Geschrieben June 24, 2013 at 13:42 Share Geschrieben June 24, 2013 at 13:42 "null" means probably that the object "null" is returned, not the integer 0. Are the PHP Bindings up to date? Zitieren Link zu diesem Kommentar Share on other sites More sharing options...
blackfox Geschrieben June 24, 2013 at 14:44 Autor Share Geschrieben June 24, 2013 at 14:44 PHP Version 5.4.4-14+deb7u2 BCMath support enabled include_path .:/usr/share/php:/usr/share/pear Recent download: pear install Tinkerforge.tgz And may I add that WeatherStation.php does work and gives me a correct temperature. But I cannot get a temperature with WeatherStationWebsite.php. Zitieren Link zu diesem Kommentar Share on other sites More sharing options...
borg Geschrieben June 24, 2013 at 15:09 Share Geschrieben June 24, 2013 at 15:09 If you print $temperature, is that also "null"? Your PHP seems to evaluate "Temperature: $temperature °C" as null. I am not sure why that is. Perhaps you can try to change the string bit for bit, to find what excatly the reason is! Zitieren Link zu diesem Kommentar Share on other sites More sharing options...
blackfox Geschrieben June 24, 2013 at 15:31 Autor Share Geschrieben June 24, 2013 at 15:31 It seems that the ° in front of the C causes the problem. By omitting the ° I get a response: {"illuminance":"Illuminance: 838.1 Lux","humidity":"Humidity: 61 %RH","air_pressure":"Air Pressure: 1013.163 mbar","temperature":"Temperature: 20.46 C"} Adding a ° gives always a null no mater where it is put. Is ° a not accepted character in PHP? Zitieren Link zu diesem Kommentar Share on other sites More sharing options...
borg Geschrieben June 24, 2013 at 18:32 Share Geschrieben June 24, 2013 at 18:32 That seems to be a string encoding problem. I just tested it on my PC, here the strings seem to be encoded as utf-8. You probably have to enable utf-8 encoding in your php.ini: http://stackoverflow.com/questions/1605760/how-to-best-configure-php-to-handle-a-utf-8-website Zitieren Link zu diesem Kommentar Share on other sites More sharing options...
blackfox Geschrieben June 26, 2013 at 23:49 Autor Share Geschrieben June 26, 2013 at 23:49 utf-8 encoding wasn't the problem. I fixed it as follows: Changed: "temperature" => "Temperature: $temperature °C" To: "temperature" => "Temperature: $temperature °C" Or: "temperature" => "Temperature: $temperature °C" So the °C was changed to &decC or to °C This gives the correct response: Temperature: 18.83 °C Zitieren Link zu diesem Kommentar Share on other sites More sharing options...
photron Geschrieben July 3, 2013 at 12:29 Share Geschrieben July 3, 2013 at 12:29 I changed the example to use ° to make it less error prone. Zitieren Link zu diesem Kommentar Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.