SmartHome Project : Website

Hello everyone. This week no course was planned but we decide to continue to work on the SmartHome project. Last week, we explained how to fill a database with Mysql and we described the communication between the Raspberry Pi and the Arduino card. Now, we will describe how we communicate with the Rasperry Pi and the database to give the setpoint for the luminosity value and how we can see the database. To do that, we will use a website done with php.

Look below for an example of the php code, it is just a test and not a definitive code but it allows us to understand how to communicate between a website and a database stored on the Rasperry Pi:






<h1 class=”k1 mrg”>Bievenue sur la page de gestion de votre eclairage</h1>


Commande de l’eclairage de l’installation :

<input type=”button” name=”Commande” value=”Commande” onclick=”self.location.href=’instruction3.php'” style=”background-color:#FFFFFF” style=”color:white; font-weight:bold”onclick>


Suivi en temps reel :

<input type=”button” name=”suivi” value=”Suivi” onclick=”self.location.href=’suivi.php'” style=”background-color:#FFFFFF” style=”color:white; font-weight:bold”onclick>





$jour = date(‘d’);

$mois = date(‘m’);

$annee = date(‘Y’);

$heure = date(‘H’);

$minute = date(‘i’);

echo ‘<div align=”center”>Nous sommes le ‘ . $jour . ‘/’ . $mois . ‘/’ . $annee . ‘ et il est ‘ . $heure. ‘ h ‘ . $minute;



<img src=”smarthome.jpg” width=”100″/>



The code above is for the menu. The code below is for defining the setpoint, choose the mode (Auto or Manual) and display the database.




// On commence par récupérer les champs



else      $lux=””;



else      $mode=””;

// On vérifie si les champs sont vides

if(empty($lux) AND empty($mode))


echo ‘<font color=”red”>Veuillez inserer la valeur en lux <br /> </font>’;


if (empty($mode))


echo ‘<font color=”red”>Veuillez cocher si le systeme est en mode auto ou manuel</font>’;


// Aucun champ n’est vide, on peut enregistrer dans la table



// connexion à la base

$bdd = new pdo(‘mysql:host=localhost;dbname=instructions’, ‘root’, ”);

// sélection de la base

if ($mode==”manu”)


else $mode=1;

// Permet d’écrire 1 si mode Auto et 0 si mode Manu

// on écrit la requête sql

$sql = “INSERT INTO infos(id, lux, auto) VALUES(”,’$lux’,$mode)”;

// on insère les informations du formulaire dans la table

$ecriture = $bdd->query($sql);

// on affiche le résultat pour le visiteur

echo ‘Les nouveaux parametres de fonctionnement ont ete envoyes.’;






Retour au menu :

<input type=”button” name=”Menu” value=”Menu” onclick=”self.location.href=’Menu.php'” style=”background-color:#FFFFFF” style=”color:white; font-weight:bold”onclick>



The following pictures show a draft of our future website project:

0205one 0205two

It is a French previous version. The definitive version will be in English 🙂

Currently, we master all the aspects of the project; the Arduino card, the Rasperry Pi, the Mysql database and the website. Now, we have to do a 3D model of the house. It is necessary to implement the different sensors needed to make the video.

Follow this video link for the making of the house with a 3D printer:

Next week will be dedicated to the achieving of the website and the making of the video.

See you next week!

The Smart Home Team

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s