Exemplo n.º 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"
    )
Exemplo n.º 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)
Exemplo n.º 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
    if len(history_data) > frame_size:
        del history_data[0:len(history_data) - frame_size]
    Mn = statistics.mean(history_data)
    Variance = 0
    for data in history_data:
        Variance += math.pow((data - Mn), 2)
    Zn = factor * math.sqrt(Variance / frame_size)
    High_bound = history_data[frame_size - 1] + Zn
    Low_Bound = history_data[frame_size - 1] - Zn
    return [High_bound, Low_Bound]


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_EMAIL,
               conf.RECIPIENT_EMAIL)
history_data = []

while True:
    response = mybolt.analogRead('A0')
    data = json.loads(response)
    if data['success'] != '1':
        print("There was an error while retriving 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'])
Exemplo n.º 6
0
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)
Exemplo n.º 7
0
import email_conf
from boltiot import Email, Bolt
import json, time

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:
Exemplo n.º 8
0
import email_conf, json, time
from boltiot import Email, Bolt
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:
response = mybolt.analogRead('A0')
data = json.loads(response)
print (data['value'])
try:
sensor_value = int(data['value'])
print (sensor_value)
if sensor_value > maximum_limit or sensor_value < minimum_limit:
response = mailer.send_email("Alert", "The Current
temperature sensor value is " +str(sensor_value))
except Exception as e:
print ("Error",e)
time.sleep(10)
Exemplo n.º 9
0
        Mn = statistics.mean(history_data)
        variance = 0
        for data in history_data:
            variance += math.pow((data - Mn), 2)
        Zn = factor * math.sqrt(variance / frame_size)
        High_bound = history_data[frame_size - 1] + Zn
        Low_bound = history_data[frame_size - 1] - Zn
        return [High_bound, Low_bound]


history_data = []
min = 20.48
max = 46.08
mybolt = Bolt(conf.API_KEY, conf.DEVICE_ID)
sms = Sms(conf.SID, conf.AUTH_TOKEN, conf.TO_NUMBER, conf.FROM_NUMBER)
mailer = Email(conf.MAILGUN_API_KEY, conf.SANDBOX_URL, conf.SENDER_EMAIL,
               conf.RECEPIENT_EMAIL)
while True:
    print(
        "==========================================================================================================="
    )
    print("Reading sensor value")
    response = mybolt.analogRead('A0')
    data = json.loads(response)
    if data['success'] != 1:
        print("There was an error while retriving the data.")
        print("This is the error:" + data['value'])
        time.sleep(10)
        continue
    try:
        sensor_value = int(data['value'])
    except Exception as e:
        del history_data[0:len(history_data) - frame_size]
    Mn = statistics.mean(history_data)
    Variance = 0
    for data in history_data:
        Variance += math.pow((data - Mn), 2)
    Zn = factor * math.sqrt(Variance / frame_size)
    High_Bound = history_data[frame_size - 1] + Zn
    print("High bound = ", High_Bound)
    Low_Bound = history_data[frame_size - 1] - Zn
    print("Low bound = ", Low_Bound)
    return [High_Bound, Low_Bound]


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_EMAIL,
               conf.RECIPIENT_EMAIL)
history_data = []

while True:
    response = mybolt.analogRead('A0')
    response1 = mybolt.analogRead('A0')

    data = json.loads(response)

    sensor_value1 = int(data['value'])
    sensor_value1 = int((sensor_value1 / 10.24) * 9 / 5 + 32)
    print("The current temp is " + str(sensor_value1) +
          " degrees F, and the sensor value is " + data['value'])
    sensor_value = 0
    try:
        sensor_value = int(data['value'])
Exemplo n.º 11
0
def compute_bounds(history_data, frame_size, factor):
    if len(history_data)<frame_size:
    return None

    if len(history_data)>frame_size:
    del history_data[0:len(history_data)-frame_size]
        Mn = statistics.mean(history_data)
        Varriance = 0
        for data in history_data:
    Varriance += math.pow((data-Mn), 2)
        Zn = factor * math.sqrt(Varriance/frame_size)
        High_bound = history_data[frame_size-1]+ Zn
        Low_bound = history_data[frame_size-1] - Zn
        return [High_bound, Low_bound]
mybolt = Bolt(conf.API_KEY, conf.DEVICE_ID)
mailer = Email(conf.MAILGUN_API_KEY, conf.SANDBOX_URL, conf.SENDER_EMAIL, conf.RECIPIENT_EMAIL)
history_data = []

while True:
    response = mybolt.analogRead('A0')
    data = json.loads(response)
    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:
Exemplo n.º 12
0
import requests, time, json, conf, math, statistics
from boltiot import Sms, Email, Bolt
from threading import Thread, Lock

mybolt = Bolt(conf.api_key, conf.device_id)
mailer = Email(conf.mailgun_api_key, conf.sandbox_url, conf.sender_email,
               conf.recipient_email)
sms = Sms(conf.SSID, conf.AUTH_TOKEN, conf.TO_NUMBER, conf.FROM_NUMBER)
history_data = []


class globalVars():
    pass


G = globalVars()
G.value = 2
G.lock = Lock()
G.kill = False
trigger = 200


def compute_bounds(history_data, frame_size, factor):
    if len(history_data) < frame_size:
        return None

    if len(history_data) > frame_size:
        del history_data[0:len(history_data) - frame_size]

    Mn = statistics.mean(history_data)
Exemplo n.º 13
0
import conf, json, time
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)
Exemplo n.º 14
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)
    Mn = statistics.mean(history_data)
    Variance = 0

    for data in history_data:
        Variance += math.pow((data - Mn), 2)

    Zn = factor * math.sqrt(Variance / frame_size)
    High_bound = history_data[frame_size - 1] + Zn
    Low_bound = history_data[frame_size - 1] - Zn
    return [High_bound, Low_bound]


mybolt = Bolt(ad_conf.API_KEY, ad_conf.DEVICE_ID)
mybolt = Bolt(email_config.API_KEY, email_config.DEVICE_ID)
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))
Exemplo n.º 16
0
from boltiot import Bolt, Email
import credentials
import json, time
import dtree

mybolt = Bolt(credentials.API_KEY, credentials.DEVICE_ID)
mailer = Email(credentials.MAILGUN_API_KEY, credentials.SANDBOX_URL,
               credentials.SENDER_EMAIL, credentials.RECIPIENT_EMAIL)
previous_state = 0
N = True
while N:
    ldr_response = mybolt.analogRead('A0')
    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:
Exemplo n.º 17
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)
Exemplo n.º 18
0
import conf,time,json,math,statistics
from boltiot import Bolt,Email

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

frame = 10
factor = 6
history = []

def computeBounds(history,frame,factor):
    if len(history) < frame:
        return None
    if len(history) > frame:
        del history[0:len(history)-frame]
    mn = statistics.mean(history)
    variance = 0
    for data in history:
        variance += math.pow((data-mn),2)
    z = factor * math.sqrt(variance/frame)
    high = history[frame-1] + z
    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)
        del history_data[0:len(history_data) - frame_size]
    Mn = statistics.mean(history_data)
    Variance = 0
    for data in history_data:
        Variance += math.pow((data - Mn), 2)
    Zn = factor * math.sqrt(Variance / frame_size)
    High_bound = history_data[frame_size - 1] + Zn
    Low_Bound = history_data[frame_size - 1] - Zn
    return [High_bound, Low_Bound]


mybolt = Bolt(conf.API_KEY, conf.DEVICE_ID)
sms = Sms(conf.SSID, conf.AUTH_TOKEN, conf.TO_NUMBER, conf.FROM_NUMBER)
sms_whatsapp = Sms(conf.SSID, conf.AUTH_TOKEN, conf.TO_WHATSAPP,
                   conf.FROM_WHATSAPP)
