Feature request / workaround / bug report WLAN...


 

DanielK

New member
First of all: Thanks to all contributors to this perfect project!
I really love my just finished HeaterMeter (even though I didn’t do a cook with it yet). Images will follow in a separate thread.

This will be a bit longer - I though about splitting it into more threads, but it wouldn’t have benefited. I’ll try to keep the different parts separated a bit.

------------------
General remark:
One minor remark for the Software page in the wiki:
The B+ also needs the current snapshot image. Or you manually exchange get the latest boot files "bootcode.bin", "kernel.img" & "start.elf" from Raspberry project and replace the current ones, as given on the openwrt page.
------------------
Bug?
Then, there seems to be a WLAN bug in rt8192cu in the current HM builds that gave me headache for a weeks evenings. I stumbled upon that while working on scripts to change the WLAN AP (see below).
I’m not sure if it is known already as I just read the last sentence on the Software page about rebooting to switch to WLAN.
I’ve got a "Edimax EW-7811Un 150Mbps Wireless 11n Nano” which is basically working. I can connect to my WPA2 secured AP at home.
However, I can only connect once after reboot. If I press the “reconnect” button for wwan on the network page, the WLAN stick does not reconnect correctly. It blinks periodically, show on the web page that it is connected to the AP, but doesn’t get an IP. Also running udhcp on the command line (ssh via network cable) doesn’t help. My AP shows it to be connected, but with extremely low speed. Only rebooting the pi helps.
The same state can also reproducibly be reached by associating to different APs. via the Wifi page, I can switch the AP once, on the second change of AP it ends up in the same unknown state.
I tried to isolate this one a bit, but didn’t get too far.
- I tried the 12.09 AA from openwork.org, but this doesn’t have support for rt8192cu
- I tried the 14.07 BB from openwork.org, but this had more general problems in the downloadable build. "lsmod” didn’t show any modules, and the rt8192cu module didn’t load, even though I installed the package
- I tried the current trunk (Jan 30) from openwork.org and it worked perfectly after installing the modules. Hence my WLAN Stick and pi are fine.

This bug is not nice, but also not serious. Connecting to a WLAN after a reboot perfectly worked up to now. also no connection losses up to now. Hence, this is no urgent problem, that will disappear after switching to a newer openwork version. If this is known, maybe just add the information to the wiki, so other do not also waste the time...

------------------
Feature request / workaround / finished scripts to include?
As the HM is only controlled via the four buttons / joystick and the RJ45 network connection is not accessible without opening the box.
I need to be able to easily switch the WLAN AP, as the coverage here is bad. Hence, I have several APs, and I need to connect to a different one, depending on wether I use the HM a the garage or in the garden. With the current HM, you always have to switch the HM on in the AP rage you used it last, and then reconfigure it for the AP you want to use it. If I take the HM to a friends house I have no WLAN access at (first), I would like the HM to go to AP mode, so I can configure it from my tablet.
The feature request: switch WLAN from a list of preconfigured networks via the AVR buttons.
Possible way to do it: add a config file with the different WLAN configs to /etc, add a variable for the chose WLAN in the AVR. A script then periodically (or only once at boot) checks for that value, sets the WLAN config and reconnects (or opens up an AP).
But with the current WLAN problems (reconnect problems, see above), it cannot be done without a reboot anyway. Hence (and as I didn’t want to change the AVR firmware), I made up a script which I want to share.
Workaround: I started with the AAP scripts from here, but failed with a non-reconnecting WLAN. After isolating this, I made a modified script - Nevertheless credit goes to dabyd64 from the openwrt Forum, as I modified his script to solve my problem.
What it does: At boot (boot script 99), the script looks for known WLANs from the config file /etc. It gives some output of what its doing to the LCD (and system log file).
-> If it finds one and it is different the one currently configured, it sets it up and reboots.
-> If it is already configured, it just does nothing.
-> If it doesn’t find a known WLAN, it sets up the AP from the config file and reboots.
With this script, I can switch my HM on anywhere without worrying about the last WLAN setting and end up with a HM I can connect to.

