import mysql.connector
from boltiot import Bolt
import conf
import time
import json
import re
mybolt = Bolt(conf.bolt_api_key, conf.device_id)
while True:
    response = mybolt.serialRead('1')
    data = json.loads(response)
    recv_data = data['value'].rstrip()
    print(recv_data)
    if ((recv_data) == ''):
        print("Arduino is starting")
        time.sleep(5)
    elif ((recv_data) == 'Command timed out'):
        print("Command Timed out")
    elif (((recv_data) == '\n') or ((recv_data) == '\r')):
        print("")
    else:
        time.sleep(5)
        x = re.findall("\D", recv_data)
        if (x):
            continue
        elif int(recv_data) < 20:
            print(recv_data)
            mybolt.digitalWrite(0, 'HIGH')
            mydb = mysql.connector.connect(host="localhost",
                                           user="******",
                                           passwd="123",
                                           database="sensor")
Esempio n. 2
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]


mybolt = Bolt(conf.API_KEY, conf.DEVICE_ID)
sms = Sms(conf.SSID, conf.AUTH_TOKEN, conf.TO_NUMBER, conf.FROM_NUMBER)
history_data = []

while True:
    mybolt.serialWrite("GetAnalogData")
    response = mybolt.serialRead(10)
    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'].split(",")[0])
    except e:
        print("There was an error while parsing the response: ", e)
        continue
previousWaterLevel = 0
totalWaterConsumed = 0
criticalConsumption = 15  # Try 1
errorMaxValue = 350


def messageToUser(level='CRITICAL LEVEL'):
    twillioMessage.send_sms("ALERT!!!!!!! \nDear User, " + str(level) +
                            " is crossed. Control excess water usages.")
    print('msg sent')


while True:
    if status:

        response = Mybolt.serialRead('10')
        currentWaterLevel = json.loads(response)
        print(currentWaterLevel)
        if totalWaterConsumed >= criticalConsumption:
            messageToUser(totalWaterConsumed)
            time.sleep(10000)
        elif previousWaterLevel < int(
                currentWaterLevel['value']) < errorMaxValue:
            totalWaterConsumed = totalWaterConsumed + int(
                currentWaterLevel['value']) - previousWaterLevel
            previousWaterLevel = int(currentWaterLevel['value'])
        elif int(currentWaterLevel['value']) > errorMaxValue:
            print("Error retrying other loop")
        else:
            previousWaterLevel = currentWaterLevel['value']
    print('total:', totalWaterConsumed, '\nCurrent:',
Esempio n. 4
0
    url = 'https://api.telegram.org/' + Tele_BotID + '/sendMessage'
    data = {'chat_id': Channel_ID, 'text': message}
    try:
        response = requests.request("GET", url, params=data)
        print('This is the Telegram response')
        print(response.text)
        telegram_data = json.loads(response.text)
        return telegram_data["ok"]
    except Exception as e:
        print("Error occured in sending message via Telegram")
        print(e)
        return False


Bolt_ID = "BOLT6098139"
API_Key = 'f04bfd50-9d89-42a8-a957-ff2cfe9fd930'
garbage_full_limit = 7  # the distance between device and  garbage in dustbin
mybolt = Bolt(API_Key,
              Bolt_ID)  #This is to access the bolt device and send commands
response = mybolt.serialRead('10')  #fetch data from arduino
message = "Hello Brother, the trash can is full"
while True:
    response = mybolt.serialRead('10')  #Fetching the value from Arduino
    data = json.loads(response)
    garbage_limit = data['value'].rstrip()
    print("Garbage level is", garbage_limit)
    if int(garbage_limit) < garbage_full_limit:
        Twilio_message(message)
        Tele_message(message)
    time.sleep(10)
Esempio n. 5
0
            i = str(i)
            usr = "******" + i
            presence = len(doc[usr])
            if presence == 0:
                continue
            presence = presence - 1
            presence = len(doc[usr][presence])
            if presence == 1:
                add_exit(i)
                print("added exit to user_" + i)
                usr_list.append(int(i))
        new_month(temp_date)
        data = {"_id": temp_day, "user_0": [], "user_1": [], "user_2": [], "user_3": []}
        coll.insert_one(data)
        day = temp_day
        for j in usr_list:
            add_entry(str(j))
            print("added entry to user_" + str(j))


while True:
    time.sleep(5)
    response = bolt.serialRead("10")
    ans = json.loads(response)
    if ans['success'] == 1:
        if ans['value'] != "":
            tag = ans['value']
            tag_detected(tag)
    else:
        print(response)
Esempio n. 6
0
import requests
import conf
from boltiot import Bolt
import json, time

mybolt = Bolt(conf.bolt_api_key, conf.device_id)  #Create object to fetch data

response = mybolt.serialRead('10')
print(response)


def send_telegram_message(message):
    """Sends message via Telegram"""
    url = "https://api.telegram.org/" + conf.telegram_bot_id + "/sendMessage"
    data = {"chat_id": conf.telegram_chat_id, "text": message}
    try:
        response = requests.request("POST", url, params=data)
        print("This is the Telegram response")
        print(response.text)
        telegram_data = json.loads(response.text)
        return telegram_data["ok"]
    except Exception as e:
        print("An error occurred in sending the alert message via Telegram")
        print(e)
        return False


while True:
    response = mybolt.serialRead('10')  #Fetching the value from Arduino
    data = json.loads(response)
    status_value = data['value'].rstrip()
Esempio n. 7
0
from boltiot import Sms, Bolt
import json, time

mybolt = Bolt(conf.API_KEY, conf.DEVICE_ID)
sms = Sms(conf.SID, conf.AUTH_TOKEN, conf.TO_NUMBER, conf.FROM_NUMBER)
garbage_limit = 10
response = mybolt.serialRead('13')
print(response)

while True:
    print("Reading sensor value")
    response = mybolt.serialRead('13')
    data = json.loads(response)
    print("Garbage value is: " + str(data['value']))
    try:
        garbage_value = int(data['value'].rstrip())
        if garbage_value < garbage_limit or garbage_value == 357:
            print("Making request to Twilio to send a SMS")
            response = sms.send_sms("Hello I'm full, please clean me")
    except Exception as e:
        print("Error occurred: Below are the details")
        print(e)
    time.sleep(20)