mailer = Email(conf.MAILGUN_API_KEY, conf.SANDBOX_URL, conf.SENDER_EMAIL,
               conf.RECIPIENT_EMAIL)
history_data = []

while True:
    response = mybolt.analogRead('A0')
    response1 = mybolt.analogRead('A0')
    response2 = mybolt.analogRead('A0')
    data = json.loads(response)
    if data['success'] != '1':
        print("There was an error while retriving the data.")
        print("This is the error:" + data['value'])
        time.sleep(5)
        continue

    sensor_value1 = int(data['value'])
    sensor_value1 = sensor_value1 / 10.24
Exemplo n.º 20
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)
        del history_data[0:len(history_data) - frame_size]
    Mn = statistics.mean(history_data)
    Variance = 0
    for data in history_data:
        Variance += math.pow((data - Mn), 2)
    Zn = factor * math.sqrt(Variance / frame_size)
    High_bound = history_data[frame_size - 1] + Zn
    Low_Bound = history_data[frame_size - 1] - Zn
    return [High_bound, Low_Bound]


minimum_limit = 4
maximum_limit = 7

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)
sms = Sms(conf.SSID, conf.AUTH_TOKEN, conf.TO_NUMBER, conf.FROM_NUMBER)

history_data = []

while True:
    response = mybolt.analogRead('A0')
    data = json.loads(response)

    if data['success'] != '1':
        print("There was an error while retriving the data.")
        print("This is the error:" + data['value'])
        time.sleep(10)
        continue

    print("The sensor value is " + (data['value']))
Exemplo n.º 22
0
       return None
   if len(history_data)>frame_size :
       del history_data[0:len(history_data)-frame_size]
   Mn=statistics.mean(history_data)
   Variance=0
   for data in history_data :
       Variance += math.pow((data-Mn),2)
   Zn = factor * math.sqrt(Variance / frame_size)
   High_bound = history_data[frame_size-1]+Zn
   Low_Bound = history_data[frame_size-1]-Zn
   return [High_bound,Low_Bound]
  
mybolt = Bolt(conf.API_KEY, conf.DEVICE_ID)
sms = Sms(conf.SSID, conf.AUTH_TOKEN, conf.TO_NUMBER, conf.FROM_NUMBER)
sms_whatsapp = Sms(conf.SSID, conf.AUTH_TOKEN, conf.TO_WHATSAPP, conf.FROM_WHATSAPP)
mailer = Email(conf.MAILGUN_API_KEY, conf.SANDBOX_URL, conf.SENDER_EMAIL, conf.RECIPIENT_EMAIL)
history_data=[]
  
while True:
   response = mybolt.analogRead('A0')
   response1 = mybolt.analogRead('A0')
   response2 = mybolt.analogRead('A0')
   data = json.loads(response)
   if data['success'] != '1':
       print("There was an error while retriving the data.")
       print("This is the error:"+data['value'])
       time.sleep(5)
       continue
   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'])
Exemplo n.º 23
0
    for data in history_data:
        Variance += math.pow((data - Mn), 2)
    Zn = factor * math.sqrt(Variance / frame_size)
    High_bound = history_data[frame_size - 1] + Zn
    Low_bound = history_data[frame_size - 1] - Zn
    return [High_bound, Low_bound]


#sensor value=temperature*10.24
minimum_temp_limit = 4 * 10.24
maximum_temp_limit = 20 * 10.24

#api authentication
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_EMAIL,
               conf.RECIPIENT_EMAIL)

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

    print("Sensor value : " + data['value'])
    temperature = float(data['value']) / 10.24
    print("Temperature : " + str(temperature))
    sensor_value = 0
    try:
        sensor_value = int(data['value'])
    except Exception as e:
        print("There was an error while parsing the response: ", e)
        continue
