Transmit power based on need

Discussion in 'Tomato Firmware' started by cobrax2, Nov 2, 2018.

  1. cobrax2

    cobrax2 Serious Server Member

    Hi guys
    I'd like to change the transmit power on my r7000 based on the existance of a client connected to the router.
    Specifically, if no device is wirelessly connected to the router, it should set the transmit power to some minimum that i will set. When a client connects, it should go back to full power. Then, when no other client is connected, it should go to sleep again.
    Can i script that somehow?
    Thank you!
     
  2. Sean B.

    Sean B. LI Guru Member

    The only way I can see for this to be implimented is to write a shell script that handles checking for clients on wifi and use the scheduler to repeatedly run it. This would be a time based event, as in a client connection itself would not immediately trigger a change in txpwr, how long it would take to happen after a client has connected would depend on how frequently you set the scheduler to run the script. It would be rather clunky so to speak, but doable.
     
    Techie007 likes this.
  3. cobrax2

    cobrax2 Serious Server Member

    that was what i was thinking too
    but how do i check for clients? with wl assoclist? could i query somehow the dhcp server? or make it run the script instead?
    if i set this script to run every, let's say 30 sec, would it overburden the router? also changing the tx power repeatedly would affect the router or its stability over time?
    thanks!
     
  4. Sean B.

    Sean B. LI Guru Member

    I would likely use the assoclist, as any output from the command means there's an associated mac. Making it rather easy to script a test for. No, it would not burden the router. The script would be a handful of lines of shell code, and run in no time flat. Changing the TX power would not affect stability. Nothing would need to be committed to NVRAM by the script, so there's no wear there either.

    ***EDIT*** My comment about stability was assuming you were referring to the overall stability and longevity of the router as a whole and if it would be negatively impacted by tx power level changes. It was not in regards to the stability of client connections on that radio, of which will vary dependent on many factors including the current tx power setting.
     
    Last edited: Nov 7, 2018 at 4:39 AM
  5. cobrax2

    cobrax2 Serious Server Member

    cool, thank you!
     
  6. jerrm

    jerrm Network Guru Member

    Curious as to why you want to do this. We are talking milliwatts, even on a multi-radio router any cost savings would be negligible even at European power costs, or is there another reason?
     
  7. Monk E. Boy

    Monk E. Boy Network Guru Member

    Yeah understanding why it's being done would be helpful. The minimum you'd want to set the transmitter to for power savings or health benefits or whatever may very well be so low you'll have trouble connecting to the router at all until you physically approach it.
     
  8. Sean B.

    Sean B. LI Guru Member

    I didn't want to open the "why are you doing that" can of worms on this one. I get the feeling I won't comprehend the reasoning.
     
    Techie007 likes this.
  9. cobrax2

    cobrax2 Serious Server Member

    lol
    i have a somewhat big house and already 2 routers. they dont cover it very well, and i'd like to add a third one.
    but i also have a 2 yo child, and despite what is discussed about the small or non-impact level of radiation the routers emit, i don't want to expose it to so many.
    i'm not paranoid, i dont' believe very much of this, but also i don't want to take a risk, no matter how insignificant it may be, especially if there is an easy way to avoid it...
    yes, if there will be a problem that i can't connect at all, i'll have to find another way :)
     
    Techie007 likes this.
  10. jerrm

    jerrm Network Guru Member

    Increasing the beacon interval would reduce the overall RF exposure for idle wifi with less fuss.
     
    Techie007 likes this.
  11. Techie007

    Techie007 Serious Server Member

    I was going to suggest that as well—I do it for the same reason on all my networks. But don't go higher than 1000ms as some devices will start to think the router isn't responding and won't connect. I find that 500ms works best, as some devices won't stay connected while sleeping when at 1000ms. But maybe you want that behavior, or maybe none of your devices will exhibit this behavior. A beacon interval of 500ms is 1/5 the default amount of RF energy during idle. The beacon is what causes the router to emit RF energy all the time, even when not in use. But it is also what causes your router's WiFi hotspot to show up in the list of available connections on your devices.
    You can find this setting in Advanced -> Wireless -> Beacon interval. The default value is 100ms. Also make sure that WMM and APSD are enabled, while No ACK and Wireless Multicast Forwarding are disabled.


    I find your idea of reducing the wireless transmit power when there are no active connections novel. I tested the txpwr changing commands on my Tenda AC15 and they changed the signal strength immediately without interrupting WiFi connections at all. One caveat with this idea however (since you mentioned that there are two other hotspots in the house) is that with the lower signal strength, devices will be less likely to roam to this hotspot and will choose to stay connected to one of the others as long as possible.

    Yes, you would use wl assoclist to detect the presence of wireless clients and wl txpwr to change the signal strength. I am assuming that you're not using 5 GHz. If you are, disabling it completely would be the first thing to do to reduce RF emissions from your router: If you care about RF emissions and WiFi range, you will stay away from 5 GHz. If that's not an option, you will probably have to modify the wl commands to target the 5 GHz radio too. To my knowledge, you cannot schedule a script to run any more frequently than 1 minute in Tomato. But, that's probably not an issue: I'd stick the script in the Init section and make it an endless loop with a Sleep 5 or Sleep 10 instruction to keep CPU usage minimal.
     
  12. cobrax2

    cobrax2 Serious Server Member

    oh, so the router doesn't emit anything besides that beacon if nothing is connected to it? i had no idea
    this is indeed a good thing to try first
    thanks guys!

    the 5ghz radios are off, not getting through the walls :)
     
  13. Justio

    Justio Networkin' Nut Member

    Any chance to have the script shared here on the forum?

    FYI i have set more than 2 years ago the Beacon interval to 2000ms. No issue detected or connections pbs. until now (on 2.4 Ghz channels, and with 2 different routers - different locations)
     
  14. Techie007

    Techie007 Serious Server Member

    Absolutely! Below is my script for automatically adjusting the txpower. As is, this script checks every five seconds and drops the signal strength down as low as possible if no clients are connected, and boosts it to full power if any clients are detected (even ones trying to connect). I recommend adding this script to your Administration -> Scripts -> Init section. You would then need to reboot the router for the changes to take effect. Feel free to adjust the power levels to suit your needs (for example, you might not need full power, and lowest power might be too low for devices far away to see the "sleeping" router and connect). You can verify that the script is working either by using an app like WiFiAnalyzer on a mobile device, or by checking the router's log.

    Code:
    while true
    do
      while [ ${#cinfo} -gt 16 ]
      do
        sleep 5
        cinfo=$(wl assoclist)
      done
      logger WiFi entering low power mode
      wl txpwr 1
    
      while [ ${#cinfo} -lt 16 ]
      do
        sleep 5
        cinfo=$(wl assoclist)
      done
      logger WiFi entering high power mode
      wl txpwr 400
    done
    My comments about the beacon interval are regarding observations with some of the devices on my network. I start having troubles with Windows PCs not connecting or staying connected reliably over 1000ms, and I have an older Android tablet that disconnects after a minute or two of sleeping if it's over 500ms. If you're not experiencing these issues with your devices at high beacon intervals, good for you! My preference is that higher is better, but technology needs what it needs sometimes! :)

    One way this script could be improved would be to evaluate the signal strengths of all the connected devices and boost the txpower only when a connected device's signal strength is low. It would be possible (but a little complicated) to write such a script, and that is beyond my bash scripting skills at the moment. I believe you would need to loop through each of the MAC addresses returned by wl assoclist, and pass them (one at a time) to wl rssi, and then make a signal strength decision based on the results. One issue you would run into however, is that devices connected to a virtual WiFi interface would return an error unless you specified the interface by name (e.g. wl -i wl0.1 rssi).
     
    Last edited: Nov 11, 2018 at 7:08 PM
    Justio likes this.
  15. Sean B.

    Sean B. LI Guru Member

    The received signal strength indication ( RSSI ) of a connected device is a measure of the received signal from that device. To improve the RSSI of a device as seen from the router, the transmit power would need to be adjusted on that device, not the router. The router has no ability to determine the RSSI of its transmitted signal as measured at the receiving end, the connected device. The two are mutually exclusive, in that RSSI levels on one end do not correlate to RSSI levels on the other. You could have very low RSSI levels from a device as seen on the router, yet have very high RSSI levels from the router as seen on the device.
     
    Last edited: Nov 11, 2018 at 11:25 PM
  16. Techie007

    Techie007 Serious Server Member

    True, and that is one of the shortcomings in the current WiFi protocols; but the RSSI is still a good indication of whether the device is nearby and easy to reach, or farther away/behind walls with poor signal quality. If the router is having a hard time receiving the device (RSSI -70 to -90), it's a good guess that the device may also be having a hard time receiving the router, and a good clue to boost transmit power to at least alleviate the issue from one side. Conversely, if you're sitting on the sofa 10 feet from the router, RSSI would be good (-30 to -50) and the lowest TX power would be more than adequate!
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice