Page 2 of 12

Re: RPi + Runeaudio +Wifi as Accesspoint

PostPosted: 12 Aug 2016, 20:26
by hondagx35
Hi dror,

hondagx35 wrote:Yes we DO NaTed ! :lol: :lol:

Did i miss the joke?

Frank

Re: RPi + Runeaudio +Wifi as Accesspoint

PostPosted: 14 Aug 2016, 09:11
by dror
:? Guess so.. but no offense the joke is on me. If you search you can see that most of my posts are in this subject (of getting a reliable AP configuration with internet sharing), so i'm sort of biased here when answering to your question.

To the subject, a NaTed AP configuration could be a great feature to my opinion. This could also give Rune a benefit, since Volumio and Moode already have a built in AP, but without internet sharing.

Dror

Re: RPi + Runeaudio +Wifi as Accesspoint

PostPosted: 14 Aug 2016, 14:14
by hondagx35
Hi dror,

To the subject, a NaTed AP configuration could be a great feature to my opinion.

OK, but why?
What is the benefit over using a cheap wifi router?

I think Rune should offer an AP because:
- makes it easy to setup the device without the need to connect it to ethernet first
- ethernet may available but without DHCP
- because it then can be used inside a car
- you can grant visitors access to the GUI without sharing your local network

On the other side i do not think the should add router functionality to an audio project.

Keep in mind Rune is made as a good sounding and cheap music player.
RuneAudio is a free and open source software with one specific objective: to transform an embedded platform (a cheap, silent and low-consumption mini-PC) into an Hi-Fi digital music player.


Give me some good reasons why we should implement NAT and it will get in.

Frank

Re: RPi + Runeaudio +Wifi as Accesspoint

PostPosted: 14 Aug 2016, 18:21
by keithdw
Frank, looking forward to your how to guide. I have had no success getting this to work in the past, have been messing about for months with both Runeaudio and Volumio.

Re: RPi + Runeaudio +Wifi as Accesspoint

PostPosted: 14 Aug 2016, 20:16
by johnbanks
Frank ...

I absolutely agree with you. What you are proposing will cover two different groups of users:

 Those with wifi but no access to a wired LAN who wish to set up RuneAudio using wireless only and which they may subsequently also use to stream music & web radio.

 Those who want to control RuneAudio from a tablet, smart phone, etc in the car or holiday location without wifi or in a cabin in the woods, etc – their music being on a USB stick or drive. Of course, these users will have needed access to a wired LAN to initially set up their RPi.

The current forum activity (dror, Stino, cmh714, BAZA, jojo, Mat, rathmannm & keithdw) seems to be focused on the second group & Wireless AP. And several of us have tried the create_ap script.

Over the past couple of days, I’ve spent several hours on this with only partial success (= failure) – RuneAudio reports as being connected to the AP but with unknown encryptation and I cannot connect to the AP from my laptop. (Also the popular EdiMax wifi adaptor was a complete pain to deal with because of its driver problem).

My Eureka moment was your post earlier today when you stated “The create_ap script and the way RuneAudio handles network do not fit.”
So I’ll stop wasting my time (but always a learning experience) and await your promised How To.

Frank, is there a chance you could release some early ‘alpha’ information that a few of us could try?
Thx

PS: My current holiday solution is an Rpi just as a Wireless AP and a second RPi with RuneAudio

Re: RPi + Runeaudio +Wifi as Accesspoint

PostPosted: 14 Aug 2016, 22:19
by hondagx35
Hi all,

Frank, is there a chance you could release some early ‘alpha’ information that a few of us could try?

Yes i can, but it will not work on all devices the same way.

So let us start with Raspberry Pi2 and Pi3 (latest image required)
With this modification Rune starts an AP if no IP is assigned to wlan0 after booting.
A configured WIFI connection will always be tried first and only if it fails the AP starts.

* get access to the console (ssh)

* check the free space on your sd card (<=85%). If not resize your partition (see documentation)