from boltiot import Sms, Email
import json, time
import bitcoin_conf as conf
from requests import request

#set your desirable limits
minimum_limit = 4000
maximum_limit = 5000

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


def get_bitcoin_price():
    #here I am using only USD and INR you can add more by editing the URL here
    URL = "https://min-api.cryptocompare.com/data/price?fsym=BTC&tsyms=USD,INR"

    try:
        response = request("GET", URL)
        print(response)
        response = json.loads(response.text)
        current_price = {}
        current_price['USD'] = response["USD"]
        current_price['INR'] = response["INR"]
        return current_price
    except Exception as e:
        print("Error occured: Below are the details")
        print(e)

Exemplo n.º 25
0
        Variance=0 
        for data in history_data : 
              Variance += math.pow((data-Mn),2) 
        Zn = factor * math.sqrt(Variance / frame_size) 
        High_bound = history_data[frame_size-1]+Zn 
        Low_Bound = history_data[frame_size-1]-Zn 
        return [High_bound,Low_Bound]

critical_limit = 8 #the critical_value of temperature 
maximum_limit = 10 #the maximum_value of temperature 

# Configuring bolt device 
mybolt = Bolt(email_conf.API_KEY, email_conf.DEVICE_ID) 

# Configuring email alert requirement 
mailer = Email(email_conf.MAILGUN_API_KEY, email_conf.SANDBOXURL, email_conf.SENDER_EMAIL, email_conf.RECIPIENT_EMAIL) 

# Configuring sms alert requirement sms = Sms(sms_conf.SSID, sms_conf.AUTH_TOKEN, sms_conf.TO_NUMBER, sms_conf.FROM_NUMBER) 

# setting up empty list to save the temperature sensor readings 
history_data=[] 

while True: 
       
       # saves bolt module response in a variable 
        response = mybolt.analogRead('A0') 

       # saves the response data in a variable 
       data = json.loads(response) 

       if data['success'] != '1': 
from boltiot import Bolt
import conf, conf_sms, conf_mail
from boltiot import Sms, Bolt
from boltiot import Email, Bolt


def get_bitcoin_price():
   URL = "https://min-api.cryptocompare.com/data/price?fsym=BTC&tsyms=USD,JPY,INR" # REPLACE WITH URL
   response = requests.request("GET", URL)
   response = json.loads(response.text)
   current_price = response["USD"]
   return current_price  
   
mybolt = Bolt(conf.bolt_api_key, conf.device_id)
sms=Sms(conf_sms.SID, conf_sms.AUTH_TOKEN, conf_sms.TO_NUMBER, conf_sms.FROM_NUMBER)
mailer=Email(conf_mail.MAILGUN_API_KEY, conf_mail.SANDBOX_URL, conf_mail.SENDER_EMAIL, conf_mail.RECIPIENT_EMAIL)

def get_bitcoin_price():
   try:
   	URL = "https://min-api.cryptocompare.com/data/xxxxxxxxxxxxxxxxxxx=USD,JPY,INR" # REPLACE WITH URL we got from min-api.cryptocompare.com
   	response = requests.request("GET", URL)
   	response = json.loads(response.text)
   	current_price = response["USD"]
   	return current_price
   except Exception as e:
        print("Something went wrong when returning the sensor value")
        print(e)
        return -999
def send_telegram_message(message):
    """Sends message via Telegram"""
    url = "https://api.telegram.org/" + conf.telegram_bot_id + "/sendMessage"
Exemplo n.º 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)
Exemplo n.º 28
0
        print(e)
        return False


def get_bitcoin_price():
    URL = "https://min-api.cryptocompare.com/data/price?fsym=BTC&tsyms=USD,JPY,EUR,INR"  # REPLACE WITH CORRECT URL
    respons = requests.request("GET", URL)
    respons = json.loads(respons.text)
    current_price = respons["USD"]
    return current_price


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))
Exemplo n.º 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)
Exemplo n.º 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()