It works perfectly for me, maybe it helps someone else, maybe it could even be added (in this or an optimized version) to further versions of the HM software.

You can download the files here, for convenience.
 
and here is the script to look at (too many lines for one post):

config file is "/etc/switch_wifi.conf"
Code:
ap_ssid="Wifi_18765"
ap_bssid="aa:bb:cc:dd:ee:ff"
ap_channel="6"
ap_encrypt="psk2"
ap_key="20g3dsdsd5"

net1_ssid="Wifi_18765"
net1_bssid="aa:bb:cc:dd:ee:ff"
net1_channel="6"
net1_encrypt="psk2"
net1_key="20g3dsdsd5"

net2_ssid="wifiHome"
net2_ssid="aa:bb:cc:dd:ee:ff"
net2_channel="6"
net2_encrypt="psk2"
net2_key="68b6sd2dAx30"

net3_ssid=""
net3_ssid=""
net3_encrypt=""
net3_key=""

boot script is /etc/init.d/switch_wifi
Code:
#!/bin/sh /etc/rc.common

START=99
            
start() {
        /usr/bin/scan_wifi.sh                                        
}

the actual script is "/usr/bin/scan_wifi.sh"
Code:
#!/bin/sh
. /etc/switch_wifi.conf

SendToLCD()
{
         lmclient LMST,tt,"$1","$2"
}

logger "SCANWIFI: Performing network scan..."
SendToLCD "Scanning for" "known networks"

DoReboot=0
OldSSID=`uci get wireless.@wifi-iface[0].ssid`
n=0
scanres=
while [ "$scanres" = "" ]; do
        #Sometimes it shows nothing, so better to ensure we did a correct scan
        scanres=$(iw wlan0 scan|grep SSID)

        n=$(expr "$n" + "1")
        #max 200 tries... if something goes wrong, we should have an exit route.
        if [ "$n" = "200" ]; then
                #didn't find any SSIDs. breaking loop!
                logger "SCANWIFI: didn't find any SSIDs. breaking loop!"
                break
        fi
done

logger "SCANWIFI: Searching available networks..."

#start with first one in config
n=0

while [ "1" ]; do
        n=$(expr "$n" + "1")
        #max 99 wireless networks - should be enough.
        if [ "$n" = "99" ]; then
                #too many networks - or something else went wrong. Breaking the loop!
                break
        fi

        #get the network name
        ssid=net"$n"_ssid
        eval ssid=\$$ssid

        if [ "$ssid" = "" ]; then
          # ssid not existing or empty. Assume it's the end of the white list file
                # I will have to set up my own one...
          if [ "$ap_ssid" != "" ]; then
               #This is the way to disable the AP mode...
               echo -----------------------------------------------
               if [ "$OldSSID" != "$ap_ssid" ]; then
                    logger "SCANWIFI: didn't find any known networks. I will got to AP mode."
                          echo "didn't find any known networks. I will got to AP mode."
                          SendToLCD "None found" "Switching to AP"
                          #
                          # Configure DHCP for AP network
                          #
                          uci delete dhcp.wwan
                          uci set dhcp.wwan=dhcp
                          uci set dhcp.wwan.interface=wwan
                          uci set dhcp.wwan.start=50
                          uci set dhcp.wwan.limit=200
                          uci set dhcp.wwan.leasetime=1h
                          uci commit dhcp

                          uci del network.wwan.hostname
                          uci set network.wwan.ipaddr=192.168.201.1
                          uci set network.wwan.netmask=255.255.255.0
                          uci set network.wwan.proto=static
                          uci commit network

                          uci set wireless.radio0.hwmode=11ng
                          uci del wireless.radio0.disabled=0
                          uci del wireless.radio0.channel=11
                          uci del wireless.radio0.txpower=20
                          uci del wireless.radio0.country=00
                          uci set wireless.radio0.channel="$ap_channel"
                          uci set wireless.@wifi-iface[0].mode="ap"
                          uci del wireless.@wifi-iface[0].bssid
                          uci set wireless.@wifi-iface[0].ssid="$ap_ssid"
                          uci set wireless.@wifi-iface[0].encryption="$ap_encrypt"
                          uci set wireless.@wifi-iface[0].key="$ap_key"
                          uci commit wireless
    
                          logger "SCANWIFI: changed network. We will have to reboot..."
                          DoReboot=1
               else
                    logger "SCANWIFI: didn't find any known networks. AP mode already configured."
                    echo "Didn't find any known networks. AP mode already configured."
                    SendToLCD "None found" "Staying AP"
               fi
          fi
          break
        fi                                                 
                                                           
        #Debug: spam what we are doing on command line     
        echo -----------------------------------------------
        echo "Looking for network:"
        echo SSID: $ssid
                                                   
                                                   
        #check if current network is available     
        active=$(echo $scanres | grep "$ssid">&1 )
        if [ "$active" ]; then            
                #get full set of parameters                                  
                bssid=net"$n"_bssid      
                channel=net"$n"_channel
                encrypt=net"$n"_encrypt
                key=net"$n"_key                                               
                eval bssid=\$$bssid              
                eval channel=\$$channel              
                eval encrypt=\$$encrypt                                
                eval key=\$$key                                         
                                                                        
                #check if we have to so something:                      
                if [ "$OldSSID" != "$ssid" ]; then                      
                        echo "Network found. setting it up for next boot:"
                        #Debug: output current parameters on command line         
                        echo BSSID: $bssid                                        
                        echo SECURITY: $encrypt                                   
