Arduino Forum

Using Arduino => Networking, Protocols, and Devices => Topic started by: vincentmckenzie on Feb 01, 2013, 06:25 pm

Title: Arduino Network causing severe battery drain on WiFi connected devices.
Post by: vincentmckenzie on Feb 01, 2013, 06:25 pm
So I have a weather station that uploads weather data to COSM every 10 seconds. This works fine.

However, I noticed that when my Weather Station is running, the battery life on all of the mobile devices that are connected to the network via WiFi (i.e. several mobile phones, couple of tablets, various brands/types) is terrible. To put this difference in perspective, with the Weather Station on, the battery life on my phone is about 4 hours. With the Weather Station off it's 2 days. This is repeatable every time.

I can see from some diagnostics on my phone that 98% of the battery use is due to WiFi RX Wakelocks. In other words, it's receiving stuff on WiFi and having to wake up deal with it.

Wireshark tells us what the problem is. Every time the Weather Station uploads its data to the internet it sends an ARP broadcast:

ARP Who has 192.168.0.1?  Tell 192.168.0.20


192.168.0.20 is the IP of the Weather Station, and 192.168.0.1 is the gateway.

So what it's doing is trying to get the MAC address for the router from its IP address so that it can communicate with it. This is absolutely normal... ONCE (it should store the MAC address in its ARP table), but it does this every time it tries to connect. The rest of my devices only send such ARP broadcasts once after a reboot.

Does anybody have any suggestions on how to fix or work around this?
Title: Re: Arduino Network causing severe battery drain on WiFi connected devices.
Post by: pylon on Feb 01, 2013, 08:33 pm
What kind of Arduino Wifi hardware are you using?
Title: Re: Arduino Network causing severe battery drain on WiFi connected devices.
Post by: wildbill on Feb 01, 2013, 10:17 pm
Interesting. I see the same thing happening with my arduino ethernet: every time it wants to talk to its target web server, there is an ARP request. Mind you, there's a bunch more ARP requests going on that don't make sense either - some of them generated by the router, and my Mac and XP box seemingly can't remember each others MAC address. I suspect that the same thing is going on with my wifi shield too but I can't see that traffic with wireshark.
Title: Re: Arduino Network causing severe battery drain on WiFi connected devices.
Post by: JohnHoward on Feb 02, 2013, 02:06 am
Put a cheap router between them and have two subnets (such as 198.168.0.* and 198.168.1.*), or if your gear is capable, change the routing in it to implement this.  The ARPs will not find their way off the arduino's subnet to the other one where your phones and tablets are connected.

I'll hedge a bit and say I'm pretty sure that will solve the problem, but not 100%.  ARP is OSI L1 and therefore does not pass through the router.
Title: Re: Arduino Network causing severe battery drain on WiFi connected devices.
Post by: vincentmckenzie on Feb 02, 2013, 04:40 pm
Thanks for the replies so far. To answer everyone...

I'm using an Arduino Ethernet, not a WiFi one: http://arduino.cc/en/Main/ArduinoBoardEthernet

I tried putting it on another subnet (192.168.1.20 as opposed to 192.168.0.20), but the requests still appear on every device on the LAN. I'm guessing this is because they're sent to a MAC of FF:FF:FF:FF:FF:FF. I didn't try putting another router between the device as I don't have a spare. Really though, I don't want yet another device plugged in with even more cabling, when this seems like a an issue that could be fixed in the library or code.
Title: Re: Arduino Network causing severe battery drain on WiFi connected devices.
Post by: pylon on Feb 04, 2013, 03:21 pm
It's not the subnet that holds back the ARPs, it a different segment, so you need a router between the two segments. Depending on the router you're using for your WLAN you may have the possibility to separate the WLAN and LAN part of your network. For example if you're using OpenWRT on your WLAN router, this is possible.
Title: Re: Arduino Network causing severe battery drain on WiFi connected devices.
Post by: vincentmckenzie on Feb 04, 2013, 06:47 pm
Thanks for the clarification - much appreciated. I was sort of naively hoping that putting it on another subnet would be enough as some broadcasts I see on Wire Shark are sent to 192.168.0.255 and I also hoped the router would segment the subnets itself given everything on the other subnet is all coming off one port on the router.

