ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Main Area and Open Discussion > Living Room

Need hardware (and software) to reset power when internet connection is lost

<< < (2/4) > >>

wraith808:
Another perspective with this device:
It depended on a server running under the control of the creator to set it up, (I don't even know if it's still running).
It was a Kickstarter project run by someone who apparently has a history of thinking up good ideas but then never fully follows through with them after an initial run. There are a ton of reports of people not receiving anything or that they didn't work properly.
-4wd (February 13, 2021, 04:28 PM)
--- End quote ---

Thanks for chiming in. I never had a problem with mine, and used a throwaway google account for the service, so never knew things went so badly. I stopped using it a while ago when I was able to get my own modem.

But yeah, I don't think it would be too hard or expensive to hack this together yourself- I just used that because I didn't want to reinvent the wheel and it worked for me.

4wd:
and used a throwaway google account for the service, -wraith808 (February 13, 2021, 09:40 PM)
--- End quote ---

Same here, there's a mention in the comments that someone was getting an error when trying to login, that was about 3 years ago.

Anyway, some Python I hacked together that might do the job on the RPi, (TestNet.py):

--- Code: Python ---#!/bin/python # python TestNet.py # Power to load goes through relay NC (normally closed) contacts so relay# doesn't have to be activated all the time # sudo apt-get install python-requests import datetimeimport requestsimport signalimport sysimport timeimport RPi.GPIO as GPIO def exit_handler(signum, frame):   # releases GPIO when you hit Ctrl-C to exit  GPIO.cleanup()  sys.exit(0) signal.signal(signal.SIGINT, exit_handler) # Handle Ctrl-C pinNum = 8                         # GPIO pin relay is activated onGPIO.setmode(GPIO.BCM)             # numbering scheme that corresponds to breakout board and pin layoutGPIO.setup(pinNum, GPIO.OUT)       # replace pinNum with whatever pin you used, this sets up that pin as an outputurl = "http://www.google.com"      # URL to test connectiontimeout = 5                        # connection timeout in secondsconnected = 0                      # connection counter, incremented on failurefailNum = 4                        # number of consecutive failures before rebootinterval = 180                     # interval between connection attempts in seconds while True:  now = datetime.datetime.now()    # get the current date/time  try:    request = requests.get(url, timeout = timeout)  # connection attempt    print(now.strftime("%Y%m%d-%H%M%S") + ': Connected to the Internet')    connected = 0                  # reset counter on successful connection  except (requests.ConnectionError, requests.Timeout) as exception:    connected += 1                 # increment counter on connection failure    print(now.strftime("%Y%m%d-%H%M%S") + ': No internet connection, failure: %s' % connected)   if connected >= failNum:         # too many failures    print (now.strftime("%Y%m%d-%H%M%S") + ': Rebooting modem')    GPIO.output(pinNum, GPIO.HIGH) # output high, turn on relay    time.sleep(30)                 # wait 30 seconds    GPIO.output(pinNum, GPIO.LOW)  # output low, turn off relay#    time.sleep(120)                # optional extra sleep period after a reboot, in case more time than normal interval required,  in seconds   time.sleep(interval)             # sleep until next connection attempt

