Jump to content

WeatherStationWebsite.php gives no Temperature


Recommended Posts



I'm testing the weather station with PHP.


For WeatherStationWebsite.php I use:









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",







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?



Link to comment
Share on other sites

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?


Link to comment
Share on other sites

utf-8 encoding wasn't the problem.


I fixed it as follows:


Changed:  "temperature"  => "Temperature: $temperature °C"


To:      "temperature"  => "Temperature: $temperature &degC"


Or:      "temperature"  => "Temperature: $temperature &#176C"


So the °C was changed to &decC or to &#176C


This gives the correct response:  Temperature: 18.83 °C

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...