If this can't be fixed in the Ethernet code (or mine), then I'll look at getting an additional router. The one I have doesn't have an OpenWRT port (yet).

I'm hoping that when I have time to trawl through the network libraries I'll be able to find a place where I can add entries to an ARP table.
Title: Re: Arduino Network causing severe battery drain on WiFi connected devices.
Post by: pylon on Feb 04, 2013, 07:45 pm
ARP isn't done on the Arduino processor but by the WizNet5100 itself, so you cannot change the Ethernet library to work around that.

Have you checked your routers configuration if there isn't an option to separate the wireless from the fixed network? Some of the routers (even without an Open Source firmware) offer such an option.
Title: Re: Arduino Network causing severe battery drain on WiFi connected devices.
Post by: vincentmckenzie on Feb 04, 2013, 08:44 pm
I'll not check the Ethernet library then :) Thanks for saving me a lot of time there.

It's a shame there's no function to add an IP address with its MAC too so it never has to try and get that info from the network. Obviously on Windows or Linux you can manually add a static ARP entry with the arp command.

On my router I can "isolate" any of its WiFi networks, which means all devices using that SSID have no access to the LAN and can only access the internet. This does work and would be a good solution but I need to access my LAN from wireless devices (e.g. VNC/Remote Desktop from my phone to PC).

Unless there's some undocumented arp command, it looks like I'll need a cheap router. There's another device that is (optionally) connected to my network that does this every second (another embedded system) so that sweetens the situation a bit.
Title: Re: Arduino Network causing severe battery drain on WiFi connected devices.
Post by: SurferTim on Feb 04, 2013, 08:49 pm
Just because I am curious (and use a lot of routers) what make/model router do you have now?
Title: Re: Arduino Network causing severe battery drain on WiFi connected devices.
Post by: vincentmckenzie on Feb 05, 2013, 12:01 am
Asus RT-N66U
Title: Re: Arduino Network causing severe battery drain on WiFi connected devices.
Post by: billroy on Feb 05, 2013, 12:09 am
The Arduino gets its revenge on all those devices with the fancy power saving.  Denial of service by battery depletion.  Not a novel attack, but possibly a novel vector.

-br
Title: Re: Arduino Network causing severe battery drain on WiFi connected devices.
Post by: SurferTim on Feb 05, 2013, 11:28 am
I downloaded that router manual, just because I haven't used it before, but it seems fairly easy to set up. It appears by the manual the wireless network will use 192.168.1.1/24.

edit: I do not see any ethernet LAN ports on that box.
Title: Re: Arduino Network causing severe battery drain on WiFi connected devices.
Post by: vincentmckenzie on Feb 05, 2013, 12:26 pm
You sure you got the right manual? Check here: http://www.asus.com/Networking/RTN66U/

As you can see from the description it has 4 gbit LAN and 1 gbit WAN (which you can also use as a normal LAN port if you're using the router in just Access Point mode).

The RT-N66U is an awesome little router. Just this morning I was telnetted into its Linux shell and reading of the temperatures from three temperature sensors on the board. It's a geek-boy's dream ;)
Title: Re: Arduino Network causing severe battery drain on WiFi connected devices.
Post by: vincentmckenzie on Feb 05, 2013, 12:28 pm
Forgot to say... I'm not sure where those IP ranges are coming from. There is only one place to set the IP and MASK that the router will use. It uses the same for both LAN and WLAN. Even in the DHCP settings it won't let you set IPs out of the range of that single IP + Mask.
Title: Re: Arduino Network causing severe battery drain on WiFi connected devices.
Post by: SurferTim on Feb 05, 2013, 12:41 pm
My bad. I downloaded the wrong manual. I have the correct one now. I would go into the router settings and check your LAN settings. What ip/subnet does it show? It should be 192.168.1.1.

I would also check the dhcp server settings for your LAN. Avoid using any (add: static) ips in that range.

