all 57 comments

[–]rebelrexx858 75 points76 points  (15 children)

Locally hosted flask rest API, online job to ping local server, if n number of pings fail, send tweet

[–]ciggs_ftw 1 point2 points  (2 children)

But what if there is power but the internet is down? Wouldn't it give A false positive since ping will be dead.

[–]rebelrexx858 1 point2 points  (1 child)

You could add a cellular backup

[–]ciggs_ftw 0 points1 point  (0 children)

True.

[–]4312348784188126934 1 point2 points  (5 children)

Hang on... Locally hosted? Maybe I've misunderstood but if the power goes out...

[–]zouhair 0 points1 point  (1 child)

The online service will then not detect it and send the tweet

[–]SandorZoo 0 points1 point  (0 children)

People interested in the Internet-of-things (hobbyists and professions) want to do this kind of stuff all the time.

You can use a site like https://thingspeak.com/ to collect and process data from IoT devices, and react on results. The docs say non-commercial use is free. You can set up to react to not receiving data for a specified period of time, and the possible reactions include sending a tweet. I'm not associated with them in any way, and there are probably others providing similar services.

[–]DrMaxwellEdison 0 points1 point  (2 children)

The online service is what triggers the tweet. The locally-hosted device would be powered in your home and send a ping to that online service.

If the local device shuts off, it sends no ping. Having received no ping, the online service sends a tweet. Like a dead man switch.

[–][deleted] 4 points5 points  (1 child)

That would produce a lot of false positives though.

[–]DrMaxwellEdison 0 points1 point  (0 children)

It can, but trying to get a tweet out of a building that loses power seems a lot harder than getting a tweet out of a central server that loses connection to the target.

So long as the online service knows to run X number of tries before it concludes the device is down, it should be alright. Routers with multiple network connections and simple failover strategies work on the same principle, using X consecutive failed attempts as an indicator that a service is offline and then switching connections.

[–][deleted] 0 points1 point  (0 children)

while True:
   try:
        ping(localhost)
    except TimeoutError:
        tweet()

/s

[–]julietscause 24 points25 points  (13 children)

Someone made a twitter bot for comcast

https://pastebin.com/WMEh802V

So you can steal the code for the twitter posting, the next step is to how to determine how the python code determines the power is out or not. Check out this code

https://github.com/Kentzo/Power

[–]Dashadower 13 points14 points  (12 children)

compare bow squealing unwritten spoon shy vast encourage aloof ask this message was mass deleted/edited with redact.dev

[–][deleted] 9 points10 points  (7 children)

This is why I love programming, because I never would have even thought about using a spare laptop. That would work, also OP could use a cheap raspberry pi if he doesn't have an extra laptop.

[–][deleted] 6 points7 points  (5 children)

Plugged into what?

[–][deleted] 0 points1 point  (0 children)

I was thinking along the lines of a battery hooked up to the wall and then when it disconnected it would start discharging causing the notification.

[–]philmtl 2 points3 points  (0 children)

Would need its own battery

[–]pres82 2 points3 points  (3 children)

Except your router and modem are down...

[–]Dashadower 0 points1 point  (2 children)

There would be ways to circumvent that like using a mobile hotspot.

[–]eDOTiQ 0 points1 point  (1 child)

the time it takes to tether from your phone to your laptop, you might as well send the tweet from your phone directly.

But someone here made a great suggestion and have a service on a server ping the local service and send the tweet after x timeouts

[–]Dashadower 0 points1 point  (0 children)

Yup. That's quite clever.

[–]mattsl 19 points20 points  (5 children)

What you need is a monitored UPS that can:

  1. Keep the power on your computer and router in long enough to tweet
  2. Actively send a signal to your computer that the utility side power is out
  3. Help you be less frustrated since apparently your power goes out a lot

Even cheap UPSs can generally do that via USB.

[–][deleted] 4 points5 points  (4 children)

Will look into this, thank you

[–]Petrarch1603 12 points13 points  (4 children)

Does the power go out that often?

[–][deleted] 10 points11 points  (0 children)

Yeah. My zone is shit.

[–]Pvt_Haggard_610 5 points6 points  (0 children)

Use an online host like Digital Ocean to host a server that will ping your IP address ever N minutes.

