Configure hotspot
Network
Step 1 - Create custom recipe
In order to create wireless access point (hotspot) you have to configure
hostapd
service. Create custom recipe which will be appending instructions
to original recipe.
mkdir -p ../meta-golemos/recipes-connectivity/hostapd/files
touch ../meta-golemos/recipes-connectivity/hostapd/hostapd_%.bbappend
Inside this recipe place this instructions.
FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
SRC_URI += " \
file://wlan0.conf \
file://hostapd@.service \
"
SYSTEMD_AUTO_ENABLE = "enable"
SYSTEMD_SERVICE_${PN}_append = " hostapd@wlan0.service "
do_install_append () {
install -d ${D}${sysconfdir}/hostapd
install -D -m 600 ${WORKDIR}/wlan0.conf ${D}${sysconfdir}/hostapd/
install -d ${D}${systemd_system_unitdir}
install -D -m 0644 ${WORKDIR}/hostapd@.service ${D}${systemd_system_unitdir}/
install -d ${D}${sysconfdir}/systemd/system/multi-user.target.wants/
ln -s ${systemd_system_unitdir}/hostapd@.service ${D}${sysconfdir}/systemd/system/multi-user.target.wants/hostapd@wlan0.service
}
Note
This instruction enable interface specific version of the service. It will automaticly wait for the interface to be operational before started.
Step 2 - Create configuration file
Inside this file will be placed information about wireless network and also credentials to this network.
touch ../meta-golemos/recipes-connectivity/hostapd/files/wlan0.conf
In this file you have to write this configuration.
interface=wlan0
ssid=Datalogger_AP
hw_mode=g
channel=11
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
own_ip_addr=192.168.8.1
wpa=2
wpa_passphrase=datalogger
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
Step 3 - Create service file
To match custom recipe instructions you have to create special service file for
hostapd
.
touch ../meta-golemos/recipes-connectivity/hostapd/files/hostapd@.service
Inside this file you should place such content.
[Unit]
Description=Advanced IEEE 802.11 AP and IEEE 802.1X/WPA/WPA2/EAP Authenticator (%I)
After=network.target
BindsTo=sys-subsystem-net-devices-%i.device
[Service]
Type=forking
PIDFile=/run/hostapd.%i.pid
Restart=on-failure
RestartSec=2
EnvironmentFile=-/etc/default/hostapd
ExecStart=/usr/sbin/hostapd -B -P /run/hostapd.%i.pid $DAEMON_OPTS /etc/hostapd/%i.conf
[Install]
WantedBy=multi-user.target sys-subsystem-net-devices-%i.device
DHCP server
In newer versions of yocto they remove isc-dhcp-server
and replaced it with
kea
.
Step 1 - Create custom recipe
In order to configure DHCP server you need to create custom recipe which will install configuration file in proper location.
mkdir -p ../meta-golemos/recipes-connectivity/kea/files
touch ../meta-golemos/recipes-connectivity/kea/kea_%.bbappend
In this recipe place such a configuration.
FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
SRC_URI += " \
file://kea-dhcp4.conf \
file://kea-dhcp4.service \
"
SYSTEMD_AUTO_ENABLE = "enable"
SYSTEMD_SERVICE_${PN}_append = " kea-dhcp4.service "
FILES_${PN} += " ${systemd_system_unitdir}/kea-dhcp4-server.service "
do_install_append () {
install -d ${D}${sysconfdir}/kea/
install -D -m 600 ${WORKDIR}/kea-dhcp4.conf ${D}${sysconfdir}/kea/
install -d ${D}${systemd_system_unitdir}
install -m 0644 ${WORKDIR}/kea-dhcp4.service ${D}${systemd_system_unitdir}
install -d ${D}${sysconfdir}/systemd/system/multi-user.target.wants/
ln -s ${systemd_system_unitdir}/kea-dhcp4.service ${D}${sysconfdir}/systemd/system/multi-user.target.wants/kea-dhcp4.service
}
Step 2 - Create configuration file
Kea needs JSON configuration file to be installed in proper place. You already have instructions which will place this file. Now create this file and configure DHCP server.
touch ../meta-golemos/recipes-connectivity/kea/files/kea-dhcp4.conf
{
"Dhcp4": {
"valid-lifetime": 1296000,
"renew-timer": 864000,
"rebind-timer": 864000,
"expired-leases-processing": {
"reclaim-timer-wait-time": 10,
"flush-reclaimed-timer-wait-time": 25,
"hold-reclaimed-time": 3600,
"max-reclaim-leases": 100,
"max-reclaim-time": 250,
"unwarned-reclaim-cycles": 5
},
"interfaces-config": {
"interfaces": [ "wlan0/192.168.8.1" ]
},
"lease-database": {
"type": "memfile",
"persist": true,
"name": "/var/lib/kea/dhcp4.leases",
"lfc-interval": 3600
},
"subnet4": [
{
"subnet": "192.168.8.0/24",
"pools": [
{
"pool": "192.168.8.100 - 192.168.8.200"
}
],
"option-data": [
{
"name": "routers",
"data": "192.168.8.0"
}
]
}
]
}
}
Step 3 - Create service file
Kea by itself install service file. Unfortunately this service file is really slow. In this case you have to create your own custom service file.
touch ../meta-golemos/recipes-connectivity/kea/files/kea-dhcp4.service
Inside newly created service file place such content, but first read warning underneath the code block.
[Unit]
Description=Kea DHCPv4 Server
Documentation=man:kea-dhcp4(8)
# Wants=network-online.target
# After=network-online.target
# Start after interface is up
BindsTo=sys-subsystem-net-devices-wlan0.device
After=sys-subsystem-net-devices-wlan0.device
[Service]
ExecStartPre=/sbin/ifconfig wlan0 192.168.8.1 netmask 255.255.255.0 up
ExecStartPre=/bin/mkdir -p /var/run/kea/
ExecStartPre=/bin/mkdir -p /var/lib/kea
ExecStart=/usr/sbin/kea-dhcp4 -c /etc/kea/kea-dhcp4.conf
ExecStopPost=/sbin/ifconfig wlan0 0
[Install]
WantedBy=multi-user.target
Warning
Kea install by itself service file, but custom recipe will
overwrite it. This is required to set static IP before DHCP server starts
and also because Kea by default wait for network-online.target
. In this
case it is not necessary. The minimal requirement is that the interface must
be configured.
Summary
Combining this two tools will allow you to create hotspot on your device and enabling it on system boot. Following this steps should provide you to this layer structure.
../meta-golemos
├── COPYING.MIT
├── README
├── conf
│ ├── bblayers.conf.sample
│ ├── conf-notes.txt
│ ├── distro
│ │ └── golemos.conf
│ ├── layer.conf
│ └── local.conf.sample
├── recipes-connectivity
│ ├── hostapd
│ │ ├── files
│ │ │ ├── hostapd@.service
│ │ │ └── wlan0.conf
│ │ └── hostapd_%.bbappend
│ ├── kea
│ │ ├── files
│ │ │ ├── kea-dhcp4.conf
│ │ │ └── kea-dhcp4.service
│ │ └── kea_%.bbappend
│ └── wpa-supplicant
│ ├── files
│ │ └── wpa_supplicant-nl80211-wlan0.conf
│ └── wpa-supplicant_%.bbappend
├── recipes-core
│ ├── images
│ │ ├── datalogger-dev-image.bb
│ │ ├── datalogger-extended-image.bb
│ │ └── datalogger-image.bb
│ ├── packagegroups
│ │ ├── datalogger-base-packagegroup.bb
│ │ ├── datalogger-core-packagegroup.bb
│ │ ├── datalogger-dev-packagegroup.bb
│ │ └── datalogger-extended-packagegroup.bb
│ ├── systemd
│ │ └── systemd_%.bbappend
│ └── systemd-conf
│ ├── files
│ │ └── wlan.network
│ └── systemd-conf_%.bbappend
└── recipes-example
└── example
└── example_0.1.bb