Great. We are on Step 0 of our smart home automation project.
For this step i am expecting that you have either Linux or Mac.
We do need an ssh connection and also if you haven't already - do set up RPi to automatically start up the ssh on boot.
Why am i saying that we are on Step 0. Because lets face it - we haven't touched ANY programming or ANY electronics so far. That will, however, change from the next tutorial. In this one we will get the Logic of what needs to be done and why are we doing it the way we will.
For this tutorial i am using this reference.
I'm going to say it right from the start. It sucks. It sucks donkeys ass.
Still i did fix it and now i am happy to say i think it doesn't suck that much.
NOTE: Even though i do know C,C++,C#, Java, Python,... from Excellent (C/C++/C#) To Really good (Python) to i wouldmanageinitifyouthroweditatme (perl,prolog) I HAVE NOT LEARNED PHP!! So i did have to learn it since (lets face it there ain't gonna be a server without PHP).
So i did look a quick glance at the syntax and started digging in the fun stuff. (My prior expertise in a lot of other programming languages helped of course for this to go smoothly)
CODE IDEA AND WHY CREATE A WHOLE SESSION CLASS:
So i'm going to create a whole new session class and my own session handler functions since php native session_start() is a security hazard.The idea is:
session function communicates with a smarthomedb database and in that database we have a table called sessions. And a user who is authorized to write and read to and from that table. That way we can have a really good session control with MySQL.
Creating MySQL database:
Go to phpmyadmin page of your RPi. Log in as root and type this in:
We now have the database (with no tables!) created.
For the tables we do need: members, sessions, login_attempts.
As a bare minimum for now. Later on action table will be added (as to have control which user initiated which command on the smart home) and quite possibly some others.
But for now we will do the following:
1. Go to your phpmyadmin and login as root.
2. Click on your smarthomedb and look for the field 'Create table for database ...'
3. Insert name members and number of colums 7.
4. The names and the types are as follow:
Now do the same for the table named sessions - no. columns 4
Names and types as follow:
Great now for the login_attempts with no. columns 3
Names and types:
We now have the database and tables created. We can start the coding.
NEXT: Session Managment for Smart Home Server
For this step i am expecting that you have either Linux or Mac.
We do need an ssh connection and also if you haven't already - do set up RPi to automatically start up the ssh on boot.
Why am i saying that we are on Step 0. Because lets face it - we haven't touched ANY programming or ANY electronics so far. That will, however, change from the next tutorial. In this one we will get the Logic of what needs to be done and why are we doing it the way we will.
For this tutorial i am using this reference.
I'm going to say it right from the start. It sucks. It sucks donkeys ass.
Still i did fix it and now i am happy to say i think it doesn't suck that much.
NOTE: Even though i do know C,C++,C#, Java, Python,... from Excellent (C/C++/C#) To Really good (Python) to i wouldmanageinitifyouthroweditatme (perl,prolog) I HAVE NOT LEARNED PHP!! So i did have to learn it since (lets face it there ain't gonna be a server without PHP).
So i did look a quick glance at the syntax and started digging in the fun stuff. (My prior expertise in a lot of other programming languages helped of course for this to go smoothly)
CODE IDEA AND WHY CREATE A WHOLE SESSION CLASS:
So i'm going to create a whole new session class and my own session handler functions since php native session_start() is a security hazard.The idea is:
session function communicates with a smarthomedb database and in that database we have a table called sessions. And a user who is authorized to write and read to and from that table. That way we can have a really good session control with MySQL.
Creating MySQL database:
Go to phpmyadmin page of your RPi. Log in as root and type this in:
1 | CREATE DATABASE smarthomedb; |
We now have the database (with no tables!) created.
For the tables we do need: members, sessions, login_attempts.
As a bare minimum for now. Later on action table will be added (as to have control which user initiated which command on the smart home) and quite possibly some others.
But for now we will do the following:
1. Go to your phpmyadmin and login as root.
2. Click on your smarthomedb and look for the field 'Create table for database ...'
3. Insert name members and number of colums 7.
4. The names and the types are as follow:
id int(11) PRIMARY KEY (check the AI field - autoincrement)
uname varchar(30)
email varchar(50)
pass char(128)
salt char(128)
acc_permissions enum('a', 'b', 'c', 'd', 'e')
phone_no varchar(15)
Now do the same for the table named sessions - no. columns 4
Names and types as follow:
id char(128) PRIMARY KEY
settime datetime
data text
skey char(128)
Great now for the login_attempts with no. columns 3
Names and types:
id int(11)
time datetime
ip varchar(45)
We now have the database and tables created. We can start the coding.
NEXT: Session Managment for Smart Home Server
No comments:
Post a Comment