edit: Try dhcp on the ethernet shield. Does it pick up an ip?
Title: Re: Arduino Network causing severe battery drain on WiFi connected devices.
Post by: vincentmckenzie on Feb 05, 2013, 01:01 pm
I'm using 192.168.0.0/24 (but that's OK obviously). DHCP is off (I prefer static IPs). There's no way to specify independent IP ranges for the LAN and WLAN in the settings.

However, this isn't a WLAN / LAN / IP / Subnet type issue - it's an ARP Broadcast issue. It wouldn't matter what IP or subnet I was using because the broadcasts are sent to FF:FF:FF:FF:FF:FF, so they hit every device on the same network segment. As I only have one router the entire LAN/WLAN is the same segment. The only thing my router is blocking broadcasts from/to is the WAN.

The only way to prevent broadcasts spreading too far is to add a segment to the network by adding another router as routers don't normally allow broadcasts to pass through. I could, for example, add another WiFi Access Point router and put all my mobile devices on that. But again that's additional hardware that I'd like to avoid.
Title: Re: Arduino Network causing severe battery drain on WiFi connected devices.
Post by: SurferTim on Feb 05, 2013, 01:13 pm
That is odd. I haven't checked my network for that. When I get a chance, I will. Mine might be doing that, but I do not see any noticeable indication yet.

edit: I probably wouldn't see anything on my wireless network. My wireless and ethernet are separate networks, so I wouldn't see the effect on my mobile devices.
Title: Re: Arduino Network causing severe battery drain on WiFi connected devices.
Post by: vincentmckenzie on Feb 05, 2013, 01:33 pm
You can see broadcasts on Wireshark if you want to look for it. Just download it, install it, run it, and set a filter for "eth.dst == ff:ff:ff:ff:ff:ff".

It's normal for every device on the network to send out the ARP "Who has <ip>" requests the first time they try to communicate with that IP. It's a bit like the way DNS works, in that when you enter "google.com" as an address, a DNS server will look up that IP address for that domain name and you'll use the IP address. A MAC is looked up by IP address by asking every device on the network "Who has <ip>". The device that has that IP will respond with its MAC address and then the two devices can then communicate.

For example, if you reboot your PC, the first time it tries to connect to the internet it will send out a "Who has 192.168.1.1" broadcast (assuming 192.168.1.1 is your gateway's IP and you have that IP set as the default gateway on your PC). Whichever device has that IP address will respond back with its MAC address. Then your PC will know what MAC address to send stuff to when communicating with your gateway.

What is meant to happen, however, is that the MAC address for a given IP address is meant to be stored in the device's ARP table. You can see the ARP table on Windows by opening a command prompt and doing "arp -a". This table prevents the need to ask all the devices on your network who has a given IP address every time you want to talk to that IP because the device already knows that information and has remembered it. You can also add MAC addresses manually and permanently (until you manually delete them) with something like "arp -s 192.168.1.1 00-aa-bb-cc-dd-ee".

So the problem with the Arduino Ethernet is that these ARP entries are not being cached and it's asking the entire network who has the gateway's IP address every time it sends stuff. Ideally it should cache the IP to MAC address entries, but I'm guessing with limited memory on the Ethernet card this isn't possible. Also it would be nice if you could tell it in code what the MAC address of an IP is(i.e. the same as "arp -s"), as it's not very often my router changes MAC addresses.
Title: Re: Arduino Network causing severe battery drain on WiFi connected devices.
Post by: SurferTim on Feb 05, 2013, 01:40 pm
Thanks, but I think I have that part down.  ;)

I just have never checked the ARP broadcast before. Like I said, my wireless and ethernet ports are separate networks. I can bridge them, but I don't. When I do my send every 30 seconds, I am not likely to notice one extra pre-send ARP broadcast unless I was looking.

I do use the DNS thing with the w5100 tho. Instead of using a domain for each send, which does a dns lookup for every send, I do one dns request, then use that ip for a while. That really speeds up things.

