What's new

Tutorial How to automatically reboot Xfinity Gateway (xFi)

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

t1100mfp

New Around Here
Hi,

I would like to share the script I created to automatically reboot daily my Xfinity Gateway.

I came up with it because the router started gave ridiculously low download speeds (~20Mbps) and doing a reboot solved the issue.

I used my Raspberry Pi 4 to do the job, but any computer running Linux can be used.

Xfinity Gateway (xFi) hardware information:
- Model:CGM4981COM
- Vendor:Technicolor
- Hardware Revision:2.0

Computer prerequisites:
- Python 3 available, with Selenium installed
- Firefox installed
- Download the Selenium geckodriver (if possible copy it to /usr/local/bin)
- Install the python script using crontab -e, and remember to define the PATH var to include the path where the geckodriver was placed, e.g.
Code:
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games
0 5 * * *  /home/hugo/scripts/reboot-xfi.py 2>&1 >> /home/hugo/scripts/output.log

You can use https://crontab.guru/ to see more options.

Here's the script:
Python:
#!/usr/bin/python3

from selenium import webdriver
from selenium.webdriver import FirefoxOptions
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
import logging
import sys
import time

DEBUG=False

logging.basicConfig(
#    filename="selenium-test.log",
    format="%(asctime)s %(levelname)s %(message)s",
    stream=sys.stdout,
    level=logging.INFO
)

# credentials
username = "admin"
password = "xxx" # put your own password

if __name__ == "__main__":
    logging.info("STARTING application")

    opts = FirefoxOptions()
    opts.add_argument("--headless")

    logging.info("Creating driver (opening browser window)")
    driver = webdriver.Firefox(options=opts)

    logging.info("Loading login page")
    driver.get("http://10.0.0.1")

    logging.info("Entering login information")
    driver.find_element(By.ID, "username").send_keys(username)
    driver.find_element(By.ID, "password").send_keys(password)

    logging.info("Submitting login form")
    driver.find_element(By.CLASS_NAME, "btn").click()

    WebDriverWait(driver=driver, timeout=10).until(
        lambda x: x.execute_script("return document.readyState == 'complete'")
    )

    logging.info("Loading reset webpage")
    driver.get("http://10.0.0.1/restore_reboot.jst")

    WebDriverWait(driver=driver, timeout=10).until(
        lambda x: x.execute_script("return document.readyState == 'complete'")
    )

    logging.info("Clicking reset button")
    driver.find_element(By.ID, "btn1").click()

    if not DEBUG:
        logging.info("Confirming dialog box")
        driver.find_element(By.ID, "popup_ok").click() # the gateway modem takes aprox. 2 minutes to be online again

    logging.info("Waiting for the reset action to be processed")
    time.sleep(30)  # sleep for 30 seconds, this will give time for the request to be processed and to be logged out

    logging.info("Quitting driver (closing browser)")
    driver.quit()

The output will be something like this:
Code:
2022-11-11 05:00:01,584 INFO STARTING application
2022-11-11 05:00:01,584 INFO Creating driver (opening browser window)
2022-11-11 05:00:08,255 INFO Loading login page
2022-11-11 05:00:10,264 INFO Entering login information
2022-11-11 05:00:10,986 INFO Submitting login form
2022-11-11 05:00:15,386 INFO Loading reset webpage
2022-11-11 05:00:17,242 INFO Clicking reset button
2022-11-11 05:00:17,777 INFO Confirming dialog box
2022-11-11 05:00:18,117 INFO Waiting for the reset action to be processed
2022-11-11 05:00:48,148 INFO Quitting driver (closing browser)

I hope this can be helpful to someone else.

Thanks.
 
Thanks for sharing, but your gateway or ISP connection have issues and this is only an over-engineered band-aid solution.
 
Hi,

Seems I'm not the only person having these kind of issues.

In my case, I have noticed that after some weeks of not restarting the modem, the internet connectivity is impacted.

Not sure if it's because the signal is electric through coaxial, and not through fiber optic.

Xfinity even recommends doing regular restart on the xFi gateway:

Regularly Restart Your Equipment​

Restarting your gateway, modem or router is good for the device's health and for your home WiFi performance. Doing this allows the device to update its software, if necessary, which can help optimize your connection and speed.

Perhaps doing a daily reboot is overkill, maybe once a week should be enough.

Regards.
 
If you have to reboot it regularly, there is an issue with getaway it self. Or an issue with cable, poor physical cable connection.

Ive been using my own Cable modems as far as I can remember and I rarely had to restart them. Last two second hand cable modems I bought on Facebook marketplace, Asus CM16 and Arris. They run for +10 months at a time with out any problems.

When I was having speed issues almost two years ago, Xfinity sent out a tech and he replaced a VCE Coaxial Cable Connector, because it had too much paint on it. Thanks to property management, painting over everything before they rent out an apartment.

I suggest you replace the F-Type coax connector behind the wall plate and the CVE Coax cable connector that is part of the wall plate.

Link for reference.
https://www.amazon.com/dp/B0B8MVX8GX/?tag=snbforums-20

Xfinity tech will replace them for free. So don't waist your time and money buying your own.

 

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top