Monitor home temperature - YJMuzangisa/Monitor-Fan GitHub Wiki

Preview

This is page can be seen as a soft copy of how to assemble and use my project. We were asked by the academic to write a project (related to Data Science) that will display our understanding of what we've been thought in Data Science for this semester. A lot of good project ideas, notably home automation which is the focus of my project. I decided then to write a program that could make it possible to play with some devices at the house because of the behaviour of a sensor. But also, I had to find a way to incorporate network communication in my project.

See Readme.md, to understand the first couple of step and devices needed for my project.

ProjectPane.java

My main focus was on designing a GUI that could provide me with the necessary buttons and text fields to make the all process possible. I had to be able to send commands when buttons are pressed and see the replies on the textfields or even see the progress.

Services

Here, no extra service has been really installed. The only ones that could be consider as services, are Javafx and Socket. But those ones are built-in services that you find in your Java SE (8 or more).

How-To

With the help of an adequate IDE (Eclipse for example) or even Command Prompt (or terminal for Mac users), run the java file. A graphical user interface should appear on your screen. Press on the red buttons (toggle buttons with names Off) to turn on the fan. And on the show buttons to request informations about your rooms such as the current temperature of the requested room and the time needed for the room to be warm or cool off.

see attached picture

  • With the toggle buttons, when pressed, a socket connection is established between the java program on the main computer and python program on the Raspberry Pi 4 (establishing your java program as the client and the python program as the server). That connection is then used as a tunnel of communication to send a command to the Raspberry Pi 4 through form of bytes messages instructing the server to turn on the fan. Once a positive response (the command has been executed) from the server is received, the connection is then closed.
  • With the show buttons, when pressed, a socket connection is once again established between the client and the server to obtain request temperature from the python program.

N.B: As you can see, I tried to maintained a client-server connection to a minimum. The reason is, I'm not really sure for what specific reason, when a constant connection is maintained, the temperature readings from the DHT22 break or work sometimes. After some research, I've found out that this was some manufactured issue with the DHT22

Schedule.java

Here is where every problem related to time is handled.

Services

The only ones worth mentioning are GregorianCalendar and Calendar built-in classes which gave me access to my timezone and made it possible to determine exactly at what time my fans were turned on or off, and how long it would take for the rooms to cool off.

Project.py

I've used a python code to handled behaviours from my Raspberry Pi 4. The extra components and services from the Raspberry Pi makes possible behaviour such getting the temperature of the room and handling connection with my tp-link smart plug.

Services

DHT22

You will find in the link below, information on the specific DHT22 I've chosen. http://www.waveshare.com/wiki/DHT22_Temperature-Humidity_Sensor

For my project, my DHT22 and Raspberry Pi 4 were connected as follow:

* VCC to the first pin (3v3)
* DOUT to the pin 7 (GPIO17)
* GND to the pin 39 (Ground)

adafruit_dht

Again, due to my setup of the Raspberry Pi 4 and how I've written my codes, my project works better with python3 which prefer the use of adafruit_dht rather than Adafruit_DHT (Also related to the use of the DHT22).

This service helped me with my reading of the temperatures from the DHT22 component.

Installing

To install for current user:

pip3 install adafruit_dht

Or

sudo pip3 install adafruit_dht

for a system wide installation

N.B: It would be a good idea to ensure that your pip3 is up to date

pyHS100

This was used for my connection with my tp-link smart plug (HS110)

Installing

To install for current user:

pip3 install pyHS100

Or

sudo pip3 install pyHS100

for a system wide installation

N.B: It would be a good idea to ensure that your pip3 is up to date

How-To

Here, after the client-sever connection between the java program and the python program established, the on or off command is received from the client. After receiving the the command from the toggle switch buttons, the server then send a turn_on() or turn_off() command to the smart plug. Once the command has been sent, depending on whether the execution was successful on the tp-link side, an email is then send into my account telling which of the fan was turned on or off.

When it comes to my show buttons, after the client-sever connection between the java program and the python program established, a request for the room temperature is sent to the server. The server then with the use of my adafruit_dht class, get the room temperature and sent it back to the clien.