#                       echo KEY: $key                                            
                                                                                  
                        logger SCANWIFI: "$ssid" network found. Applying settings..
                        SendToLCD "rebooting for:" "$ssid"           
                       
               uci set dhcp.wwan.ignore=1
               uci commit dhcp

#               uci del network.wwan.ipaddr
#               uci del network.wwan.netmask
               uci set network.wwan.proto=dhcp
               uci set network.wwan.hostname=HeaterMeter
               uci commit network

               uci del wireless.radio0.hwmode
                        uci set wireless.radio0.disabled=0
                        uci set wireless.radio0.channel=11
                        uci set wireless.radio0.txpower=20
                        uci set wireless.radio0.country=00
                        uci set wireless.radio0.channel="$channel"
                        uci set wireless.@wifi-iface[0].mode="sta"
                        uci set wireless.@wifi-iface[0].ssid="$ssid"
                        uci set wireless.@wifi-iface[0].bssid="$bssid"
                        uci set wireless.@wifi-iface[0].encryption="$encrypt"
                        uci set wireless.@wifi-iface[0].key="$key"
               uci commit wireless                                         
                                                                                    
                        logger "SCANWIFI: changed network. We will have to reboot..."
                        DoReboot=1                                                     
                else                                                          
                        echo Network found, aleready set up. No changes needed.                   
                        #Debug: output current parameters on command line                         
                        echo BSSID: $bssid                                                        
                        echo SECURITY: $encrypt                                                   
#                       echo KEY: $key                                                            
                        logger SCANWIFI: "$ssid" network found, aleready set up. No changes needed.
                        SendToLCD "up and running:" "$ssid"
                fi                                       
                                                            
                break                                    
        else                                             
                echo Network NOT found. Trying next one...    
        fi                                                             
done                                                        
                                                    
if [ "$DoReboot" = 1 ]; then                        
#       logger "SCANWIFI: I would have rebooted now!"                       
        reboot           
fi

Indenting doesn't look too nice here, but this is just cosmetic. But I wasn't able to set up an encrypted AP on the pi (as opposed to the example config file above).

Best,
Daniel
 