* update the kernel and firmware (this is needed to get the EDIMAX dongle working and doesn't hurt anyway)
Code: Select all
pacman -Sy --force raspberrypi-firmware-bootloader linux-raspberrypi

Edit:
the above doesn't work anymore, use this instead:
Code: Select all
pacman -Sy --force raspberrypi-firmware raspberrypi-bootloader linux-raspberrypi


* add "dtparam=audio=on" to your /boot/config.txt
Code: Select all
    # Uncomment one of these lines to enable an audio interface
    #dtoverlay=hifiberry-dac
    #dtoverlay=hifiberry-dacplus
    #dtoverlay=hifiberry-digi
    #dtoverlay=hifiberry-amp
    #dtoverlay=iqaudio-dac
    #dtoverlay=iqaudio-dacplus
    dtparam=audio=on


* delete the file /etc/modules-load.d/ras....conf

* install and check your WIFI dongle
Code: Select all
iw list

should show something like this
Code: Select all
Wiphy phy0
        max # scan SSIDs: 9
        max scan IEs length: 2304 bytes
        max # sched scan SSIDs: 0
        max # match sets: 0
        Retry short limit: 7
        Retry long limit: 4
        Coverage class: 0 (up to 0m)
        Supported Ciphers:
                * WEP40 (00-0f-ac:1)
                * WEP104 (00-0f-ac:5)
                * TKIP (00-0f-ac:2)
                * CCMP (00-0f-ac:4)
        Available Antennas: TX 0 RX 0
        Supported interface modes:
                 * IBSS
                 * managed
                 * AP
                 * monitor
                 * P2P-client
                 * P2P-GO
        Band 1:
                Capabilities: 0x1862
                        HT20/HT40
                        Static SM Power Save
                        RX HT20 SGI
                        RX HT40 SGI
                        No RX STBC
                        Max AMSDU length: 7935 bytes
                        DSSS/CCK HT40
                Maximum RX AMPDU length 65535 bytes (exponent: 0x003)
                Minimum RX AMPDU time spacing: 16 usec (0x07)
                HT Max RX data rate: 150 Mbps
                HT TX/RX MCS rate indexes supported: 0-7, 32
                Bitrates (non-HT):
                        * 1.0 Mbps
                        * 2.0 Mbps
                        * 5.5 Mbps
                        * 11.0 Mbps
                        * 6.0 Mbps
                        * 9.0 Mbps
                        * 12.0 Mbps
                        * 18.0 Mbps
                        * 24.0 Mbps
                        * 36.0 Mbps
                        * 48.0 Mbps
                        * 54.0 Mbps
                Frequencies:
                        * 2412 MHz [1] (20.0 dBm)
                        * 2417 MHz [2] (20.0 dBm)
                        * 2422 MHz [3] (20.0 dBm)
                        * 2427 MHz [4] (20.0 dBm)
                        * 2432 MHz [5] (20.0 dBm)
                        * 2437 MHz [6] (20.0 dBm)
                        * 2442 MHz [7] (20.0 dBm)
                        * 2447 MHz [8] (20.0 dBm)
                        * 2452 MHz [9] (20.0 dBm)
                        * 2457 MHz [10] (20.0 dBm)
                        * 2462 MHz [11] (20.0 dBm)
                        * 2467 MHz [12] (20.0 dBm)
                        * 2472 MHz [13] (20.0 dBm)
                        * 2484 MHz [14] (disabled)
        Band 2:
                Capabilities: 0x1862
                        HT20/HT40
                        Static SM Power Save
                        RX HT20 SGI
                        RX HT40 SGI
                        No RX STBC
                        Max AMSDU length: 7935 bytes
                        DSSS/CCK HT40
                Maximum RX AMPDU length 65535 bytes (exponent: 0x003)
                Minimum RX AMPDU time spacing: 16 usec (0x07)
                HT Max RX data rate: 150 Mbps
                HT TX/RX MCS rate indexes supported: 0-7, 32
                Bitrates (non-HT):
                        * 6.0 Mbps
                        * 9.0 Mbps
                        * 12.0 Mbps
                        * 18.0 Mbps
                        * 24.0 Mbps
                        * 36.0 Mbps
                        * 48.0 Mbps
                        * 54.0 Mbps
                Frequencies:
                        * 5170 MHz [34] (20.0 dBm)
                        * 5180 MHz [36] (20.0 dBm)
                        * 5190 MHz [38] (20.0 dBm)
                        * 5200 MHz [40] (20.0 dBm)
                        * 5210 MHz [42] (20.0 dBm)
                        * 5220 MHz [44] (20.0 dBm)
                        * 5230 MHz [46] (20.0 dBm)
                        * 5240 MHz [48] (20.0 dBm)
                        * 5260 MHz [52] (20.0 dBm) (radar detection)
                          DFS state: usable (for 40621 sec)
                          DFS CAC time: 60000 ms
                        * 5280 MHz [56] (20.0 dBm) (radar detection)
                          DFS state: usable (for 40621 sec)
                          DFS CAC time: 60000 ms
                        * 5300 MHz [60] (20.0 dBm) (radar detection)
                          DFS state: usable (for 40621 sec)
                          DFS CAC time: 60000 ms
                        * 5320 MHz [64] (20.0 dBm) (radar detection)
                          DFS state: usable (for 40621 sec)
                          DFS CAC time: 60000 ms
                        * 5500 MHz [100] (26.0 dBm) (radar detection)
                          DFS state: usable (for 40621 sec)
                          DFS CAC time: 60000 ms
                        * 5520 MHz [104] (26.0 dBm) (radar detection)
                          DFS state: usable (for 40621 sec)
                          DFS CAC time: 60000 ms
                        * 5540 MHz [108] (26.0 dBm) (radar detection)
                          DFS state: usable (for 40621 sec)
                          DFS CAC time: 60000 ms
                        * 5560 MHz [112] (26.0 dBm) (radar detection)
                          DFS state: usable (for 40621 sec)
                          DFS CAC time: 60000 ms
                        * 5580 MHz [116] (26.0 dBm) (radar detection)
                          DFS state: usable (for 40621 sec)
                          DFS CAC time: 60000 ms
                        * 5600 MHz [120] (26.0 dBm) (radar detection)
                          DFS state: usable (for 40621 sec)
                          DFS CAC time: 60000 ms
                        * 5620 MHz [124] (26.0 dBm) (radar detection)
                          DFS state: usable (for 40621 sec)
                          DFS CAC time: 60000 ms
                        * 5640 MHz [128] (26.0 dBm) (radar detection)
                          DFS state: usable (for 40621 sec)
                          DFS CAC time: 60000 ms
                        * 5660 MHz [132] (26.0 dBm) (radar detection)
                          DFS state: usable (for 40621 sec)
                          DFS CAC time: 60000 ms
                        * 5680 MHz [136] (26.0 dBm) (radar detection)
                          DFS state: usable (for 40621 sec)
                          DFS CAC time: 60000 ms
                        * 5700 MHz [140] (26.0 dBm) (radar detection)
                          DFS state: usable (for 40621 sec)
                          DFS CAC time: 60000 ms
                        * 5745 MHz [149] (disabled)
                        * 5765 MHz [153] (disabled)
                        * 5785 MHz [157] (disabled)
                        * 5805 MHz [161] (disabled)
                        * 5825 MHz [165] (disabled)
                        * 5920 MHz [184] (disabled)
                        * 5940 MHz [188] (disabled)
                        * 5960 MHz [192] (disabled)
                        * 5980 MHz [196] (disabled)
                        * 6000 MHz [200] (disabled)
                        * 6020 MHz [204] (disabled)
                        * 6040 MHz [208] (disabled)
                        * 6060 MHz [212] (disabled)
                        * 6080 MHz [216] (disabled)
        Supported commands:
                 * new_interface
                 * set_interface
                 * new_key
                 * start_ap
                 * new_station
                 * set_bss
                 * join_ibss
                 * set_pmksa
                 * del_pmksa
                 * flush_pmksa
                 * remain_on_channel
                 * frame
                 * set_channel
                 * connect
                 * disconnect
        Supported TX frame types:
                 * IBSS: 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0 0xb0 0xc0 0xd0 0xe0 0xf0
                 * managed: 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0 0xb0 0xc0 0xd0 0xe0 0xf0
                 * AP: 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0 0xb0 0xc0 0xd0 0xe0 0xf0
                 * AP/VLAN: 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0 0xb0 0xc0 0xd0 0xe0 0xf0
                 * P2P-client: 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0 0xb0 0xc0 0xd0 0xe0 0xf0
                 * P2P-GO: 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0 0xb0 0xc0 0xd0 0xe0 0xf0
        Supported RX frame types:
                 * IBSS: 0xd0
                 * managed: 0x40 0xd0
                 * AP: 0x00 0x20 0x40 0xa0 0xb0 0xc0 0xd0
                 * AP/VLAN: 0x00 0x20 0x40 0xa0 0xb0 0xc0 0xd0
                 * P2P-client: 0x40 0xd0
                 * P2P-GO: 0x00 0x20 0x40 0xa0 0xb0 0xc0 0xd0
        software interface modes (can always be added):
                 * monitor
        interface combinations are not supported
        Device supports scan flush.

The interesting part is:
Code: Select all
Supported interface modes:
                 * IBSS
                 * managed
                 * AP
                 * monitor
                 * P2P-client
                 * P2P-GO

We are looking for AP mode.

* install haveged
Code: Select all
pacman -S haveged

Code: Select all
systemctl enable haveged


* install hostapd and dnsmasq
Code: Select all
pacman -S hostapd dnsmasq


* edit /etc/hostapd/hostapd.conf
Code: Select all
nano /etc/hostapd/hostapd.conf

Code: Select all
# interface and driver
interface=wlan0
driver=nl80211

# WIFI-Config
ssid=RuneAudioAP
channel=7
hw_mode=g
wmm_enabled=1
auth_algs=1
max_num_sta=10

# WIFI authorization
wpa=2
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP CCMP
rsn_pairwise=CCMP
wpa_passphrase=RuneAudio


* edit /etc/dnsmasq.conf
Code: Select all
nano /etc/dnsmasq.conf

Code: Select all
# DHCP-Server for WIFI-Interface
interface=wlan0

# exclude DHCP-Server for ethernet
no-dhcp-interface=eth0

# IPv4 address-range and lease-time
dhcp-range=192.168.1.2,192.168.1.254,24h

# DNS
dhcp-option=option:dns-server,192.168.1.1

The IP settings here are only dummy values. They get overwritten by the settings from database (see below)

* modify /var/www/command/refresh_nics
Code: Select all
nano /var/www/command/refresh_nics

and add this
Code: Select all
// start AP if configured and no IP is assigned
if (FALSE === $redis->hGet('AccessPoint', 'enabled')) {
    $redis->hSet('AccessPoint', 'enabled', 0);
}
if (FALSE === $redis->hGet('AccessPoint', 'ip-address')) {
    $redis->hSet('AccessPoint', 'ip-address', '192.168.1.1');
}
if (FALSE === $redis->hGet('AccessPoint', 'broadcast')) {
    $redis->hSet('AccessPoint', 'broadcast', '192.168.1.255');
}
if (FALSE === $redis->hGet('AccessPoint', 'ssid')) {
    $redis->hSet('AccessPoint', 'ssid', 'RuneAudioAP');
}
if (FALSE === $redis->hGet('AccessPoint', 'passphrase')) {
    $redis->hSet('AccessPoint', 'passphrase', 'RuneAudio');
}
if (FALSE === $redis->hGet('AccessPoint', 'dhcp-range')) {
    $redis->hSet('AccessPoint', 'dhcp-range', '192.168.1.2,192.168.1.254,24h');
}
if (FALSE === $redis->hGet('AccessPoint', 'dhcp-option')) {
    $redis->hSet('AccessPoint', 'dhcp-option', 'option:dns-server,192.168.1.1');
}
if (FALSE === $redis->hGet('AccessPoint', 'enable-NAT')) {
    $redis->hSet('AccessPoint', 'enable-NAT', 0);
}
if ($redis->hGet('AccessPoint', 'enabled') === '1') {
   runelog('------------------ try to start AP if no IP is assigned ---------------------');
   $got_one_IP = false;
   if (!empty($active_nics)) {
      foreach($active_nics as $nic) {
         if (($nic === "wlan0") && (sysCmd('ip address show dev '.$nic.' | grep inet | wc -l')[0] !== '0')) {
            runelog('########### got one IP for nic: '.$nic);
            $got_one_IP = true;
         }
      }
   }
   if ($got_one_IP === false) {
      runelog('########### no IP => start AP on wlan0');
      sysCmd('systemctl stop netctl-auto@wlan0');
      // change AP name
      $file = '/etc/hostapd/hostapd.conf';
        $newArray = wrk_replaceTextLine($file, '', 'ssid=', 'ssid='.$redis->hGet("AccessPoint", "ssid"));
        $fp = fopen($file, 'w');
        $return = fwrite($fp, implode("", $newArray));
        fclose($fp);
      // change passphrase
      $file = '/etc/hostapd/hostapd.conf';
        $newArray = wrk_replaceTextLine($file, '', 'wpa_passphrase=', 'wpa_passphrase='.$redis->hGet("AccessPoint", "passphrase"));
        $fp = fopen($file, 'w');
        $return = fwrite($fp, implode("", $newArray));
        fclose($fp);
      sysCmd('systemctl start hostapd');
      // change dhcp-range
      $file = '/etc/dnsmasq.conf';
        $newArray = wrk_replaceTextLine($file, '', 'dhcp-range=', 'dhcp-range='.$redis->hGet("AccessPoint", "dhcp-range"));
        $fp = fopen($file, 'w');
        $return = fwrite($fp, implode("", $newArray));
        fclose($fp);
      // change dhcp-option
      $file = '/etc/dnsmasq.conf';
        $newArray = wrk_replaceTextLine($file, '', 'dhcp-option=', 'dhcp-option='.$redis->hGet("AccessPoint", "dhcp-option"));
        $fp = fopen($file, 'w');
        $return = fwrite($fp, implode("", $newArray));
        fclose($fp);
      sysCmd('systemctl start dnsmasq');
      sysCmd('ip addr add '.$redis->hGet("AccessPoint", "ip-address").'/24 broadcast '.$redis->hGet("AccessPoint", "broadcast").' dev wlan0');
      if ($redis->hGet('AccessPoint', 'enable-NAT') === '1') {
         sysCmd('iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE');
         sysCmd('iptables -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT');
         sysCmd('iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT');
         sysCmd('sysctl net.ipv4.ip_forward=1');
      }
   }
}
// start AP end

before
Code: Select all
// end - unlock the scan system
runelog('--------------------------- unlock the scan system ---------------------------');
$redis->Set('lock_wifiscan', 0);
// colse Redis connection
$redis->close();

at the end of that file.

* enable the AccessPoint
Code: Select all
redis-cli hset AccessPoint enabled 1


* if you like you can also enable NAT to connect wifi and ethernet
Code: Select all
redis-cli hset AccessPoint enable-NAT 1


* reboot and enjoy the AP

This is tested with:
- EDIMAX EW-7811UN
- D-LINK DWL-G122
- RP3 integrated wifi

The default values are:
- SSID = RuneAudioAP
- KEY = RuneAudio
- DHCP = 192.168.1.2 - 192.168.1.254
- IP (Pi) = 192.168.1.1
All settings are stored in redis as "AccessPoint", so it will be easy to setup a settings page on Rune.
Code: Select all
redis-cli hgetall AccessPoint

Code: Select all
root@runeaudio(rw):~# redis-cli hgetall AccessPoint
 1) "enabled"
 2) "1"
 3) "ip-address"
 4) "192.168.1.1"
 5) "broadcast"
 6) "192.168.1.255"
 7) "ssid"
 8) "RuneAudioAP"
 9) "passphrase"
