├── .gitattributes ├── .DS_Store ├── Temperature Alert ├── __pycache__ │ └── email_conf.cpython-38.pyc ├── email_conf.py └── temp_alert.py └── Z score analysis ├── __pycache__ └── email_conf.cpython-38.pyc ├── email_conf.py └── zscore.py /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techiesms/Codes-for-IoT---ML-Workshop-/master/.DS_Store -------------------------------------------------------------------------------- /Temperature Alert/__pycache__/email_conf.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techiesms/Codes-for-IoT---ML-Workshop-/master/Temperature Alert/__pycache__/email_conf.cpython-38.pyc -------------------------------------------------------------------------------- /Z score analysis/__pycache__/email_conf.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techiesms/Codes-for-IoT---ML-Workshop-/master/Z score analysis/__pycache__/email_conf.cpython-38.pyc -------------------------------------------------------------------------------- /Temperature Alert/email_conf.py: -------------------------------------------------------------------------------- 1 | MAILGUN_API_KEY = 'This is the private API key which you can find on your Mailgun Dashboard' 2 | SANDBOX_URL= 'You can find this on your Mailgun Dashboard' 3 | SENDER_EMAIL = 'This would be test@your SANDBOX_URL' 4 | RECIPIENT_EMAIL = 'Enter your Email ID Here' 5 | API_KEY = 'This is your Bolt Cloud account API key' 6 | DEVICE_ID = 'This is the ID of your Bolt device' -------------------------------------------------------------------------------- /Z score analysis/email_conf.py: -------------------------------------------------------------------------------- 1 | MAILGUN_API_KEY = 'This is the private API key which you can find on your Mailgun Dashboard' 2 | SANDBOX_URL= 'You can find this on your Mailgun Dashboard' 3 | SENDER_EMAIL = 'This would be test@your SANDBOX_URL' 4 | RECIPIENT_EMAIL = 'Enter your Email ID Here' 5 | API_KEY = 'This is your Bolt Cloud account API key' 6 | DEVICE_ID = 'This is the ID of your Bolt device' 7 | FRAME_SIZE = 10 8 | MUL_FACTOR = 6 9 | -------------------------------------------------------------------------------- /Temperature Alert/temp_alert.py: -------------------------------------------------------------------------------- 1 | import email_conf 2 | from boltiot import Email, Bolt 3 | import json, time 4 | 5 | minimum_limit = 300 #the minimum threshold of light value 6 | maximum_limit = 600 #the maximum threshold of light value 7 | 8 | 9 | mybolt = Bolt(email_conf.API_KEY, email_conf.DEVICE_ID) 10 | mailer = Email(email_conf.MAILGUN_API_KEY, email_conf.SANDBOX_URL, email_conf.SENDER_EMAIL, email_conf.RECIPIENT_EMAIL) 11 | 12 | 13 | while True: 14 | print ("Reading sensor value") 15 | response = mybolt.analogRead('A0') 16 | data = json.loads(response) 17 | print ("Sensor value is: " + str(data['value'])) 18 | try: 19 | sensor_value = int(data['value']) 20 | if sensor_value > maximum_limit or sensor_value < minimum_limit: 21 | print("Making request to Mailgun to send an email") 22 | response = mailer.send_email("Alert", "The Current temperature sensor value is " +str(sensor_value)) 23 | response_text = json.loads(response.text) 24 | print("Response received from Mailgun is: " + str(response_text['message'])) 25 | except Exception as e: 26 | print ("Error occured: Below are the details") 27 | print (e) 28 | time.sleep(10) 29 | -------------------------------------------------------------------------------- /Z score analysis/zscore.py: -------------------------------------------------------------------------------- 1 | import email_conf, json, time, math, statistics 2 | from boltiot import Email, Bolt 3 | 4 | def compute_bounds(history_data,frame_size,factor): 5 | if len(history_data)frame_size : 9 | del history_data[0:len(history_data)-frame_size] 10 | Mn=statistics.mean(history_data) 11 | Variance=0 12 | for data in history_data : 13 | Variance += math.pow((data-Mn),2) 14 | Zn = factor * math.sqrt(Variance / frame_size) 15 | High_bound = history_data[frame_size-1]+Zn 16 | Low_bound = history_data[frame_size-1]-Zn 17 | return [High_bound,Low_bound] 18 | 19 | mybolt = Bolt(email_conf.API_KEY, email_conf.DEVICE_ID) 20 | mailer = Email(email_conf.MAILGUN_API_KEY, email_conf.SANDBOX_URL, email_conf.SENDER_EMAIL, email_conf.RECIPIENT_EMAIL) 21 | history_data=[] 22 | 23 | while True: 24 | try: 25 | response = mybolt.analogRead('A0') 26 | data = json.loads(response) 27 | print ("This is the value "+data['value']) 28 | sensor_value = int(data['value']) 29 | bound = compute_bounds(history_data,email_conf.FRAME_SIZE,email_conf.MUL_FACTOR) 30 | history_data.append(int(data['value'])) 31 | 32 | 33 | if not bound: 34 | print("Not enough data to compute Z-score") 35 | 36 | elif sensor_value > bound[0] : 37 | print ("The Temperature level increased suddenly. Sending an Email.") 38 | response = mailer.send_email("Alert", "The Current temperature sensor value is " +str(sensor_value)) 39 | print("This is the response ",response) 40 | 41 | elif sensor_value < bound[1]: 42 | print ("The Temperature level decreased suddenly. Sending an Email.") 43 | response = mailer.send_email("Alert", "The Current temperature sensor value is " +str(sensor_value)) 44 | print("This is the response ",response) 45 | except Exception as e: 46 | print ("Error",e) 47 | time.sleep(10) --------------------------------------------------------------------------------