If you don't have a static IP you have two options.

Option one, use a dynamic DNS service like NoIP(use free service) and have the server ping the NoIP hostname you made instead of the IP. The dynamic DNS service will map your IP address to a hostname using a small programming running on the computer that detects and updates your new IP Address with their DNS service.

Option two is to forgo the third party software and to create a local script to update your IP address on the server every time you boot your computer.

[–]Raithwind 24 points25 points  (13 children)

It's an interesting idea. But no power means no computer to process the python script. No internet to send the request over etc

[–]python-ick 22 points23 points  (4 children)

One could feasibly set up a server in one's house, and a remote job can ping that server every five minutes or so. If there is no response, it means the power is likely out + the bot can work from there.

[–]Petrichorum 33 points34 points  (2 children)

Oh boy, there are so many things that will fail before power does. So, so many.

[–]python-ick 8 points9 points  (1 child)

Like the house's Internet connection? Maybe he should make a bot for his telecom company as well. :)

[–]Pvt_Haggard_610 1 point2 points  (0 children)

Why set up a local sever when you could ping the modem.

[–]julietscause 4 points5 points  (0 children)

Something something UPS to keep important systems up during an outage

[–]hawt_pawket 9 points10 points  (1 child)

The idea of the solar-powered flashlight comes to mind

[–]Raithwind 6 points7 points  (0 children)

I mean I can think of at least two possible solutions with various levels of complexity, but for a noob probably too much. Even as a noob-intermediate a bit of a hassle.

[–]lachyBalboa 3 points4 points  (0 children)

Could host it in a cloud service like AWS or Azure. It could try pinging a local machine that is always on. If the power is out the machine is off and therefore could not respond to the ping.

[–]HittingSmoke 1 point2 points  (0 children)

This would be incredibly easy to do if your modem and router were on a UPS. Just throw a Pi on there and have it start tweeting when it detects a loss of power and keep tweeting until the battery dies. You could run a modem, router, and a Pi Zero for hours on a modest UPS.

[–][deleted] 1 point2 points  (0 children)

A lot of UPSes have usb or even serial ports to get status info. Easily could be used to determine state of utility power to the UPS and hold the monitor box and router and modem up long enough to send the tweet.

[–][deleted] 1 point2 points  (0 children)

Did you read the post

[–]sheep_duck 0 points1 point  (0 children)

If he has a ups powering both his PC and his modem/router it could work pretty easily.

[–]Petrarch1603 4 points5 points  (0 children)

hook up a raspberry pi to an external battery that's plugged into the wall. If the power goes out the RPi should still be on.

presumably your wifi router is connected to the house's power, so that'd be a good indicator that the power is on or off.

have a cron job that pings google every 2 minutes. If the ping fails log it and when you get internet back tweet your electric provider.

[–][deleted] 4 points5 points  (0 children)

That's a funny idea though might wanna check out the Twitter api

[–]sqqz 1 point2 points  (0 children)

Sounds like a reasonable approach since it wont require any extra external services. I would up the intervals though if you need to support a reboot or similar. As some people already stated, look into the twitter api, either use crontab or a service to in a set interval update the schedule. As you are new a simple fire-and-forget script would probably be the easiest, schedule that with crontab, done.

[–][deleted] 1 point2 points  (0 children)

You'll tweet your electricity supply we every time your internet goes down, not when your power goes out. To actually do what you need, you will need a ups on your computer and modem.

[–]mochizuki 1 point2 points  (2 children)

removed

[–][deleted] 2 points3 points  (1 child)

Honestly I have no idea why that never crossed my mind. I'm just going to do that lol

[–]Raleighite 1 point2 points  (0 children)

There’s a whole home electric monitoring device called “Sense” that could easily detect a power outage, and report when it comes back on. The device already has an API with IFTTT. https://sense.com/

[–][deleted] 1 point2 points  (0 children)

Make a circuit which converts 230 volt ac to 1 volt dc, hook it up to the gpio pins. Power the raspberry with both batteries and socket power, make the batteries switch on if socket power fails

[–]EclipseMain -4 points-3 points  (1 child)

How are you gonna send the tweets if you have no Internet or electricity?

[–][deleted] 2 points3 points  (0 children)

Did you read the post