Example #1
0
def send_mail():
    sub = 'Burglar Alert at: ' + now.strftime("%Y-%m-%d %H:%M") + '!!!!'
    mailer = Email(MAILGUN_API_KEY, SANDBOX_URL, SENDER_EMAIL,
                   RECIPIENT_EMAIL)  # Create object to send Email
    mailer.send_email(
        sub,
        "Dear User, \n\nWe have detected intruder movement in your vault!! \n\nTo stop the buzzing alarm at your premises, <a href='https://cloud.boltiot.com/remote/5c13db10-a9f9-4d67-9fff-f03a0b13288f/digitalWrite?pin=1&state=LOW&deviceName=BOLT3622826'> click here </a> . Please take required action immediately. \n\nSincerely, \n\nBolt Team"
    )
Example #2
0
def send_mail(subject, body, ifprint = False):
    mailer = Email(cred.MAILGUN_API_KEY, cred.SANDBOX_URL, cred.SENDER_EMAIL, cred.RECIPIENT_EMAIL)
    response = mailer.send_email(subject, body)
    response_text = json.loads(response.text)

    if(ifprint):
        print(response_text)
    if response_text['message'] == 'Queued. Thank you.':
        return True
    else:
        return False
def mail_func(email_id):
    mailer = Email(email_conf.MAILGUN_API_KEY, \
    email_conf.SANDBOX_URL, email_conf.SENDER_EMAIL, email_id)
    try:
        print("Making request to Mailgun to send an email")
        response = mailer.send_email("You got a Reward",\
        "Thank you for your valuable contribution in recycling the plastic and making incredible india clean and pollution free.")
        response_text = json.loads(response.text)
        print("Response received from Mailgun is: " + \
        str(response_text['message']))
    except Exception as e:
        print("Error occured: Below are the details")
        print(e)
Example #4
0
def send_mail(subject, body, ifprint=False):
    '''
        This function sends mail to the RECIPIENT_EMAIL as mentioned in cred.py
        subjects and body are self explanatory
        ifprint is default False. Setting it True, makes the fuction print all response texts
    '''
    mailer = Email(cred.MAILGUN_API_KEY, cred.SANDBOX_URL, cred.SENDER_EMAIL,
                   cred.RECIPIENT_EMAIL)

    response = mailer.send_email(subject, body)
    response_text = json.loads(response.text)

    if (ifprint):
        print(response_text)
    if response_text['message'] == 'Queued. Thank you.':
        return True
    else:
        return False
Example #5
0
import edtls, json, time
from boltiot import Email, Bolt

mybolt = Bolt(edtls.API_KEY, edtls.DEVICE_ID)
mailer = Email(edtls.MAILGUN_API_KEY, edtls.SANDBOX_URL, edtls.SENDER_EMAIL,
               edtls.RECIPIENT_EMAIL)

print("Welcome to A_C_Stark_SSLS Traffic Density Analyser :)")

while True:
    response = mybolt.serialRead('10')
    data = json.loads(response)
    print("Current Count: " + str(data['value']))
    try:
        sensor_value = 0
        sensor_value = int(data['value'])
        if sensor_value > 0:
            print("Making request to Mailgun to send an email...")
            response = mailer.send_email(
                "Stark_SSLS Daily TDR",
                "The Traffic Count for yesterday dusk till today dawn was: " +
                str(sensor_value))
            response_text = json.loads(response.text)
            print("Response received from Mailgun is: " +
                  str(response_text['message']))
    except Exception as e:
        print("Error occured. Details below.")
        print(e)
    print("Reading data......")
    time.sleep(10)