10) "RuneAudio"
11) "dhcp-range"
12) "192.168.1.2,192.168.1.254,24h"
13) "dhcp-option"
14) "option:dns-server,192.168.1.1"
15) "enable-NAT"
16) "1"

You can enable or disable the AP with:
Code: Select all
redis-cli hset AccessPoint enabled 1

Code: Select all
redis-cli hset AccessPoint enabled 0

You can enable or disable the NAT mode with:
Code: Select all
redis-cli hset AccessPoint enable-NAT 1

Code: Select all
redis-cli hset AccessPoint enable-NAT 0


You can try this on all other platforms, but skip updating kernel and firmware.
The EDIMAX EW-7811UN will only work with latest kernel!

Other platforms follow as soon as i made some tests.

AccessPoint.zip
(3.68 KiB) Downloaded 700 times


Edit: NAT functionality added
Edit: changed hostapd.conf

Frank

Re: RPi + Runeaudio +Wifi as Accesspoint

PostPosted: 14 Aug 2016, 22:46
by johnbanks
Frank, you're a star!
I'll try it on an RPi2 and report back
But maybe not tonight
Thx again

Re: RPi + Runeaudio +Wifi as Accesspoint

PostPosted: 15 Aug 2016, 12:21
by dror
Hi Frank and all,
First,
Give me some good reasons why we should implement NAT and it will get in.


