Framework for domotizing houses using various raspberries pi 3
Install hostapd
and isc-dhcp-server
via:
sudo apt-get update
sudo apt-get install hostapd isc-dhcp-server
Backup of the default config:
sudo cp /etc/dhcp/dhcpd.conf /etc/dhcp/dhcpd.conf.default
Edit the defult config file:
sudo nano /etc/dhcp/dhcpd.conf
Comment the following lines:
#option domain-name "example.org";
#option domain-name-servers ns1.example.org, ns2.example.org;
Un-comment this line
# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
authoritative;
Scroll down at the bottom of the file (CTRL + V) and paste:
subnet 192.168.42.0 netmask 255.255.255.0 {
range 192.168.42.10 192.168.42.50;
option broadcast-address 192.168.42.255;
option routers 192.168.42.1;
default-lease-time 600;
max-lease-time 7200;
option domain-name "local";
option domain-name-servers 8.8.8.8, 8.8.4.4;
}
Now, with this configuration we are assigning the subnet 192.168.42.10–50
(40 devices in total) and we are configuring our WiFi local IP address to be 192.168.42.1
. While we’re at it, we’re assigning Google’s public DNS: 8.8.8.8
, 8.8.4.4
.
Next, let’s specify on what interface should the DHCP server servce DHCP requests (wlan0 in this case):
sudo nano /etc/default/isc-dhcp-server
Edit this line:
# File /etc/default/isc-dhcp-server
INTERFACES="wlan0"
Let’s setup wlan0 for static IP:
Shut it down:
sudo ifdown wlan0
Make a backup file:
sudo cp /etc/network/interfaces /etc/network/interfaces.backup
Edit the network interfaces file:
sudo nano /etc/network/interfaces
Edit accordingly to read:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
iface eth0 inet dhcp
allow-hotplug wlan0
iface wlan0 inet static
address 192.168.42.1
netmask 255.255.255.0
post-up iw dev $IFACE set power_save off
Close the file and assign a static IP now:
sudo ifconfig wlan0 192.168.42.1
Create a file and edit it:
sudo nano /etc/hostapd/hostapd.conf
Modify ssid with a name and wpa_passphrase to a password
interface=wlan0
ssid=WiPi
hw_mode=g
channel=6
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=xyz
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
Next, let’s configure the network address translation:
Create a backup file
sudo cp /etc/sysctl.conf /etc/sysctl.conf.backup
Edit the config file
sudo nano /etc/sysctl.conf
Add to the bottom:
net.ipv4.ip_forward=1
Activate it immediately:
sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
Modify the iptables to create a network translation between eth0 and the wifi port wlan0
sudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT
Make this happen on reboot by runnig
sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"
And editing again
sudo nano /etc/network/interfaces
Appending at then end:
up iptables-restore < /etc/iptables.ipv4.nat
Let's clean everything:
sudo service hostapd start
sudo service isc-dhcp-server start
And make sure that we're up and running:
sudo service hostapd status
sudo service isc-dhcp-server status
Configure our daemons to start at boot time:
sudo update-rc.d hostapd enable
sudo update-rc.d isc-dhcp-server enable
Reboot the pi.
sudo reboot
Copy all beek_master/beek
files to /etc/beek/
.
Set your daemon in your sudo crontab:
sudo crontab -l > mycron
echo "* * * * * /etc/beek/beek-daemon.sh" >> mycron
sudo crontab mycron
rm mycron
Config you modules in beek.conf
Add your smartphone's MAC address to trusted.conf
First install apache
sudo apt-get install apache2 -y
Copy all files in web/html
under /var/www/html
You will need to install VLC media player to run this module.
sudo apt-get install vlc
Copy all files under beek_music/.beek
in your raspberry's home/pi/.beek
location.
Set a default playlist under ~/Music/default
.
Now you can connect to 192.168.42.1
in your device to control your music.
Copy all files under beek_heat/.beek
in your raspberry's home/pi/.beek
location.
Start your Sense Hat emulator or connect a real one.
Start the server running python ~/.beek/server.py
Now you can connect to 192.168.42.1
in your device to control the heat.