Example #6
0
    pb_response = mybolt.digitalRead('1')

    ldr_data = json.loads(ldr_response)
    pb_data = json.loads(pb_response)
    print(ldr_data['value'])
    ldr_value = int(ldr_data['value'])
    print(pb_data['value'])
    pb_value = int(pb_data['value'])

    state = dtree.MachineLearning_model(ldr_value)
    if previous_state != present_state:
        try:
            if pb_value == 1:
                print("Door is Closed")
                led_state = mybolt.analogWrite('0', '0')
                response = mailer.send_email(
                    "Alert", "The Current door state is: CLOSE")

            if present_state == 0 and pb_value == 0:
                print("Door is half open")
                led_state = mybolt.analogWrite('0', '75')

            if present_state == 1 and pb_value == 0:
                print("Door is open")
                led_state = mybolt.analogWrite('0', '255')
                response = mailer.send_email(
                    "Alert", "The Current door state is: OPEN")

            previous_state = present_state

        except Exception as e:
            print("Error", e)
Example #7
0
    except Exception as e:
        print("There was an error while parsing the response: ", e)
        continue

    bound = compute_bounds(history_data, conf.FRAME_SIZE, conf.MUL_FACTOR)
    if not bound:
        required_data_count = conf.FRAME_SIZE - len(history_data)
        print("Not enough data to compute Z-score. We Need ",
              required_data_count, " more data points")
        history_data.append(int(data['value']))
        time.sleep(9)
        continue

    try:
        if sensor_value > maximum_limit or sensor_value < minimum_limit:
            response = mailer.send_email(
                "Alert", "The Current temperature is beyond the threshold ")
            message = "Alert " +  \
                      ". Current temperature of Fridge  Room is " + str(sensor_value) + "Statue:=IRREVALANT"
            telegram_status = send_telegram_message(message)
            print("This is the Telegram  Response", telegram_status)
        if sensor_value > bound[0]:
            print(
                "The temperature increased Within Calculated Threshold . Triggering Alerts on 2 Channel/n1.Email/n2.Telegram"
            )
            response = mailer.send_email(
                "Alert",
                "The Current temperature is beyond the threshold ch1 SOMEONE OPENED Dppr "
            )
            message = "Alert The temperature increased Within Calculated Threshold ch2 "  + \
                      ".Someone opened Door Current temperature of Fridge  Room is " + str(sensor_value) + "Statue:=Tel_Sucess"
            telegram_status = send_telegram_message(message)
import json, time, email_conf
from boltiot import Bolt, Email
min_limit = 1
max_limit = 3
mybolt = Bolt(email_conf.API_KEY, email_conf.DEVICE_ID)
e_mail = Email(email_conf.MAILGUN_API_KEY, email_conf.SANDBOX_URL,
               email_conf.SENDER_EMAIL, email_conf.RECIPIENT_EMAIL)
while True:
    response = mybolt.analogRead('A0')
    data = json.loads(response)
    try:
        sensor_value = int(data['value'])
        print(sensor_value)
        if sensor_value > max_limit or sensor_value < min_limit:
            response = e_mail.send_email(
                "Attention!",
                "Your light sensor value is " + str(sensor_value))
    except Exception as e:
        print("Error!", e)
    time.sleep(10)
Example #9
0
import confi
from boltiot import Sms,Email,Bolt
import json,time

minimum_limit=300
maximum_limit=600

mybolt=Bolt(confi.API_KEY,confI.DEVICE_ID)

sms=Sms(confi.SID,confi.AUTH_TOKEN,confi.TO_NUMBER,confi.FROM_NUMBER)
mailer=Email(confi.MAILGUN_API_KEY,confi.SANDBOX_URL,confi.SENDER_EMAIL,confi.RECIPIENT_EMAIL)

while True:
    print ("Reading sensor value")
    response = mybolt.analogRead('A0')
    data = json.loads(response)
    print("Sensor value is:"+str(data['value']))
    try:
        if sensor_value > maximum_limit or sensor_value < minimum_limit:
            print("Making request to mailgun and twilio to send an email and a message")
            response1 = sms.send_sms("the current temperature sensor value is"+str(sensor_value))
            response2 = mailer.send_email("Alert","the current sensor value is "+str(sensor_value))
            print("response recived from twilio is:"+str(response1))
            response_text = json.loads(response2.text)
            print("Status of SMS at Twilio is:"+str(response1.status))
            print("response recieved from Mailgun is:"+str(response-text[message]))
        except Exception as e:
            print("Error occured:Below are the reasons")
            print(e)
        time.sleep(10)