I'm relating to the scenario in which one would like to have the Ethernet cable plugged in (to mount a NAS from PC)
1.Ifrastructre Wifi is not always wanted on demiciles. I personally try to avoid strong electromagnetic radiation in the surroundings of my children, that is why I do need a local (=living room only) wifi internet AP.
2. Using another wifi router is more mess to a already messed up table (Speakers, Amplifiers, Rpi, Router and all their power and data cables).
3. If one is using his tablet as the control for Rune and would like to stream to Rune DLNA or AirPlay requires the tablet to have internet access. I'm using Tubio and AllStream on my Android/tablet devices - how could I get internet access? (Cellular data costs, and not always reachable)
4. I have the impression it shouldn't be such a hard task. Indeed, I tried myseldf to implement this, but you're more familier with the guts of Rune than me, so you could "keep things in their place"

Second,
Thank you for the tutorial - Is it for a NaTed configuration? couldn't figure it out (also haven't tested it yet..)

johnbanks,
My Eureka moment was your post earlier today when you stated “The create_ap script and the way RuneAudio handles network do not fit.”
So I’ll stop wasting my time (but always a learning experience) and await your promised How To.


This is not true. I'm running an access point with internet with the create_ap script on an old version of Rune.
On newer version I managed to bring it up in bridged mode of create_ap ( -m bridged).
Well, if you ask - if everything is ok why i'm discussing this? - The only thing is I am sufferring from is my NAS mount disconnections, and I'm not sure why. Could be create_ap issues, and could not - this is why I'm trying to get an out-of-the-box solution so I can eliminate the causes.

Dror

Re: RPi + Runeaudio +Wifi as Accesspoint

PostPosted: 15 Aug 2016, 14:08
by johnbanks
Dror ...

create_ap script problems could well be associated with up to date Rune versions which handle networking differently as I understand it.

If your NAS is disconnecting is it possible that your wifi adapter is automatically going into power saving mode?

Re: RPi + Runeaudio +Wifi as Accesspoint

PostPosted: 15 Aug 2016, 14:20
by dror
johnbanks wrote:Dror ...
create_ap script problems could well be associated with up to date Rune versions which handle networking differently as I understand it.


Yeah, thats what Frank says. But even though, brigded configuration is working. (as far as I remember. should be check again)


johnbanks wrote:If your NAS is disconnecting is it possible that your wifi adapter is automatically going into power saving mode?

The NAS is connected via Ethernet (which also provides the Internet connection), to the PC. No Wifi adapter in the middle.

dror