def service_check(device_id, device_api, sql_curr, db): # Init bolt instance mydevice = Bolt(device_api, device_id) # Check device status response = mydevice.isOnline() if 'online' in response: # GLOW RESPONSE BULB mydevice.digitalWrite(LED, 'HIGH') # CHECK TAMPER PIN tamper_pin = json.loads(mydevice.digitalRead(TPIN)) if tamper_pin['value'] == '1': print("LOCK INIT__DEVICE:", device_id) # LOG UPDATE sql_curr.callproc('log_update', ('1', 'Lock Activated', '0')) db.commit() # MOVE TO ACTIVE DEVICES sql_curr.callproc('activate_device') db.commit() # BLINK RESPONSE BULB for i in range(3): mydevice.digitalWrite(LED, 'LOW') sleep(BLK_INTV) mydevice.digitalWrite(LED, 'HIGH') sleep(BLK_INTV) #else: # REGISTERED TAMPER #sql_curr.callproc('log_update', args = (1, 'Lock found tampered', 1)) #sql_curr.callproc('faulty_device') del mydevice return
def transmit(api,dev_id,i): print("Transmitter ON") mybolt = Bolt(api, dev_id) flag=1 while flag: time.sleep(10) response = mybolt.digitalRead('3') #ACK PIN Read data = json.loads(response) if int(data['value'])==1: rantime=random.choice(range(2,5,1))#random time is selected time.sleep(rantime) #waits for random time response = mybolt.digitalRead('3') #ACK PIN Read data = json.loads(response) if int(data['value'])==1: time.sleep(3) response = mybolt.digitalWrite('0','LOW') #ack pin made zero,indicate active transmission time.sleep(5) response = mybolt.digitalWrite(str(i),'HIGH')# i is the pin number of device to be made high return
def booking(request): api_key = "9b21f2d6-b8b2-4d59-9892-442b41b97b20" bolt_id = "BOLT10922204" status_list = ['Available', 'Occupied', 'Booked'] status = 0 p_sen = Bolt(api_key, bolt_id) if p_sen.isOnline(): mode = True In = p_sen.digitalRead('0') if In[11] == "0": status = 1 else: status = 0 context = {} context['mode'] = mode context['status'] = status_list[status] return render(request, 'test.html', context)
def tamper_check(device_id, device_api, sql_curr, db): # Init bolt instance mydevice = Bolt(device_api, device_id) # Check device status response = mydevice.isOnline() if 'online' in response: mydevice.digitalWrite(LED, 'HIGH') # CHECK TAMPER PIN tamper_pin = json.loads(mydevice.digitalRead(TPIN)) if tamper_pin['value'] == '1': print("Status OK", device_id) # LOG UPDATE sql_curr.callproc('log_update', ('1', 'Routine Check', '0')) db.commit() # ActiveDevice TABLE update sql_curr.callproc('update_status', ('1', '0')) db.commit() else: print("TAMPERED!!_,DEVICE_ID:", device_id) # REGISTERED TAMPER sql_curr.callproc('update_status', ('1', '1')) db.commit() sql_curr.callproc('log_update', ('1', 'Lock tampered', '1')) db.commit() sql_curr.callproc('deactivate_device') db.commit() # TURN OFF GLOW mydevice.digitalWrite(LED, 'LOW') # SEND SMS sql_curr.callproc('get_tamper_report') data = sql_curr.stored_results() for d in data: row = d.fetchone() msg = "TAMPERED DEVICE ID {} TIME {}".format(device_id, row[1]) sendSms(row[0].strip(), msg) break else: sql_curr.callproc('update_status', ('0', '0')) db.commit() sql_curr.callproc('log_update', ('0', 'Device OFFLINE', '0')) db.commit() del mydevice return
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: print("Error occured: Below are the details ")
import conf,json,time from boltiot import Bolt,Sms mybolt = Bolt(conf.API_KEY,conf.DEVICE_ID) sms = Sms(conf.SID,conf.AUTH_TOKEN,conf.TO_NUMBER,conf.FROM_NUMBER) old_state = 0 while True: print("Reading value from Bolt") response = mybolt.digitalRead('1') data = json.loads(response) print (data) new_state = int(data['value']) if old_state != new_state: #Change in state indicates that the garage door is openend or closed try: if new_state == 1: #value of new_state is 1 implies that garage door is open print("Making request to twilio to send SMS") #sending an SMS to the TO NUMBER response = sms.send_sms("Garage is open") print ("Response received from twilio is:"+str(response)) print ("Status of SMS at Twilio is :"+str(response.status)) elif new_state == 0: #value of new_state is 0 implies that garage door is closed print("Making request to twilio to send SMS") #sending an sms to the TO NUMBER response = sms.send_sms("Garage is closed") print ("Response received from twilio is:"+str(response)) print ("Status of SMS at Twilio is :"+str(response.status)) except Exception as e: print("Error occured: Below are the details") print (e) old_state = new_state #assign new_state value to the old_state for the next cycle
def SendMessage(): account_sid = 'ACc85b615ebcfeb6b24b2646f5cd883338' auth_token = '0deac459493fa4bfede8fd4a3fb21046' client = twilio.rest.Client(account_sid, auth_token) message = client.messages \ .create( body='There has been a breach in your house.', from_='+12563872330',#this remains the same to='+16695006489' #keep your phone number here ) while True: #Infinite loop while alarm == 0: #If alarm is off response = mybolt.digitalRead('3') #check if it is being activated if (response == HIGH): print("Security System is activated") mybolt.digitalWrite('2', 'HIGH') #Turn on LED to indicate Aalarm is activated mybolt.digitalWrite('4', 'LOW') alarm = 1 elif (response == LOW): print ("Waiting for Security System to be activated....") else: print ("Probelm in getting value from pin 3") time.sleep(5) #check once in every 5 seconds to avoid exceeding API rate lmit while alarm == 1: #If alarm is on response = mybolt.digitalRead('4') #check is it is being de-activated if (response == HIGH):
response = requests.request("POST", url, params=data) 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 response = mybolt.digitalWrite('0', 'HIGH') #ACK PIN Setted data = json.loads(response) time.sleep(3) #Since Receiver should be always ready,hence permanent loop while 1: response = mybolt.digitalRead('3') #ACK PIN data = json.loads(response) #Low ACK pin means active transission if int(data['value']) == 0: print("Found Info!!") flag = 1 #Is kept high because on transmitter part there might be delay mismatch so it waits for data while flag: time.sleep(10) response = mybolt.digitalRead('1') #Corona Pin data = json.loads(response) time.sleep(10) response = mybolt.analogRead('A0') #Corona Recovery Pin data1 = json.loads(response) if int(data['value']) == 1:
bot.send_photo(chat_id="@alerts_boltIOT19", photo=open("./images/" + str(img_count) + ".bmp", "rb")) 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 response = mb.serialBegin('9600') while True: # response1 = mb.serialRead('10') dread = mb.digitalRead("1") # data = json.loads(response1) dread1 = json.loads(dread) print(dread) if dread1["value"] == '1': with open("image-count.txt", "r") as f: image_count = f.read() # creating a subprocess to take images from ov7670 camera module command = '''C: cd/ cd "Program Files (x86)"\\Java\\jdk1.8.0_231\\bin java code.SimpleRead ''' + image_count + ''' ''' pro = subprocess.Popen('cmd.exe', stdin=subprocess.PIPE, shell=True)
print("Response received from Mailgun is:" + response.text) #------------------------------------------------------------------------------------------------------------------------ mybolt = Bolt(conf.bolt_api_key, conf.device_id) mailer = Email(conf.mailgun_key, conf.sandbox_url, conf.sender_email, conf.receiver_email) minimum = 71 maximum = 153 history_data = [] #------------------------------------------------------------------------------------------------------------------------- while 1: response1 = mybolt.analogRead('A0') temp = json.loads(response1) response2 = mybolt.digitalRead('3') light = json.loads(response2) print("The temperature right now is " + temp['value']) try: temp_value = int(temp['value']) except Exception as e: print(e) continue bound = compute_bounds(history_data, conf.frame_size, conf.multi_factor) if not temp_bound: required_data_count = conf.frame_size - len(history_data) print("Not enough data to compute Z-score. Need ", required_data_count,