edit: I think I see what you are saying now. You think that extra ARP broadcast is causing the mobile device "wake-on-lan" to activate?
Title: Re: Arduino Network causing severe battery drain on WiFi connected devices.
Post by: vincentmckenzie on Feb 05, 2013, 03:10 pm
Not quite... Wake-On-Lan is to remotely turn on a device (such as a laptop or PC that's turned off / hibernated / suspended). They would normally completely ignore all network traffic, including ARP broadcasts, unless it received a "Magic Packet": http://en.wikipedia.org/wiki/Wake-on-LAN#Magic_packet

What I'm talking about is a bit different. When a modern mobile device, such as an Android phone or iPhone, isn't doing anything, it goes into a low power state - essentially dropping the CPU clock speed down to something very small, turning off circuits that aren't needed, reducing the RAM refresh, etc.

When they receive an ARP broadcast though, they will go to full speed so that they can deal with it. It is normally advantageous for the device to stay at full speed for a while so that other processes can catch up and not immediately require it to wake up again (as powering up everything causes a reasonably battery hit on its own). So it'll normally stay awake for a few seconds, then go back into a power save mode. I can't speak for all devices, but on my phone it'll stay awake for at least a few seconds when woken up. So, sending frequent broadcasts to the device that require it to wake up can cause it to stay fully awake forever.

This is exactly what's happening with me based on the following evidence:
Title: Re: Arduino Network causing severe battery drain on WiFi connected devices.
Post by: SurferTim on Feb 05, 2013, 03:43 pm
That is what I meant. I didn't know exactly what the term would be for that. It must be a "wake-on-something" tho. How about "wake-on-arp"?
Title: Re: Arduino Network causing severe battery drain on WiFi connected devices.
Post by: vincentmckenzie on Feb 05, 2013, 03:50 pm
From the device's perspective they're called "Wakelocks". Or specifically in this case WLAN_RX_WAKE Kernel Wakelocks. The device is in full power mode while a Kernel Wakelock is held. You can also have Partial Wakelocks which can be held by applications.
Title: Re: Arduino Network causing severe battery drain on WiFi connected devices.
Post by: SurferTim on Feb 05, 2013, 03:58 pm
I'll go with that. "Wakelock" appears to be specifically an Android term, but it sounds good. Almost all Google search items involved Android.

So it seems your alternative is to isolate your wireless devices from the ethernet devices. I'm not sure how to stop the w5100 from doing the ARP broadcast, but I will take a look.
Title: Re: Arduino Network causing severe battery drain on WiFi connected devices.
Post by: vincentmckenzie on Feb 05, 2013, 04:26 pm
It comes down to 4 choices (in order of my preference):


Buying a router costs me money and uses up more space, power sockets, cabling.

Isolating my WiFi is a no good for me as my WiFi devices need access to the LAN (e.g. printers, remote desktop, NAS, etc).

So I'm hoping for one of the top 2. I've failed to find anything myself though. :(
Title: Re: Arduino Network causing severe battery drain on WiFi connected devices.
Post by: SurferTim on Feb 05, 2013, 04:36 pm
I'm experienced with the w5100 and w5200 versions of the ethernet library, and I do not see where the arduino or wiznet library code is involved with an arp broadcast. I think that is done by the w5100 firmware internally when it establishes the connection.

The w5100 doesn't have a bunch of internal SRAM. Most is taken by the 4 socket buffers. It doesn't leave much for arp lists.  :(
Title: Re: Arduino Network causing severe battery drain on WiFi connected devices.
Post by: pylon on Feb 05, 2013, 04:50 pm
You told you can log into your router by telnet and have a linux environment there? Do you have root access then? If yes, you probably can segment your WLAN from your LAN without loosing connectivity. You just have to remove the (software) bridge between the interfaces and enable ip_forward on the router. Configure two subnets and you're fine.
Title: Re: Arduino Network causing severe battery drain on WiFi connected devices.
Post by: vincentmckenzie on Feb 05, 2013, 04:57 pm
It seems to be root access. While I'm very familiar with Linux, I've never had to do that kind of stuff on it before. However, I'm also chatting to a guy who makes one of the more popular custom firmwares for it to see if he can help.

I wonder if an iptables rule could filter it...
Title: Re: Arduino Network causing severe battery drain on WiFi connected devices.
Post by: pylon on Feb 05, 2013, 05:32 pm
You probably don't need iptables for that. Does the router have the "ip" command? Can you post the output of "ip ro sh"?
Title: Re: Arduino Network causing severe battery drain on WiFi connected devices.
Post by: vincentmckenzie on Feb 05, 2013, 07:07 pm
You'll understand if I blank out some of the IPs :)

So it's obviously bridged the relevant devices (giving br0). At this point I'm getting scared to bugger around with it :D

admin@RT-N66U:/tmp/home/root# ip ro sh
217.X.X.X dev ppp0  proto kernel  scope link  src VincentMcKenzie'sWAN-IP
192.168.0.0/24 dev br0  proto kernel  scope link  src 192.168.0.1
169.254.0.0/16 dev eth0  proto kernel  scope link  src 169.254.128.143
127.0.0.0/8 dev lo  scope link
default via 217.X.X.X dev ppp0
Title: Re: Arduino Network causing severe battery drain on WiFi connected devices.
Post by: pylon on Feb 06, 2013, 11:11 am
Quote
You'll understand if I blank out some of the IPs


Sure, didn't expect anything else.

Quote
So it's obviously bridged the relevant devices (giving br0). At this point I'm getting scared to bugger around with it


No reason to get scared. At this level (without saving anything) if anything goes wrong, just unplug your router from power and replug it, it will boot in a state as it was before.

We have to split the WLAN interface from the bridge. The command f

or this is:

Code: [Select]
brctl delif br0 <wlan-interface>

where <wlan-interface> stands for the name of the wireless interface. The command

Code: [Select]
iwconfig

should give you the list of your interfaces, all marked "no wireless extensions." are not of interest. You probably have only one with more information, that's your WiFi interface.

Before you split the bridge with the above command, issue the following command to activate ip forwarding (router functionality). Although this is probably already the case, it's just a precaution.

Code: [Select]
echo "1" > /proc/sys/net/ipv4/ip_forward

If you've done this, your WiFi interface should be in a separate segment. We still need to configure ip addresses and we have to check what netfilter rules are active.

To do all the commands be sure to use one of the ethernet ports on the router, do not use your WLAN for that, because that might be interrupted during the commands.

If you've done the above, please post the output of the following commands (again: changing public IPs to placeholders is perfectly viable):

Code: [Select]
ifconfig

iptables -L -n
Title: Re: Arduino Network causing severe battery drain on WiFi connected devices.
Post by: SurferTim on Feb 06, 2013, 11:58 am
Quote
No reason to get scared. At this level (without saving anything) if anything goes wrong, just unplug your router from power and replug it, it will boot in a state as it was before.

Not true with all routers. If I modify a setting, there is no need to save. Unless I am in safe mode, the change is immediate and permanent. Good thing I have a serial port to access the router to get the default config back.

Otherwise, it is no big thing as long as you can afford a new one.
Title: Re: Arduino Network causing severe battery drain on WiFi connected devices.
Post by: vincentmckenzie on Feb 06, 2013, 12:36 pm
Yeah I've changed other things on this router and changes like this are usually persistent. For example I've changed the brightness of the LEDs by simply piping numbers into the right /dev and it stays that brightness after a reboot.

If this weren't a router that I need all the time for my job I'd be more than comfortable messing around with it, but I have concerns - for example br0 is mentioned in various scripts on the device - so what happens when the web interface tries to configure stuff using these scripts that reference br0? If the bridge is split, that means there'll be two separate devices to configure but again the web interface only expects one.

There's also another problem in that I actually do need to receive some broadcasts onto my Wireless devices. For example I use an app on my phone that monitors log server broadcasts for stuff :/

I really wish there was a way to fix the Arduino side of this.
Title: Re: Arduino Network causing severe battery drain on WiFi connected devices.
Post by: SurferTim on Feb 06, 2013, 12:46 pm
Quote
I really wish there was a way to fix the Arduino side of this.

I do not see where the library code is involved with an ARP broadcast. I still believe that is accomplished by the firmware in the w5100.

You can check. The library code from Wiznet and Arduino is available as source code in your IDE.
/libraries/Ethernet/
and
/libraries/Ethernet/utility/
Title: Re: Arduino Network causing severe battery drain on WiFi connected devices.
Post by: pylon on Feb 06, 2013, 02:30 pm
Quote
Not true with all routers. If I modify a setting, there is no need to save. Unless I am in safe mode, the change is immediate and permanent. Good thing I have a serial port to access the router to get the default config back.


This is probably the case if you use the Web interface for configuring things. But if you use the command line I haven't seen a device yet that automatically saves that in a non-volatile storage.

Quote
Yeah I've changed other things on this router and changes like this are usually persistent. For example I've changed the brightness of the LEDs by simply piping numbers into the right /dev and it stays that brightness after a reboot.


I didn't write you should reboot the device but unplug from power. That way there's no possibility to shutdown the device and store current settings in EEPROM or flash.

Quote
for example br0 is mentioned in various scripts on the device - so what happens when the web interface tries to configure stuff using these scripts that reference br0? If the bridge is split, that means there'll be two separate devices to configure but again the web interface only expects one.


After doing such stuff on the command line you shouldn't use the web interface to configure the device. I just wanted to give you an opportunity to use your current device and have the segments separated.

I don't see a chance to change anything on the Arduino side. Embedded devices usually don't have enough memory to cache an ARP table.
Title: Re: Arduino Network causing severe battery drain on WiFi connected devices.
Post by: SurferTim on Feb 06, 2013, 02:36 pm
Quote
This is probably the case if you use the Web interface for configuring things. But if you use the command line I haven't seen a device yet that automatically saves that in a non-volatile storage.

I have used many brands of routers, and now I use MikroTik routers. They work really well. I do not use the web interface. I am a CLI kinda guy. Here is a topic on another forum that describes what I do when I lock myself out of one of my remote routers:
http://forum.mikrotik.com/viewtopic.php?f=2&t=29388&p=142934&hilit=curse#p142934
Without the serial cable, the router would be bricked.

Unless you are in safe mode, the changes are immediate and permanent.
Title: Re: Arduino Network causing severe battery drain on WiFi connected devices.
Post by: pylon on Feb 06, 2013, 02:57 pm
Is that MikroTik router running Linux? It doesn't look like to me. If I change configuration file that are stored in the flash file system changes are permanent. But by just issuing commands to devices I just change a state and this state-change is volatile.
Title: Re: Arduino Network causing severe battery drain on WiFi connected devices.
Post by: SurferTim on Feb 06, 2013, 03:02 pm
I believe it is a highly modified Linux, but that is really not the point. The OP stated that he changed a setting, and without saving anything, it kept that setting through a reboot. That is a good sign that it is saving that setting without a "save" command.
Title: Re: Arduino Network causing severe battery drain on WiFi connected devices.
Post by: pylon on Feb 06, 2013, 04:40 pm
That's a good sign that it save it during a reboot but not on a power cycle. The commands I posted are standard Linux commands, none of them is saving anything. But the OP doesn't seem to be interested, so we're just loosing time here.
Title: Re: Arduino Network causing severe battery drain on WiFi connected devices.
Post by: vincentmckenzie on Feb 06, 2013, 04:49 pm
Changes made are saved in a device mapped off /dev/nvram, which I assume is "Non-volatile RAM". All changes you make on this router are persistent even after a power cycle.

But yes, I don't want to waste anyone's time. I'm not comfortable messing around with this router like that, especially given the references to br0 in so many places.

If there's no way to fix it from the Arduino side I'll "borrow" a router from work and if that fixes it stick with that.

Seriously though - this thread has been very valuable to me, and I greatly appreciate everyone's help.
Title: Re: Arduino Network causing severe battery drain on WiFi connected devices.
Post by: SurferTim on Feb 06, 2013, 04:51 pm
Quote
But the OP doesn't seem to be interested, so we're just loosing time here.

Better than losing money. I would not recommend anything that might brick a customer's router.

I agree with you, Vincent.