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)
from boltiot import Bolt bolt = open(r'C:\Users\haneef\Documents\Cerdentials\bolt_iot.txt').read() device_id, api_key = bolt.split() mybolt = Bolt(api_key, device_id) ''' pin 0 & intensity level 10 Intensity ranges from (0,255) analogWrite('pin numer', 'intensity value') ''' response = mybolt.analogWrite('0', '10') print(response)
from boltiot import Bolt api_key = "468b7098-505b-4d74-b955-faa4c2f1cb30" device_id = "BOLT292292" myBolt = Bolt(api_key, device_id) # for num in range(5): #myBolt.digitalWrite('0','LOW') myBolt.analogWrite('0', '10') print("Competed")
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: 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
import conf from boltiot import Bolt import json, time mybolt = Bolt(conf.API_KEY, conf.DEVICE_ID) def convert(sensor_value): led_intensity = 255 - (sensor_value * 255 / 1024) return led_intensity while True: print("Reading Sensor Value") response_ldr = mybolt.analogRead('A0') data = json.loads(response) print("Sensor value is: " + str(data['value'])) try: sensor_value = int(data['value']) print("Calculating required Light Intensity for LED") led_value_float = convert(sensor_value) led_value = int(led_value_float) print(led_value) mybolt.analogWrite('1', led_value) except Exception as e: print("Error occured: Below are the details") print(e) time.sleep(5)
#final_output = final_output[['Fstop','ShutterSpeed','Exposure Compensation','Flash']] final_output.reset_index() lower_quartile, top_quartile = final_output['Fstop'].quantile([.25, .50]) if (kind == 1): top_quartile = final_output['Fstop'].quartile([.50]) recomended = final_output[output_dataset['Fstop'] >= top_quartile] elif (kind == 2): recomended = final_output[(output_dataset['Fstop'] >= lower_quartile) & (output_dataset['Fstop'] <= top_quartile)] else: recomended = final_output[output_dataset['Fstop'] <= lower_quartile] #print(value) print(recomended) mybolt.analogWrite('1', value) index = int(input("\nWhich one did you like : ")) #app_record = pd.DataFrame([[final_output.loc[index]['Fstop'],final_output.loc[index]['ShutterSpeed'],ev,1]]) app_record = output_dataset[['Fstop', 'ShutterSpeed']] app_record['EV'] = int(ev) app_record['Match'] = 0 app_record.loc[index, 'Match'] = 1 with open('GuidedLightMeter.csv', 'a') as fd: writer = csv.DictWriter(fd, delimiter=',', lineterminator='\n', fieldnames=[0, 1, 2, 3]) for itr in list(app_record.index): writer.writerow({