Example #10
0
              " more data points")
        history_data.append(int(data['value']))
        time.sleep(10)
        continue

    try:
        if sensor_value > bound[0]:
            print(
                "The temperature level increased suddenly. Sending an SMS and Email Alert."
            )
            response = sms.send_sms("The refrigerator has been opened")
            print("This is the response from Twilio ", response)

            print("Making request to Mailgun to send an email")
            response = mailer.send_email(
                "Alert", "The Current temperature sensor value is " +
                str(sensor_value) + " and temperature is " + str(temperature) +
                " degree Celsius.")
            response_text = json.loads(response.text)
            print("Response received from Mailgun is: " +
                  str(response_text['message']))
        elif sensor_value < bound[1]:
            print(
                "The temperature level decreased suddenly. Sending an SMS and Email Alert."
            )
            response = sms.send_sms("The refrigerator has been closed")
            print("This is the response from Twilio ", response)

            print("Making request to Mailgun to send an email")
            response = mailer.send_email(
                "Alert", "The Current temperature sensor value is " +
                str(sensor_value) + " and temperature is " + str(temperature) +
Example #11
0
 try:
     sensor_value = int(data['value'])
 except Exception as e:
     print("There was an error while parsing the response:", e)
     continue
 value = sensor_value / 10.24
 print("THE CURRENT TEMPERATURE:" + str(value))
 try:
     if sensor_value > max or sensor_value < min:
         mybolt.digitalWrite('0', 'HIGH')
         print("TEMPERATURE CROSSED THE LIMIT")
         response1 = sms.send_sms(
             "TEMPERATURE CROSSED THE LIMIT.THE CURRENT TEMPERATURE IS " +
             str(value))
         response2 = mailer.send_email(
             "ALERT!",
             "TEMPERATURE CROSSED THE LIMIT.THE CURRENT TEMPERATURE IS " +
             str(value))
         print(response2)
         print("Status of SMS at Twilio is:" + str(response1.status))
         response_text = json.loads(response2.text)
         print("Response received from Mailgun is:" +
               str(response_text['message']))
         time.sleep(10)
         mybolt.digitalWrite('0', 'LOW')
 except Exception as e:
     print("Error occured:Below are the details")
     print(e)
     time.sleep(10)
     continue
 bound = compute(history_data, conf.FRAME_SIZE, conf.MUL_FACTOR)
 print(
Example #12
0
import conf, time, json
from boltiot import Bolt, Email

mybolt = Bolt(conf.boltApiKey, conf.deviceId)
email = Email(conf.mailgunApiKey, conf.sandboxUrl, conf.sender, conf.receiver)

min = 9.2
max = 10

while True:
    response = mybolt.analogRead('A0')
    data = json.loads(response)
    sv = int(data["value"])
    temp = (100 * sv) / 1024
    print("The temperature is ", temp)
    if temp < min:
        print("The temperature is lower than ", min)
        print("Sending Email request")
        response = email.send_email("Alert", "The temperature is " + str(temp))
        print("Mailgun response: ", response.text)
    elif temp > max:
        print("The temperature is greater than ", max)
        print("Sending Email request")
        response = email.send_email("Alert", "The temperature is " + str(temp))
        print("Mailgun response: ", response.text)
    time.sleep(10)
Example #13
0
    low = history[frame-1] - z
    return [high,low]

while True:
    response = mybolt.analogRead('A0')
    data = json.loads(response)
    sv = int(data["value"])
    temp = (100*sv)/1024
    print("The temperature is ",temp)

    bounds = computeBounds(history,frame,factor)
    if not bounds:
        rdc = frame - len(history)
        print("Not enough data to compute Z-score. Need",rdc,"more data points.")
        history.append(temp)
        time.sleep(10)
        continue
        
    if temp < bounds[1]:
        print("Someone has opened the Fridge door")
        print("Sending Email request")
        response = email.send_email("Someone has opened the Fridge door","The temperature is "+str(temp))
        print("Mailgun response: ",response.text)

    elif temp > bounds[0]:
        print("Someone has opened the Fridge door")
        print("Sending Email request")
        response = email.send_email("Someone has opened the Fridge door","The temperature is "+str(temp))
        print("Mailgun response: ",response.text)

    time.sleep(10)
        required_data_count = conf.FRAME_SIZE - len(history_data)
        print("I will collect ", required_data_count,
              " more data point(s) before I begin.")
        history_data.append(int(data['value']))
        time.sleep(5)
        continue

    try:
        if sensor_value > bound[0]:
            sensor_value1 = int((sensor_value / 10.24) * 9 / 5 + 32)
            print("The temp  has INCREASED. Sending SMS & email.")
            response = sms.send_sms(
                "Temp has increased. The current temperature is " +
                str(sensor_value1) + " degrees F.")
            response1 = mailer.send_email(
                "Alert", "Temp has increased. The current temperature is " +
                str(sensor_value1) + " degrees F.")
            print("This is the response for SMS ", response)
            print("This is the response for EMAIL ", response1)
        history_data.append(sensor_value)
    except Exception as e:
        print("Error", e)
    time.sleep(50)

    try:
        if sensor_value < bound[1]:
            sensor_value1 = int((sensor_value / 10.24) * 9 / 5 + 32)
            print("The temp  has decreased. Sending SMS & email.")
            response = sms.send_sms(
                "Temp has decreased. The current temperature is " +
                str(sensor_value1) + " degrees F.")
Example #15
0
    if data['success'] != 1:
      print("There was ana error while retreiving the data.")
      print("This is the error: "+data['value'])
      time.sleep(10)
       continue
    print("This is the value "+data['value'])   
    sensor_value=0
    try:
      sensor_value = int(data['value'])
    except e:
      print("There was an error while parsing the response: ", e)
      continue
    bound = compute_bounds(history_data, conf.FRAME_SIZE, conf.MUL_FACTOR)
    if not bound:
      required_data_count = conf.FRAME_SIZE - len(history_data)
      print("Not enough data to compute Z-score. Need ", required_data_count, " more data points")
      history_data.append(int(data['value']))
      time.sleep(10)
      continue
    try:
      if sensor_value>bound[0]:
        response = mailer.send_email("Alert","The temperature increased suddenl, someone open the fridge door. Sending an E-mail.")
        response_text=json.loads(response.text)
      elif sensor_value<bound[1]:
        response = mailer.send_email("Alert", "The temperature decrease suddenly. Sending an E-mail.")
        response_text=json.loads(response.text)
      except Exception as e:
        print("Error occured: Bellow are the details")
        print(e)
        time.sleep(10)
        required_data_count = conf.FRAME_SIZE - len(history_data)
        print("Not enough data to compute Z-score. Need ", required_data_count,
              " more data points")
        history_data.append(int(data['value']))
        time.sleep(10)
        continue

    try:
        if sensor_value > bound[0]:
            print(
                "Anomaly Detected. Light Intensity is showing sudden increment. Sending an SMS & Email."
            )
            response1 = sms.send_sms(
                "Light Intensity is showing sudden increment.")
            response2 = mailer.send_email(
                "Anomaly Alert",
                "Light Intensity is showing sudden increment.")
            response2_text = json.loads(response2.text)
            print("This is the response of SMS ", response1)
            print("Response received from Mailgun is: " +
                  str(response2_text['message']))

        elif sensor_value < bound[1]:
            print(
                "Anomaly Detected. Light Intensity suddenly decreased. Sending an SMS & Email."
            )
            response1 = sms.send_sms("Light Intensity suddenly decreased")
            response2 = mailer.send_email(
                "Anomaly Alert", "Light Intensity suddenly decreased")
            response2_text = json.loads(response2.text)
            print("This is the response of SMS ", response1)
Example #17
0
from boltiot import Bolt, Email

#Setting up device
device = Bolt(conf.api_key, conf.device_id)

minimum = 71.68
maximum = 153.6

mailer = Email(conf.mailgun_key, conf.sandbox_url, conf.sender_email,
               conf.receiver_email)

while 1:
    print("Reading sensor value")
    response = device.analogRead('A0')
    data = json.loads(response)
    print("Sensor value is: " + str(data['value']))
    try:
        sensor_value = int(data['value'])
        temperature = (100 * sensor_value) / 1024
    except Exception as e:
        print("Error occured: details are")
        print(e)

    if sensor_value > maximum or sensor_value < minimum:
        print("Making request to Mailgun to send an email")
        response = mailer.send_email(
            "Alert", "The Current temperature value is out of desired range" +
            str(temperature))
        print("Response received from Mailgun is:" + response.text)
    time.sleep(10)
Example #18
0
   sensor_value1 = int(data['value'])
   sensor_value1 = sensor_value1/10.24
   print ("The current temperature of your refrigerator is "+ str(sensor_value1)+" degree celsius. And the sensor Value is "+data['value'])
   sensor_value=0
   try:
       sensor_value = int(data['value'])
   except e:
       print("There was an error while parsing the response: ",e)
       continue
   bound = compute_bounds(history_data,conf.FRAME_SIZE,conf.MUL_FACTOR)
   if not bound:
       required_data_count=conf.FRAME_SIZE-len(history_data)
       print("Not enough data to compute Z-score. Need ",required_data_count," more data points")
       history_data.append(int(data['value']))
       time.sleep(5)
       continue
   try:
       if sensor_value > bound[0] :
           sensor_value1 = sensor_value/10.24
           print ("The temperature level has INCREASED suddenly.Sending SMS")
           response = sms.send_sms("Someone Opened the fridge door. The current temperature is " + str(sensor_value1)+ " degree celsius")
           response1 = mailer.send_email("ALERT", "The temperature of your refrigarator has been INCREASED suddenly because someone opened the fridge door. The current temperature is " + str(sensor_value1)+" degree celsius")
           response2 = sms_whatsapp.send_sms("The temperature of your Refrigerator has been INCREASED suddenly. The current temperature sensor value is " + str(sensor_value1)+ " degree celsius")
           print("This is the response for SMS ",response)
           print("This is the response for EMAIL ",response1)
           print("This is the response for WHATSAPP ",response2)
       history_data.append(sensor_value);
   except Exception as e:
       print ("Error",e)
   time.sleep(5)
    if not bound:
        required_data_count = conf.FRAME_SIZE - len(history_data)
        print("Not enough data to compute Z-score. Need ", required_data_count,
              " more data points")
        history_data.append(int(data['value']))
        time.sleep(5)
        continue

    try:
        if sensor_value > bound[0]:
            sensor_value1 = sensor_value / 10.24
            print(
                "The Temparature level has been INCREASED suddenly.Sending SMS"
            )
            response = sms.send_sms(
                "Someone Opened the fridge door. The Current temperature is " +
                str(sensor_value1) + " degree celsious")
            response1 = mailer.send_email(
                "RED Alert",
                "Someone opened the fridge door. Because The Temparature of your Refrigarator has been INCREASED suddenly. The Current temperature is "
                + str(sensor_value1) + " degree celsious")
            response2 = sms_whatsapp.send_sms(
                "Someone opened the fridge door. Because The Temparature of your Refrigarator has been INCREASED suddenly. The Current temperature sensor value is "
                + str(sensor_value1) + " degree celsious")
            print("This is the response for SMS ", response)
            print("This is the response for EMAIL ", response1)
            print("This is the response for WHATSAPP ", response2)
        history_data.append(sensor_value)
    except Exception as e:
        print("Error", e)
Example #20
0
      print("Not enough data to compute Z-score. Need ",required_data_count," more   data points") 
      history_data.append(int(data['value'])) 
      time.sleep(10) 
     try: 

#convert the temperature to display in degree census 
     temp = sensor_value/10.24 

    # condition for when the temperature crosses the maximum_limit 
     if temp > maximum_limit: 

           print ("The Temperature value increased suddenly. Sending an sms.") 
           # display the temeprature value in degree celsus 
           print ("The Current temperature is: "+str(temp)+" °C") 
           response = sms.send_sms("Alert ! Someone has opened the fridge door") 
           print("This is the response ",response) 

   # condition for the temperature value is between the critical_limit and the maximum_limit 
   elif temp > critical_limit or temp < maximum_limit: 
         print("Urgent! Temperature condition can destroy the tablets. Sending an email.")     
         #display the temperature value in degree Celsius 
         print (" The Current temperature is:" +str(temp)+ "°C") 
         response = mailer.send_email("Alert !","The level temperature can destroy the tablets.") 
        print("This is the response",response) 
    history_data.append(sensor_value) 

# in case of any error 
except Exception as e: 
              print ("Error",e) 
time.sleep(10)
    except Exception as e:
        print("There was an error while parsing the response: ", e)
        continue

    bound = compute_bounds(history_data, email_conf.FRAME_SIZE,
                           email_conf.MUL_FACTOR)
    if not bound:
        required_data_count = email_conf.FRAME_SIZE - len(history_data)
        print("Not enough data to compute Z-score. Need ", required_data_count,
              " more data points")
        history_data.append(int(data['value']))
        time.sleep(10)
        continue

    try:
        if sensor_value > maximum_limit or sensor_value < minimum_limit:
            response = mailer.send_email(
                "Alert", "The Current temperature is beyond the threshold ")
        if sensor_value > bound[0]:
            print("The temperature increased suddenly. Sending Sms.")
            response = sms.send_sms("Someone opened the chamber")
            print("This is the response ", (response))
        elif sensor_value < bound[1]:
            print("The temperature decreased suddenly. Sending an email.")
            response = mailer.send_email("Someone opened the chamber")
            print("This is the response ", response)
        history_data.append(sensor_value)
    except Exception as e:
        print("Error", e)
    time.sleep(10)
Example #22
0
    return [High_bound,Low_bound]

mybolt = Bolt(email_conf.API_KEY, email_conf.DEVICE_ID)
mailer = Email(email_conf.MAILGUN_API_KEY, email_conf.SANDBOX_URL, email_conf.SENDER_EMAIL, email_conf.RECIPIENT_EMAIL)
history_data=[]

while True:
    try:
        response = mybolt.analogRead('A0')
        data = json.loads(response)
        print ("This is the value "+data['value'])
        sensor_value = int(data['value'])
        bound = compute_bounds(history_data,email_conf.FRAME_SIZE,email_conf.MUL_FACTOR)
        history_data.append(int(data['value'])) 
        
        
        if not bound:
            print("Not enough data to compute Z-score")
            
        elif sensor_value > bound[0] :
            print ("The Temperature level increased suddenly. Sending an Email.")
            response = mailer.send_email("Z_Alert_High", "The Current temperature sensor value is " +str(sensor_value))
            print("This is the response ",response)
            
        elif sensor_value < bound[1]:
            print ("The Temperature level decreased suddenly. Sending an Email.")
            response = mailer.send_email("Z_Alert_Low", "The Current temperature sensor value is " +str(sensor_value))
            print("This is the response ",response)
    except Exception as e:
        print ("Error",e)
    time.sleep(10)
        print(e)


while True:
    price = get_bitcoin_price()
    print("Bitcoin price in USD and INR is as follows :\n1. USD : " +
          str(price['USD']) + "\n2. INR : " + str(price['INR']) + "\n")
    try:
        if price['INR'] > maximum_limit or price['INR'] < minimum_limit:

            print("Making request to Twilio to send a SMS")
            response = sms.send_sms(
                "Bitcoin price has crossed your set limits.\nCurrent bitcoin price in USD is "
                + str(price['USD']) + " and in INR is " + str(price['INR']))
            print("Response received from Twilio is: " + str(response))
            print("Status of SMS at Twilio is :" + str(response.status))

            print("Making request to Mailgun to send an email")
            response = mailer.send_email(
                "Bitcoin_Price_Alert",
                "Bitcoin price has crossed your set limits.\nCurrent bitcoin price in USD is "
                + str(price['USD']) + " and in INR is " + str(price['INR']))
            response_text = json.loads(response.text)
            print("Response received from Mailgun is: " +
                  str(response_text['message']))

    except Exception as e:
        print("Error occured: Below are the details")
        print(e)
    time.sleep(10)  #set the time you want to delay I have set it to 10sec
mailer = Email(email_config.MAILGUN_API_KEY, email_config.SANDBOX_URL,
               email_config.SENDER_EMAIL, email_config.RECIPIENT_EMAIL)
history_data = []

while True:
    response = mybolt.analogRead('A0')
    data = json.loads(response)
    print(data['value'])

    try:
        sensor_value = int(data['value'])
        print("temperature: ", ((sensor_value * 100) / 1024))

        if sensor_value > max_limit or sensor_value < min_limit:
            response = mailer.send_email(
                "Temperature Alert",
                "The Current temperature is " + str(sensor_value * 100 / 1024))
            print("mail sent\n")

    except Exception as e:
        print("Error 1", e)
        continue

    bound = compute_bounds(history_data, ad_config.FRAME_SIZE,
                           ad_config.MUL_FACTOR)

    if not bound:

        required_data_count = conf.FRAME_SIZE - len(history_data)
        print("Need ", required_data_count,
              " more data points to calculate Z-score")
Example #25
0
limit = 250

mybolt = Bolt(email_conf.API_KEY, email_conf.DEVICE_ID)
mailer = Email(email_conf.MAILGUN_API_KEY, email_conf.SANDBOX_URL,
               email_conf.SENDER_EMAIL, email_conf.RECIPIENT_EMAIL)

while True:
    print("Reading sensor value")
    response = mybolt.analogRead('A0')
    data = json.loads(response)
    print("Sensor value is: " + str(data['value']))
    print("Getting status of LED")
    response1 = mybolt.digitalRead('0')
    data1 = json.loads(response1)
    print("Status of LED:" + str(data['value']))
    try:
        sensor_value = int(data['value'])
        status1 = int(data1['value'])
        if status1 == 0 and sensor_value < limit:
            print("Turning light on, since surrounding light reduced!")
            response = mailer.send_email("Light is turned on",
                                         "Light sensor detected low light")
            response_text = json.loads(response.text)
            response = mybolt.digitalWrite('0', 'HIGH')
            print("Now LED is ON")
            print("Response from mailgun: " + str(response_text['message']))
    except Exception as e:
        print("Error occured: Below are the details ")
        print(e)
    time.sleep(10)
    print("The current Temperature is:", current_price)
    

    if current_price == -999:
        print("Request was unsuccessfull. Skipping.")
        time.sleep(10)
        continue
    

    if current_price <= conf.threshold:
        print("Alert! Current Bitcoin value has decreased ")
        print("Sending Telegram Alert.....")
        message = "Alert! Current Bitcoin value has decreased " + str(conf.threshold) + \
                  ". The current Bitcoin value is " + str(current_price)
        telegram_status = send_telegram_message(message)
        print("This is the Telegram status:", telegram_status)
        
        print(" Sending SMS Alert....")
		response_sms = sms.send_sms(" Alert! Current Bitcoin value has decreased ")
		print("Response From Twilio" +str(response_sms))
		print("SMS Status : " +str(response_sms.status))
		
		print("Sending Email Alert....")
		response_email = mailer.send_email( " Alert", "Current Bitcoin value has decreased ")
		email_response_text = json.loads(response_email.text)
		print("Response received from Mailgun is: " + str(email_response_text['message']))


    time.sleep(30) 

Example #27
0
import email_conf, json, time
from boltiot import Email, Bolt

minimum_val = 300
maximum_val = 600

mybolt = Bolt(email_conf.API_KEY, email_conf.DEVICE_ID)

mailer = Email(email_conf.MAILGUN_API_KEY, email_conf.SANDBOX_URL,
               email_conf.SENDER_EMAIL, email_conf.RECIPIENT_EMAIL)

while True:
    response = mybolt.analogRead('A0')
    data = json.loads(response)
    print("complete data ", data)
    print("data_val ", data['value'])
    try:
        sensor_value = int(data['value'])
        print(" sensor_val ", sensor_value)
        print("temp ", (100 * sensor_value) / 1024)
        if sensor_value > maximum_val or sensor_value < minimum_val:
            response = mailer.send_email(
                "Alert",
                " The current temp val is " + str(sensor_value / 10.24))
    except Exception as e:
        print("Error", e)
    minimum_val = minimum_val - 100
    time.sleep(10)
Example #28
0

Selling_price = input("Enter Selling Price : ")
mybolt = Bolt(conf.api_key, conf.device_id)
sms = Sms(conf.SSID, conf.AUTH_TOKEN, conf.TO_NUMBER, conf.FROM_NUMBER)
mailer = Email(conf.MAILGUN_API_KEY, conf.SANDBOX_URL, conf.SENDER_MAIL,
               conf.RECIPIENT_MAIL)

while True:
    c_price = get_bitcoin_price()
    print(get_bitcoin_price(), time.ctime())
    if c_price >= Selling_price:
        # Enable Buzzer
        response_buzzer = mybolt.digitalWrite('0', 'HIGH')
        print(response_buzzer)
        # Send SMS
        response_SMS = sms.send_sms("The Bitcoin selling price is now : " +
                                    str(c_price))
        # Send Mail
        response_mail = mailer.send_email(
            "PRICE ALERT",
            "The Bitcoin selling price is now : " + str(c_price))
        # Send Telegram Alert
        message = 'Alert! Price is now : ' + str(c_price)
        telegram_status = send_telegram_message(message)
        print("This is the Telegram status:", telegram_status)
    else:
        response = mybolt.digitalWrite('0', 'LOW')
        print(response)
    time.sleep(297)
Example #29
0
import email_conf
from boltiot import Email, Bolt
import json
import time

minimum_limit = 300  # the minimum threshold of light value
maximum_limit = 600  # the maximum threshold of light value

mybolt = Bolt(email_conf.API_KEY, email_conf.DEVICE_ID)
mailer = Email(email_conf.MAILGUN_API_KEY, email_conf.SANDBOX_URL,
               email_conf.SENDER_EMAIL, email_conf.RECIPIENT_EMAIL)

while True:
    print("Reading sensor value")
    response = mybolt.analogRead('A0')
    data = json.loads(response)
    print("Sensor value is: " + str(data['value']))
    try:
        sensor_value = int(data['value'])
        if sensor_value > maximum_limit or sensor_value < minimum_limit:
            print("Making request to Mailgun to send an email")
            response = mailer.send_email(
                "Alert",
                "The Current temperature sensor value is " + str(sensor_value))
            response_text = json.loads(response.text)
            print("Response received from Mailgun is: " +
                  str(response_text['message']))
    except Exception as e:
        print("Error occured: Below are the details")
        print(e)
    time.sleep(10)
Example #30
0
    # 5 second delay for face recognition
    if name == str("Unknown") and (end - start) > 5 and verified == False and i < 1:
        print("\n[ALERT]Intruder inside facility")
        i = i + 1

        print("Checking device status.... ")
        response = mybolt.isOnline()
        data = json.loads(response)
        print("Device is ", str(data["value"]))

        if "online" == str(data["value"]):
            print("Sending request to Alarm")
            response = mybolt.digitalWrite('0', 'HIGH')

        # Sending email to Owner
        print("\n[WARNING] Sending e-mail to owner")
        mailer = Email(conf.MAILGUN_API_KEY, conf.SANDBOX_URL, conf.SENDER_EMAIL, conf.RECIPIENT_EMAIL)
        response = mailer.send_email("Intruder Alert", "Someone tried to access your system")
        response_text = json.loads(response.text)
        print("Response received from Mailgun is: " + str(response_text['message']))

    # Hit 'q' on the keyboard to quit!
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# Switching off alarm if started
response = mybolt.digitalWrite('0', 'LOW')
# Release handle to the webcam
video_capture.release()
cv2.destroyAllWindows()