Sample output (you can comment out the print statements if output isn't required or redirect to null/file), this is before I added a timestamp to the output lines:


--- Code: Text [email protected]:~ $ python ./TestNet.py Connected to the InternetConnected to the InternetNo internet connection, failure: 1No internet connection, failure: 2Connected to the InternetConnected to the InternetNo internet connection, failure: 1No internet connection, failure: 2No internet connection, failure: 3No internet connection, failure: 4Rebooting modemConnected to the InternetConnected to the Internet
NOTE: Not tested with a relay connected but the GPIO commands are pretty basic so it should work, (plus it didn't blow up), using the same basic circuit as in the site I mentioned above.

Deozaan:
I had this problem a while ago and looked into this solution:

http://whatimade.today/make-an-automatic-router-re-starter-for-3-with-an-esp8266-01-and-single-relay/
-wraith808 (February 13, 2021, 03:19 PM)
--- End quote ---


Otherwise I would think an appropriately rated relay connected to the RasPi GPIO to switch the power to the modem would be easy enough.
eg. https://www.electronicshub.org/control-a-relay-using-raspberry-pi/

Remember, you only need to switch the 12v DC, (usually), for the modem, not the 110v AC of the mains, so mains isolation is not a problem.
It should then be as simple as pinging Google every few minutes and triggering the GPIO on a run of 3 failures, (for example).-4wd (February 13, 2021, 04:28 PM)
--- End quote ---

Both of these look like perfectly reasonable solutions, and I think I could buy all the parts needed to make it for under $5, including shipping, on AliExpress. But I'll have to wait 1-2 months for them to arrive. Or even longer, since the order won't even be processed for another 1-2 weeks due to Lunar New Year celebrations halting virtually all business in China.

The cheapskate in me wants to do this method. But it's far enough out of my depth of knowledge that I'm not even sure I'm adding the right parts to my shopping cart. I'd hate to wait the 2 months for the parts to arrive only to realize that I got the wrong things or I can't get it to work.

I don't have any training or experience with wiring circuit boards to things. And I don't know much about switches and relays and circuits and... electronics or electricity in general, I guess.

In the end I set the computer up with a shutdown schedule, had it automatically boot on power on, and then used a timer switch to shut down the power to it and the modem for 15 mins every day at a time I wasn't likely to be using it.
It ran flawlessly this way for years.-4wd (February 13, 2021, 04:28 PM)
--- End quote ---

That won't work for me. It goes out sporadically. Sometimes it goes a few days without an outage. Other days I have multiple outages within an hour or two of the previous one. So only cycling the power once per day won't be robust enough for me.

Another alternative would be a ZigBee adapter for a RasPi along with a ZigBee controlled power switch, then you're not reliant on WiFi if it's provided by the modem/router.

[...]

Also, you didn't mention, if your modem takes alternative firmware then maybe there's a facility in that to test/reboot.
-4wd (February 13, 2021, 04:28 PM)
--- End quote ---

My modem and router are separate devices, so I can power-cycle the modem without losing local WiFi. I've been happily running custom DD-WRT firmware on my router for years, but I never thought of looking for custom firmware for my modem. I guess I always imagined it as a "dumb" or "black box" signal relay between my router and my ISP. It's an Arris SURFboard SB6190.


I didn't know what a ZigBee was so I looked it up and it appears to just be a smart plug. I actually bought a smart plug recently, but it was a Christmas gift for someone else. I got a really good deal on it (only $1!) but I thought I'd never want to use one, because I didn't want it snooping on me and phoning home without my knowledge/consent. Do you happen to know if smart plugs in general, or the ZigBee specifically, snoop and phone home about stuff? I guess there's not much data that could be gathered from a smart plug, assuming it doesn't have a (potentially hidden) microphone or camera. I think the only things it could know about are just the times/schedule when it is on or off, and perhaps the name of my SSID and nearby SSIDs. But even so, I don't like the idea of internet-connected devices which report on me to their overlords (says the guy with multiple Android devices and multiple Windows 10 PCs in his household...).

This looks like the middle ground as far as convenience and cost goes, considering I already have the RasPi. But it's still slightly on the spendy side when you account for not only the smart plug but also the USB adapter for the RasPi. Looks like it's going to be somewhere in the range of $35-50. To be honest, the ZigBee method seems kind of like the worst of both worlds. Kind of spendy compared to using a simple relay, but still enough DIY jerry rigging that I'm not confident about the process.

So that said, looks like this unit might actually do what you want. Seems a little pricey but depends on how bad you want it.-x16wda (February 13, 2021, 07:40 PM)
--- End quote ---

Yes, that does look like exactly the kind of thing I want. It is a bit pricey, but I suppose that's the convenience cost of having everything done for me and being able to get it right away.


After thinking about it for a while (while typing this up) I've decided to go with both of the extremes, which I guess averages out to the perfect middle ground. :D

I see I neglected one important aspect of the problem I'm facing, which is that losing my internet connection isn't just a problem for me when I'm away from home. The reason this is a problem anytime I'm not immediately available to spring into action is because I also keep my RasPi connected to at least one cryptocurrency peer-to-peer network in which I can be penalized or deemed less trustworthy if someone tries to connect to my device and it doesn't respond. It's not making me rich, but it's earning me a decent amount of money simply for keeping a device running/connected that I'm already leaving running/connected 24/7 anyway as my personal media server and whatnot.

So this internet outage issue is a problem even when I'm at home: any time I'm sleeping, or outside doing housework, or even when I'm inside doing something (such as taking a shower) that makes me unlikely to notice or unable to respond right away when there's an internet connectivity problem. The issue can strike at any time and the consequences are not just "oh darn I can't listen to my music right now, I guess I'll have to be bored." It can actually "cost" me money in the form of missing out on opportunities to earn cryptocurrency.

So I ordered the ezOutlet3 because it's a finished product I can get from Amazon (2-day shipping!) and then I can start enjoying relative peace of mind very soon. I don't like the fact that it appears to phone home to some 3rd party server which they claim is only to help relay the connection between their device and the smartphone app. And I don't like how expensive it is.

But I'm also planning to order the parts to make my own solution following the instructions linked to by 4wd or wraith808. That way I won't feel stressed if it takes 3 months to arrive. And I can figure out how to put all the pieces and wires together and program it to behave the way I want to at a leisurely pace, without time pressure. And if it ends up for one reason or another that I ordered the wrong parts or I can't get it to work, then I'm only out an additional $5 and I won't be filled with regret about having to buy the ezOutlet3 anyway after months of waiting for the other things. But if I do end up getting it to work the way I want to, then maybe I can sell the ezOutlet3 on eBay to help recoup some of the costs.

Ath:
I'm also planning to order the parts to make my own solution following the instructions linked to
-Deozaan (February 14, 2021, 02:10 AM)
--- End quote ---
In most countries there are shops that supply an assortment of AliExpress goods from local stock, their prices are somewhat higher than the Ali prices, of course, but they manage to deliver in days instead of months, on average. You just have to find the right shop in your country :tellme:

mouser:
On amazon: https://www.amazon.com/dp/B08GLTN49M/
and https://www.amazon.com/Connect-Monitors-Connectivity-Required-Necessary/dp/B07MCRQPCS

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version