Things used in this project

Hardware components:
102110017%206
MediaTek Labs LinkIt Smart 7688 Duo
×1
Adafruit industries ada592 image 75px
USB-A to Micro-USB Cable
×1
SD Card (8GB)
×1
Software apps and online services:
PuTTy

Code

Source-codePython
Here's project's source code. Pay attention to the comments and have fun!
import httplib
import urllib
import os
import time

#global variables
TwitterAccountOfYourInternetProvider = "@NULLNULLNULL" #put here your Internet provider Twitter's account
NameOfYourCity = "Sao Bernardo do Campo - SP"
APIKeyThingSpeak = 'KKKKKKKKKKKKKKKK'   #replace KKKKKKKKKKKKKKKK by your api_key of ThingTweet
WriteAPIKey = 'WWWWWWWWWWWWWWWW'   #replace WWWWWWWWWWWWWWWW by your channel's write api key

#Downtime monitor variables
InitTimestamp_DownTime = 0
IsItOffline = 0
TotalDownTime = 0
DownTimeReportFile = "DownTimeReport.txt"
TotalDowntimesDetected = 0
NumberOfAttempts = 1

def VerifyAndRegisterDownTime(res):
	global IsItOffline
	global InitTimestamp_DownTime
	global TotalDownTime
	global DownTimeReportFile
	global TotalDowntimesDetected
	global NumberOfAttempts

	if (res == 0):
		print " "
		print "Internet is on!"
	else:
		print " "
		print "Internet is off..."

        #Check #1: Internet was on and now it's off
	if ((res!=0) and (IsItOffline == 0)):
		InitTimestamp_DownTime = time.time()
		IsItOffline = 1
	        return

        #Check #1: Internet was off and now it's on
	if ((res == 0) and (IsItOffline == 1)):
		TotalDownTime = time.time() - InitTimestamp_DownTime
		StringDT =  "DownTime detected! "+str(TotalDownTime)+" seconds offline\n"
		print StringDT
		TxtFile = open(DownTimeReportFile,"a")
		TxtFile.write(StringDT)
		TxtFile.close()
        TotalDowntimesDetected = TotalDowntimesDetected + 1
		IsItOffline = 0
	    SendTweet(TotalDownTime)
		SendDownTimeDataToThingSpeak(TotalDownTime)
		return

def SendTweet(DuracaoDT):
	global TwitterAccountOfYourInternetProvider
	global NameOfYourCity
	global APIKeyThingSpeak
        
        
    StringtoTweet = TwitterAccountOfYourInternetProvider+", a "+str(DuracaoDT)+" seconds downtime was detected. I'm on "+NameOfYourCity+". #DownTimeDetected"
	params = urllib.urlencode({'api_key': APIKeyThingSpeak, 'status': StringtoTweet})  
	conn = httplib.HTTPConnection("api.thingspeak.com:80")
	conn.request("POST","/apps/thingtweet/1/statuses/update",params)
	resp = conn.getresponse()
	conn.close()

def SendTweetSystemInit():
	global APIKeyThingSpeak

    StringtoTweet = "Downtime Monitor Started!"
	params = urllib.urlencode({'api_key': APIKeyThingSpeak, 'status': StringtoTweet})  
	conn = httplib.HTTPConnection("api.thingspeak.com:80")
	conn.request("POST","/apps/thingtweet/1/statuses/update",params)
	resp = conn.getresponse()
	conn.close()
	
def SendDownTimeDataToThingSpeak(DuracaoDT):	  	
	global WriteAPIKey

	params = urllib.urlencode({'field1': str(DuracaoDT),'key':WriteAPIKey})
   	headers = {"Content-typZZe": "application/x-www-form-urlencoded","Accept": "text/plain"}
	conn = httplib.HTTPConnection("api.thingspeak.com:80")
   	conn.request("POST", "/update", params, headers)
	resp = conn.getresponse()


#---------------
#  MAIN PROGRAM
#---------------

SendTweetSystemInit()

while True:
	try:
		os.system("clear")
       	print "---------------------------"
	    print "     DownTime Monitor      "
      	print "---------------------------"
	    print " "
		print "Attempt #"+str(NumberOfAttempts)+" - "+str(TotalDowntimesDetected)+" detected downtime(s)"
	    print " "

		PingResult = os.system("ping -c 1 8.8.8.8")
	    VerifyAndRegisterDownTime(PingResult)
		time.sleep(20) 
      	NumberOfAttempts = NumberOfAttempts + 1
	except (KeyboardInterrupt):
		print "This application is closed. Good bye."
		exit(1)

Credits

Pedrobertoleti
Pedro Henrique Fonseca Bertoleti

Hi there! My name is Pedro Bertoleti. I am aboslutely crazy about: - Electronics - Embedded software design - Technology

Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

Linkit building prototype showcase lights
Easy
  • 42
  • 4

Full instructions

This is a project that shows you how to make cool lights to show off a building prototype.

Getting Started with Linkit Smart 7688 DUO
Easy
  • 60
  • 2

Protip

In this video, we will see the specs of the module, configure using the web interface, and access the terminal using SSH.

Unboxing the LinkIt ONE
Easy
  • 541
  • 9

Protip

So you got yourself a LinkIt ONE, and you’re trying to figure it out. Everything on paper looks pretty cool, but it’s a little intimidating.

Dorothy – a project for those away from home
Easy
  • 1,126
  • 24

Full instructions

Show colour-coded distances from a location marker with a portable microcontroller system

NubChat - chat app for devices (and humans) with PubNub
Easy
  • 994
  • 20

Full instructions

NubChat is an app that let communicate with human and devices using pubnub APIs.

Animatronic Horse Mask
Easy
  • 276
  • 6

Full instructions

This project will take your awesome Halloween costume to the next level!! Have a horse mask that can open/close its mouth!!

Add projectSign up / Login