Last edited:
Daniel, this is very interesting.
I would like to be able to use the AP mode of the HeaterMeter when I'm in the garden and I'm not able to reach the WiFi that is in the house. Are you able to to this? if I understand well is not possible to do it without installing a new WiFi Adapter on the Raspberry PI.
Is correct?
I really don't understand if it's possible to configure the HeaterMeter to be a client of the house WiFi and, in the same time, to be the Access Point for a local WiFi (like the heatermeter in AP mode in the first part of the installation).
It would be helpful in the scenario I described above.

Ciao
Andrea
 
I'll look over this a bit more over the weekend, but I will say you can probably greatly simplify your script using the lua wifi library for scanning and the wifi-client and wifi-ap commands to switch between client and AP mode.

As far as not being able to connect more than once, maybe you can look into the 8192cu driver and figure out why :-D I got it working with OpenWrt but the amount of effort I had to go through to get it working was quite high and made me realize the code isn't perfect.
 
I might have to give this a try. If I understand this correctly it will connect to the configured WLAN (e.g. my house) if it is found during the startup scan otherwise go to AP mode? I want my HeaterMeter to work 80% of the time at home but on occasion I will take my smoker camping and I want to use my HM there where I can use my cell phone to monitor the smoke within my camper. I'm bringing Lazy-Q to a whole new level!
 
If your phone has hotspot mode, change the SSID and password to the one you use at home and your HeaterMeter should auto-connect to it when it boots!
 
@Tony L-Iowa:
Yes, it will do exactly that.

@Steve_M:
Will work, as long as your phone is on and within WLAN reach. But you would have to reboot your pi if you switched off your phone (HM cannot reconnect) or went out of reach (hiking, shopping, etc.) I prefers AP mode in this case.
 
I'll look over this a bit more over the weekend, but I will say you can probably greatly simplify your script using the lua wifi library for scanning and the wifi-client and wifi-ap commands to switch between client and AP mode.

As far as not being able to connect more than once, maybe you can look into the 8192cu driver and figure out why :-D I got it working with OpenWrt but the amount of effort I had to go through to get it working was quite high and made me realize the code isn't perfect.

Brian-
I'm getting ready to try some ideas on this thread. Did you ever look into the lua scripting and wifi-client, wifi-ap commands?
 
DanielK, it works well for me, I've configured:
1) is the home wifi network;
2) is the wifi created with my iPhone Hotspot;
3) is the wifi created by the HeaterMeter in the AP mode.
The only problem was in this last configuration.
I added those lines:
Code:
#
# Configure DHCP for AP network
#
uci delete dhcp.wwan
uci set dhcp.wwan=dhcp
uci set dhcp.wwan.interface=wwan
uci set dhcp.wwan.start=50
uci set dhcp.wwan.limit=200
uci set dhcp.wwan.leasetime=1h
uci commit dhcp
In the "Switching to AP" section, otherwise I was not able to connect.
Now it works very well and I'm so happy about this script.
Thank you very much.

Ciao
Andrea
 
Brian-
I'm getting ready to try some ideas on this thread. Did you ever look into the lua scripting and wifi-client, wifi-ap commands?
I was saying that it could be a lot simpler if the lua wifi module was used and then just call wifi-client or wifi-ap to switch.

I actually like this overall idea so much that I'm going to bake something similar into the next linkmeter version and the webui (along with the simplified client/AP configuration).
 
I was saying that it could be a lot simpler if the lua wifi module was used and then just call wifi-client or wifi-ap to switch.

I actually like this overall idea so much that I'm going to bake something similar into the next linkmeter version and the webui (along with the simplified client/AP configuration).

Hey Bryan,
nice to hear that I was able to contribute a bit (at least with the idea ;-).

As you mentioned the wifi-ap commands in the post, I saw them and realized that this would indeed make the script nicer and shorter. However, I didn't have time to look into it, and it was working for me. As for th lua scripting: I never got into this, so I realized my script in a way that I wouldn't have to get into reading too much first. And I know shell scripting a bit (or know where to get the information I need). But I indeed doubled something that should be there already for the web page.

Looking forward to a clean integration of that into the web page, thanks for your work Bryan!

Best,
Daniel
 
