GioExperience
IoT, computer technology and other things
Not hobby, real stuff



Proudly made by myself
Welcome, my name is Giovanni, a 35 years old italian engineer that would like share his experience in IoT, electronic, raspberry, arduino, electrotechnic, and others things. In this blog i will try to realize a different approch to these stuff. It’s not a hobby or a toys…. I will try to explain my practical, pragmatical and REAL approch for building REAL, SAFE, and RELIABLE utilities.
all posts



1.03 Reading the DS18B20, prepare some libraries

I write scripts in bash and php7. I work in the

/var/www/html

directory because in future we will write a nice WebApp. Well… begin create a path /include/ where we write some library and configuration file. And a path /script/ where we write scripts launched from the CRON.

I suggest to use WinSCP [click here]… a beautiful software that consent to you to write and modify in the raspberry like a network-path… but through ssh!

The init.php file

I wrote a file called init.php in the /include/ path… And this file include all other library files… In this way when I want to write a script I just include this.
Here is the file /include/init.php

read())) 
{
   if($e==\\\".\\\" || $e==\\\"..\\\") continue;
   if( substr($e,0,4)==\\\"lib_\\\" ) include(__DIR__.\\\"/\\\".$e);
}
$d->close();

define(\\\'PIN_RELAY_STOVE\\\',22);
define(\\\'PIN_SOLENOIDVALVE_F0\\\',17);   //floor zero
define(\\\'PIN_SOLENOIDVALVE_F1\\\',23);   //floor one

define(\\\'TEMP_Z\\\', \\\"28-00000677ca05\\\"); //external sensor
define(\\\'TEMP_F0\\\',\\\"28-00044cfb6bff\\\"); //floor zero
define(\\\'TEMP_F1\\\',\\\"28-00044eea7aff\\\"); //floor one
define(\\\'TOLERANCE\\\',1); //Celsius

//for write or read threshold temperature in floor $nfloor
function threshold($nfloor,$t=999)
{
   $file=__DIR__.\\\"/threshold_F{$nfloor}.txt\\\";
   if(!file_exists($file)) 
   file_put_contents($file,\\\"14\\\"); //default for first time

   if( $t<999 )  file_put_contents($file,$t);

   $x=round(file_get_contents($file),1);
   return $x;
}

?>
*********

The first part of the code is for avoid cache. In CLI script, is useless to avoid cache, i know… but the same init.php may be used for web script or web page…
In the second part of the script, I include ALL FILES that begin with “lib_” and after i define some constants… Physical address of our sensors, and the pin number corresponding to relais. We will view detailing after.

I wrote a function for read or write the temperature that i want to maintain in every floor (threshold). I think that the simplest solution is write this in two files. For the first time the threshold is 14°Celsius. When I want to modify the temperature in my house I write in these files…. obviously not manualy but with a beatiful webApp… that we see in future.

My lib_gpio file

I usualy programming with layers. I wrote a libray lib_gpio.php that wrap WiringPi library (seen here) and the DS18B20 (seen here).
Note that I will use ALWAYS the BCM_GPIO notation for the gpio pins.
Here the /include/lib_gpio.php

As you saw, I only wrap the WiringPI library and add a cache system for the temperature. In reality my library is more complicated like that… but I want to explain other things on other posts.
In the next post we attach relais board and finaly see the thermostat script.