Development Information

Makefile

The important command lines for development are collected in the Makefile.

Docker Environment

The rsensor-Docker-Container contains the following components:

  • Mysql Server
    • the database is initialized with the script test/init_db.sql
  • sqlite3
  • Python
  • the latest rsensor package (todo: really needed?)
  • (todo: maybe add mosquitto)

The Container is created with the command:

cd test
docker build -t rsensor .

The container is started with:

cd test
docker run --rm --name rsensordb --hostname rsensordb -v $(pwd):/test -p 5555:5000 -p 3306:3306 -t -i rsensor

Options:

–rm:delete container at exit
–name ….:set container name
–hostname ….:set hostname of the container
-v …:map local directory as volume
-p …:map ports to host system
-t:???
-i:???
rsensor:name of the container (see docker build)

At the docker-prompt you can testwise access the database:

mysql -u root

The script prepare_mysql.sql creates the user rsensor and the database rsensor:

mysql -u root < prepare_mysql.sql

Using the MySQL Docker DB from extern

Acess the container via its IP address with:

mysql -u rsensor -h 172.17.0.1  rsensor -p

The password is “rsensor” (see prepare_mysql.sql)

Todo

check how to add docker-container to DNS automatically

Python Virtual Environment

In the example Writing a SystemD-Daemon Script it is assumed that uracoli-rsensor is installed in a virtual environment in directory /home/pi/ve_py2. This virtual environment is created with the commands:

python -m virtualenv /home/pi/ve_py2
/home/pi/ve_py2/bin/pip install -e git+https://gitlab.com/uracoli-project/uracoli-rsensor.git

Raspi AP Setup

Follow the article How to use your Raspberry Pi as a wireless access point (https://thepi.io) and skip the bridge settings in this article, they are not needed for the sensor network. (alternativly see also Raspberry Pi als WLAN-Router einrichten)

Here are the current used configuration files.

/etc/dhcpcd.conf:

hostname
clientid
persistent
option rapid_commit
option domain_name_servers, domain_name, domain_search, host_name
option classless_static_routes
option interface_mtu
require dhcp_server_identifier
slaac private
interface wlan0
static ip_address=10.65.87.1/24
denyinterfaces eth0
denyinterfaces wlan0

/etc/dnsmasq.conf:

interface=wlan0
  dhcp-range=10.65.87.100,10.65.87.200,255.255.255.0,24h

/etc/hostapd/hostapd.conf:

interface=wlan0
#bridge=br0
hw_mode=g
channel=7
wmm_enabled=0
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
ssid=MyRsensorAP
wpa_passphrase=sovershennosekretno

/etc/default/hostapd:

DAEMON_CONF="/etc/hostapd/hostapd.conf"

/etc/sysctl.conf:

net.ipv4.ip_forward=1

/etc/rc.local:

#!/bin/sh -e
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
fi
# appended iptables-restore for AP, generated by:
#       sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
#       sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"
iptables-restore < /etc/iptables.ipv4.nat
exit 0

Note

Also check the permissions of /etc/rc.local. It needs to be executable. -rwxr-xr-x 1 root root 306 Apr  4  2017 /etc/rc.local

Wifi Issues

In case of an error message from hostapd:

>> journalctl -u hostapd.service
-- Logs begin at Sat 2020-06-06 12:17:01 CEST, end at Sat 2020-06-06 13:16:17 CEST. --
Jun 06 12:46:06 gretel systemd[1]: Starting Advanced IEEE 802.11 AP and IEEE 802.1X/WPA/WPA2/EAP Authenticator...
Jun 06 12:46:07 gretel hostapd[379]: Configuration file: /etc/hostapd/hostapd.conf
Jun 06 12:46:07 gretel hostapd[379]: nl80211: Driver does not support authentication/association or connect commands
Jun 06 12:46:07 gretel hostapd[379]: nl80211: deinit ifname=wlan0 disabled_11b_rates=0

If a Wifi-USB stick like TP-LINK TL-WN722N is used, you need to install new drivers. Easy way is using MrEngmans precompiled modules. (https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=62371&sid=97f79dbe9f8ac40727b1c4ba236c9454)

Do this steps on Raspberry:

sudo wget http://downloads.fars-robotics.net/wifi-drivers/install-wifi -O /usr/bin/install-wifi
sudo chmod +x /usr/bin/install-wifi
sudo /usr/bin/install-wifi -h
sudo /usr/bin/install-wifi

After reboot the error should have been gone.