def laser(): API_KEY = "d1c0747d-cf58-4b22-b97a-cfae6ba9ae2e" DEVIVE_ID = "BOLT7487042" Mybolt = Bolt(API_KEY, DEVIVE_ID) sms = Sms(conf.SSID, conf.AUTH_TOKEN, conf.TO_NUMBER, conf.FROM_NUMBER) print(json.loads(Mybolt.isOnline())['value']) 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 < 1020: #response = sms.send_sms(" an unwanted access") response = Mybolt.digitalWrite('4', 'HIGH') sleep(0) else: response = Mybolt.digitalWrite('4', 'LOW') except Exception as e: print("error", e) sleep(10000)
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 automate(): if request.method == "GET": return "Automation is not here!" else: Device_ID = request.form.get("device") API_KEY = request.form.get("apikey") mybolt = Bolt(API_KEY , Device_ID) status = mybolt.isOnline() if status[11:17] == 'online': return render_template("control.html" , Device_ID = Device_ID , API_KEY = API_KEY) else: return 'Sorry, either your device is offline or you entered invalid credentials! Please try again later...'
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)
class CarLight: def __init__(self): # Enter your own generated bolt API Key & Your own Device Id self.api_key = "638f9a4d-809a-4e47-ac2a-4436e195b503" self.device_id = "BOLT290339" # Setting Threshold value self.maximum_limit = 170 ## Connecting to the bolt IoT Module self.mybolt = Bolt(self.api_key, self.device_id) print(format("Automatic Car light Controller and Adjuster", '_^50')) self.error = '{"success": "0", "message": "A Connection error occurred"}' self.offline = '{"value": "offline", "time": null, "success": 1}' def start(self): # Checking Bolt Device is offline or Online result = self.mybolt.isOnline() if result == self.error: print( "\n Check weather your computer or bolt device is connected to Internet....." ) elif result == self.offline: print("\n Bolt Device is offline") else: while True: print("\n Collecting Value from Sensor") # Collecting Response from the sensor response = self.mybolt.analogRead('A0') data = json.loads(response) if data['value'].isnumeric(): intent = int(data['value']) print("value from sensor is: " + str(intent)) # Comparing Light Intensity & Threshold Value if intent > self.maximum_limit: # If light Intensity is Higher Than Threshold Value Then Dipper is On. analog_ack = self.mybolt.analogWrite('1', '120') digital_ack = self.mybolt.digitalWrite('0', 'LOW') print("Car's Dipper light is On ") else: # Else Main Headlight is On & Dipper is Off analog_ack = self.mybolt.digitalWrite('0', 'HIGH') digital_ack = self.mybolt.digitalWrite('1', 'LOW') print("Car's main Headlight is On") else: print(f"[Error] {data['value']}") time.sleep(1)
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
def laser(): api_key = "b42f36a3-9e5b-440c-8fa4-c57de4e5c4ca" device_id = "BOLT3732040" mybolt = Bolt(api_key, device_id) sms = Sms(conf.SSID, conf.AUTH_TOKEN, conf.TO_NUMBER, conf.FROM_NUMBER) print(json.loads(mybolt.isOnline())['value']) 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 < 1020: response = sms.send_sms(" an unwanted access") response = mybolt.digitalWrite('0', 'HIGH') sleep(20000) except Exception as e: print("error", e) sleep(10000)
from boltiot import Bolt api_key = "6166afe7-40a2-4de6-b173-fdbfc06534fa" device_id = "BOLT7421210" mybolt = Bolt(api_key, device_id) response = mybolt.isOnline() print(response)
import conf, json, time from boltiot import Bolt, Sms API_KEY = "b42f36a3-9e5b-440c-8fa4-c57de4e5c4ca" DEVIVE_ID = "BOLT3732040" Mybolt = Bolt(API_KEY, DEVIVE_ID) SSID = 'ACce54c48ff0e1271d7d50012d96ec89a3' AUTH_TOKEN = 'edaf33cf519a6efe6c8991f8bd397047' FROM_NUMBER = '+15083926124 ' TO_NUMBER = '+918077423699' sms = Sms(SSID, AUTH_TOKEN, TO_NUMBER, FROM_NUMBER) print(json.loads(Mybolt.isOnline())['value']) 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 < 1020: #response = sms.send_sms(" an unwanted access") response = Mybolt.digitalWrite('4', 'HIGH') break except Exception as e: print("error", e) time.sleep(10000)
import time, json, math from boltiot import Bolt, Sms API_KEY = "b42f36a3-9e5b-440c-8fa4-c57de4e5c4ca" DEVIVE_ID = "BOLT3732040" # SELF NOTE need to change SSID = 'ACce54c48ff0e1271d7d50012d96ec89a3' AUTH_TOKEN = 'edaf33cf519a6efe6c8991f8bd397047' FROM_NUMBER = '+15083926124 ' TO_NUMBER = '+918077423699' Diameter = 14 Mybolt = Bolt(API_KEY, DEVIVE_ID) twillioMessage = Sms(SSID, AUTH_TOKEN, TO_NUMBER, FROM_NUMBER) status = Mybolt.isOnline() print(status) 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:
def get_frame(): api_key = "xxxxxxx" device_id = "xxxxxxx" mybolt = Bolt(api_key, device_id) response = mybolt.isOnline() print(response) refIm = cv2.imread("refFrame.jpg") vid1 = cv2.VideoCapture('latestData.mp4') vid2 = cv2.VideoCapture('latestData.mp4') vid3 = cv2.VideoCapture('latestData.mp4') vid4 = cv2.VideoCapture('latestData.mp4') temp = np.zeros(refIm.shape,"uint8") timer = temp.copy() index=0 li=[[5,49],[7,32],[9,4],[10,43],[12,14],[14,3],[15,46],[2,20],[17,17]] red_img=cv2.imread("traffic_lights/red.png") yellow_img=cv2.imread("traffic_lights/yellow.png") green_img=cv2.imread("traffic_lights/green.png") #------------_DEBUG3-------------------# red_img=cv2.resize(red_img,(100,200),None) yellow_img=cv2.resize(yellow_img,(100,200),None) green_img=cv2.resize(green_img,(100,200),None) while True: # setting the video frame for different lanes# #For lane1 # lane1_start_time = calcFrame(li[index][0],li[index][1] ) print("index",index) vid1.set(1, lane1_start_time) _, frame1 = vid1.read() index=(index+1)%9 #For lane2 # lane2_start_time = calcFrame(li[index][0],li[index][1]) print("index",index) vid2.set(1, lane2_start_time) _, frame2 = vid2.read() index=(index+1)%9 #For lane3# lane3_start_time = calcFrame(li[index][0],li[index][1]) print("index",index) vid3.set(1, lane3_start_time) _, frame3 = vid3.read() index=(index+1)%9 #For lane4# lane4_start_time = calcFrame(li[index][0],li[index][1]) print("index",index) vid4.set(1, lane4_start_time) _, frame4 = vid4.read() index=(index+1)%9 # display window. fWin is the final Video# st0 = np.hstack((temp, frame1, temp)) st1 = np.hstack((frame4, timer, frame2)) st2 = np.hstack((temp, frame3, temp)) fWin = np.vstack((st0, st1, st2)) #------------DEBUG1-----------# print(temp.shape,st0.shape,red_img.shape) next_predected_time = 0 if next_predected_time == 0: predected_time = int(process(frame1)) else: predected_time = int(next_predected_time) #print("predicted time is",predected_time) t0 = time.clock() t0 = time.time() mybolt.digitalWrite(0,'LOW') while (time.time()-t0<=predected_time): rem_time=predected_time-(time.time()-t0) print("frame 1") ret1, frame1 = vid1.read() st0 = np.hstack((temp, frame1, temp)) st1 = np.hstack((frame4, timer, frame2)) st2 = np.hstack((temp, frame3, temp)) if rem_time<7: testing = np.hstack((yellow_img,red_img,red_img,red_img)) else: testing = np.hstack((green_img,red_img,red_img,red_img)) #------------DEBUG2-----------# testing=cv2.resize(testing,(st0.shape[1],st0.shape[0]+200),None) fWin = np.vstack((st0,st1,st2,testing)) x, y = int(fWin.shape[0] / 2) + 50, int(fWin.shape[1] / 2) - 80 cv2.putText(fWin, 'Green Window for Lane 1:', (x-280, y-50), cv2.FONT_HERSHEY_PLAIN, 1.0, (0, 255, 0)) cv2.putText(fWin, str(int(rem_time)), (x - 200, y), cv2.FONT_HERSHEY_DUPLEX, 1.0, (0, 0, 255)) imgencode=cv2.imencode('.jpg',fWin)[1] stringData=imgencode.tostring() yield (b'--frame\r\n'b'Content-Type: text/plain\r\n\r\n'+stringData+b'\r\n') #cv2.imshow("frame", fWin) #cv2.waitKey(1) if int(rem_time)==5: print("processing frame 2") next_predected_time=(process(frame2)) print(rem_time) predected_time=next_predected_time mybolt.digitalWrite(0,'HIGH') mybolt.digitalWrite(1,'LOW') #For Frame2# t0 = time.clock() t0 = time.time() next_predected_time = 0 while (time.time() - t0 <= predected_time): rem_time = predected_time - (time.time() - t0) print("frame 2") ret2, frame2 = vid2.read() st0 = np.hstack((temp, frame1, temp)) st1 = np.hstack((frame4, timer, frame2)) st2 = np.hstack((temp, frame3, temp)) #-- Traffic Lights --# if rem_time<7: testing = np.hstack((red_img,yellow_img,red_img,red_img)) else: testing = np.hstack((red_img,green_img,red_img,red_img)) testing=cv2.resize(testing,(st0.shape[1],st0.shape[0]+200),None) fWin = np.vstack((st0,st1,st2,testing)) x, y = int(fWin.shape[0] / 2) + 50, int(fWin.shape[1] / 2) - 80 cv2.putText(fWin, 'Green Window for Lane 2:', (x - 280, y - 50), cv2.FONT_HERSHEY_PLAIN, 1.0, (0, 255, 0)) cv2.putText(fWin, str(int(rem_time)), (x - 200, y), cv2.FONT_HERSHEY_DUPLEX, 1.0, (0, 0, 255)) imgencode=cv2.imencode('.jpg',fWin)[1] stringData=imgencode.tostring() yield (b'--frame\r\n'b'Content-Type: text/plain\r\n\r\n'+stringData+b'\r\n') if int(rem_time) == 5: print("processing frame3") next_predected_time = (process(frame3)) print(rem_time) predected_time=next_predected_time mybolt.digitalWrite(1,'HIGH') mybolt.digitalWrite(2,'LOW') #For Frame3# t0 = time.clock() t0 = time.time() next_predected_time = 0 while (time.time() - t0 <= predected_time): rem_time = predected_time - (time.time() - t0) print("frame 3") ret2, frame3 = vid3.read() st0 = np.hstack((temp, frame1, temp)) st1 = np.hstack((frame4, timer, frame2)) st2 = np.hstack((temp, frame3, temp)) if rem_time<7: testing = np.hstack((red_img,red_img,yellow_img,red_img)) else: testing = np.hstack((red_img,red_img,green_img,red_img)) testing=cv2.resize(testing,(st0.shape[1],st0.shape[0]+200),None) fWin = np.vstack((st0, st1, st2,testing)) x, y = int(fWin.shape[0] / 2) + 50, int(fWin.shape[1] / 2) - 80 cv2.putText(fWin, 'Green Window for Lane 3:', (x - 280, y - 50), cv2.FONT_HERSHEY_PLAIN, 1.0, (0, 255, 0)) cv2.putText(fWin, str(int(rem_time)), (x - 200, y), cv2.FONT_HERSHEY_DUPLEX, 1.0, (0, 0, 255)) imgencode=cv2.imencode('.jpg',fWin)[1] stringData=imgencode.tostring() yield (b'--frame\r\n'b'Content-Type: text/plain\r\n\r\n'+stringData+b'\r\n') if int(rem_time) == 5: print("processing frame4") next_predected_time = process(frame4) print(rem_time) predected_time=next_predected_time mybolt.digitalWrite(2,'HIGH') mybolt.digitalWrite(3,'LOW') #For Frame4# t0 = time.clock() t0 = time.time() next_predected_time = 0 while (time.time() - t0 <= predected_time): rem_time = predected_time - (time.time() - t0) print("frame 4") ret2, frame4 = vid4.read() st0 = np.hstack((temp, frame1, temp)) st1 = np.hstack((frame4, timer, frame2)) st2 = np.hstack((temp, frame3, temp)) if rem_time<7: testing = np.hstack((red_img,red_img,red_img,yellow_img)) else: testing = np.hstack((red_img,red_img,red_img,green_img)) testing=cv2.resize(testing,(st0.shape[1],st0.shape[0]+200),None) fWin = np.vstack((st0, st1, st2,testing)) x, y = int(fWin.shape[0] / 2) + 50, int(fWin.shape[1] / 2) - 80 cv2.putText(fWin, 'Green Window for Lane 4:', (x - 280, y - 50), cv2.FONT_HERSHEY_PLAIN, 1.0, (0, 255, 0)) cv2.putText(fWin, str(int(rem_time)), (x - 200, y), cv2.FONT_HERSHEY_DUPLEX, 1.0, (0, 0, 255)) imgencode=cv2.imencode('.jpg',fWin)[1] stringData=imgencode.tostring() yield (b'--frame\r\n'b'Content-Type: text/plain\r\n\r\n'+stringData+b'\r\n') rem_time = predected_time - (time.time() - t0) if int(rem_time) == 5: print("processing frame 1") next_predected_time = process(frame1) print(rem_time) mybolt.digitalWrite(3,'HIGH')
tag = soup("span") Effected_people = tag[4].contents[0] for i in range(9): if i == 1 or i == 5: continue y = y + Effected_people[i] x = int(y) return (x) #———————Execution starts from here———————————— Effected_people = getting_value() apikey = input("Enter API Key") Bolt_id = input("Enter the Bolt_ID") device = Bolt(apikey, Bolt_id) for i in range(1000): print(device.isOnline()) response = device.serialBegin(9600) x = getting_value() z = checking1(x, 0) response2 = device.serialWrite(x) print(response2) time.sleep(100) #time.sleep(100) with delay for execution for 100 sec y = getting_value() z = checking1(y, 1) response2 = device.serialWrite(y) if (z == 1): device.digitalWrite('0', 'HIGH') time.sleep(5) device.digitalWrite('0', 'LOW')
from boltiot import Bolt api_key = "468b7098-505b-4d74-b955-faa4c2f1cb30" device_id = "BOLT292292" myBolt = Bolt(api_key, device_id) response = myBolt.isOnline() print(response)