DanielK, it works well for me, I've configured:
1) is the home wifi network;
2) is the wifi created with my iPhone Hotspot;
3) is the wifi created by the HeaterMeter in the AP mode.
The only problem was in this last configuration.
I added those lines:
Code:
#
# Configure DHCP for AP network
#
uci delete dhcp.wwan
uci set dhcp.wwan=dhcp
uci set dhcp.wwan.interface=wwan
uci set dhcp.wwan.start=50
uci set dhcp.wwan.limit=200
uci set dhcp.wwan.leasetime=1h
uci commit dhcp
In the "Switching to AP" section, otherwise I was not able to connect.
Now it works very well and I'm so happy about this script.
Thank you very much.

Ciao
Andrea

Thanks Andrea,

I added it to post number 2, I will update the downloadable files soon.

Best,
Daniel
 
Daniel, I added also the "sync" command in every branch of the various "if then else" after a group of commit, I've read that is better before the reboot command.
It works for me.

Ciao
Andrea
 
I use 2 WiFi dongles. One set up for my home network, and one set up in AP mode. If I'm out of range for my home wifi, I can just connect to the "heatermeter" network via my mobile device. Works like a charm.
 
I use 2 WiFi dongles. One set up for my home network, and one set up in AP mode. If I'm out of range for my home wifi, I can just connect to the "heatermeter" network via my mobile device. Works like a charm.
WBegg, which WiFi dongle do you use? are both identical? It's interesting.
It's difficult to connfigure? I don't think so.

Ciao
Andrea
 
WBegg, which WiFi dongle do you use? are both identical? It's interesting.
It's difficult to connfigure? I don't think so.

Ciao
Andrea

Not difficult at all, Andrea. I did it so long ago, I can't remember what I did, but do know I had to set my HM to a static IP on my home WiFi, one that I could remember, because when I turn it on, it shows the AP address on startup. Both dongles are the ComFast WU715N.
 
So, thanks to Mr Bostwick (and of c ouse Bryan), this weekend was my first cook with a HM... I'm hooked. I'm looking for this exact functionality for the ability to easily drag my HM to competitions.

However, I am by no means close to being computer saavy enough to impliment this without some English - language instructions. 1) where do i put theses files, and how do i go about doing it? 2) i think I've figured it out enough to know that i need to edit the first file (in post #2) to contain my specific network, but I'm not sure how to do that.

I'm just getting started with the HM, so if any of this is already documented in the wiki, link would work, i like learning about this stuff.

As and aside, if this is going to be impli mente in short order, I'd probably just wait for that. Bryan, any timeframe on its inclusion?

TIA!

Don
 
Well, I was in a hurry doing this and I think I locked myself out of my HM. In DanielK's switch_wifi.conf script I used the HeaterMeter as the first two blocks (ap and net1). Now I have my home wifi defined for net2. For a while I had my home wifi for net1 while I was trying to debug getting the HM into AP mode. Now I can see my HeterMeter SSID while it's in AP mode but I can never get connected to it. I'm using the correct ap_key and net1_key (they are the same) for a password when I try to connect with my PC. I think I'm gonna have to take this apart to reflash. Thoughts on why I cannot seem to connect in to the HM in AP mode?

ap_ssid="Wifi_18765"
ap_bssid="aa:bb:cc:dd:ee:ff"
ap_channel="6"
ap_encrypt="psk2"
ap_key="20g3dsdsd5"

net1_ssid="Wifi_18765"
net1_bssid="aa:bb:cc:dd:ee:ff"
net1_channel="6"
net1_encrypt="psk2"
net1_key="20g3dsdsd5"

net2_ssid="wifiHome"
net2_ssid="aa:bb:cc:dd:ee:ff"
net2_channel="6"
net2_encrypt="psk2"
net2_key="68b6sd2dAx30"
 
Ok... I finally found my issue. Apparently the psk2 encryption don't work for OpenWRT while in AP mode? I switched to none for encryption and everything was fine.
 

 

Back
Top