import psutil from boltiot import Bolt api_key = "a1d04b0c-01e4-4542-bafa-116090c8f0ae" device_id = "BOLT293335" cpu_Threshold = 0.4 clientId = Bolt(api_key, device_id) interval = 5 def control_green_color(pin, value): response = clientId.digitalWrite(pin, value) def control_red_color(pin, value): response = clientId.digitalWrite(pin,value) while True: cpu_usage = psutil.cpu_percent( interval = interval ) print("CPU usage : ", cpu_usage) if cpu_usage > cpu_Threshold: control_green_color('0','LOW') control_red_color('1', 'HIGH') control_red_color('2', 'LOW') else: control_green_color('0', 'HIGH') control_red_color('1', 'LOW')
import api, time from boltiot import Bolt import json,requests mybolt = Bolt(api.API_KEY, api.DEVICE_ID) def send_telegram_message(message): """Sends message via Telegram""" url = "https://api.telegram.org/" + api.TELEGRAM_BOT_ID + "/sendMessage" data = { "chat_id": api.TELEGRAM_CHAT_ID, "text": message } try: response = requests.request( "POST", url, params=data ) print("This is the Telegram URL") print(url) 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:
config = { "consumer_key": tweet_conf.consumer_key, "consumer_secret": tweet_conf.consumer_secret_key, "access_token": tweet_conf.access_token, "access_token_secret": tweet_conf.access_secret_token } def get_api_object(cfg): auth = tweepy.OAuthHandler(cfg['consumer_key'], cfg['consumer_secret']) auth.set_access_token(cfg['access_token'], cfg['access_token_secret']) return tweepy.API(auth) mybolt = Bolt(tweet_conf.bolt_api_key, tweet_conf.device_id) temp_threshold = 59 while True: response = mybolt.analogRead('A0') data = json.loads(response) print(data['value']) try: sensor_value = int(data['value']) if sensor_value > temp_threshold: print("Temperature has crossed the threshold.") api_object = get_api_object(config) tweet = "Temperature has crossed the threshold." status = api_object.update_status(status=tweet) except Exception as e:
You should have received a copy of the GNU General Public License along with ClimateDAS_IoT. If not, see <https://www.gnu.org/licenses/>. ''' ########################### # @Author: pankajpatro703 # # Licensed under GPL v3 # ########################### from boltiot import Bolt from datetime import datetime, timedelta import conf, time, re import urllib3, json, requests mybolt = Bolt(conf.API_KEY, conf.DEVICE_ID) http = urllib3.PoolManager() def fetch_data(channel_id, read_key): """Returns data-temperature and light intensity from Thingspeak channel""" try: url="http://api.thingspeak.com/channels/%s/feeds/last.json?api_key=%s" \ % (channel_id,read_key) conn = http.request('GET', url) response = conn.data.decode('utf8') data = json.loads(response) conn.close() last_write = list(filter(None, re.split( "[-TZ:]+", data['created_at']))) #get time of last update last_write.append(1)
import mailgun1 from boltiot import Email, Bolt import json, time minimum_limit = 30 #the minimum threshold of light value maximum_limit = 50 #the maximum threshold of light value mybolt = Bolt(mail.API_KEY, mail.DEVICE_ID) mailer = Email(mail.MAILGUN_API_KEY, mail.SANDBOX_URL, mail.SENDER_EMAIL, mail.RECIPIENT_EMAIL) while True: print("Reading sensor value") response = mybolt.analogRead('A0') data = json.loads(response) print("Sensor value is: " + str(data['value'])) try: sensor_value = int(data['value']) if sensor_value > maximum_limit or sensor_value < minimum_limit: print("Making request to Mailgun to send an mail") response = mailer.send_email( "Alert", "The Current temperature sensor value is " + str(sensor_value)) response_text = json.loads(response.text) print("Response received from Mailgun is: " + str(response_text['message'])) except Exception as e: print("Error occured: Below are the details") print(e) time.sleep(10)
import time #Import time to peform delay operations import requests #use requests to send mail via webhooks IFTTT from boltiot import Bolt #Import boliot to control GPIO pins through API import smtplib import twilio import twilio.rest from string import Template from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText mybolt = Bolt(api_key, device_id) HIGH = '{"value": "1", "success": "1"}' #This will be returned by bolt API if digital read is high LOW = '{"value": "0", "success": "1"}'#This will be returned by bolt API if digital read is low alarm = 0 #Alarm is turned off by default def get_contacts(filename): """ Return two lists names, emails containing names and email addresses read from a file specified by filename. """ names = [] emails = [] with open(filename, mode='r') as contacts_file: for a_contact in contacts_file: names.append(a_contact.split()[0]) emails.append(a_contact.split()[1])
import email_conf from boltiot import Email, Bolt import json, time minimum_limit = 300 #the minimum threshold of light value maximum_limit = 600 #the maximum threshold of light value 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'])) try: sensor_value = int(data['value']) if sensor_value > maximum_limit or sensor_value < minimum_limit: print("Making request to Mailgun to send an email") response = mailer.send_email( "Alert", "The Current temperature sensor value is " + str(sensor_value)) response_text = json.loads(response.text) print("Response received from Mailgun is: " + str(response_text['message'])) except Exception as e: print("Error occured: Below are the details") print(e) time.sleep(10)
soup = bp(html.text, 'html.parser') 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 = "f04bfd50-9d89-42a8-a957-ff2cfe9fd930" device_id = "BOLT6098139" mybolt = Bolt(api_key, device_id) response = mybolt.analogWrite('0', '150') print(response)
import json, math, statistics, time from boltiot import Bolt frame_size = 10 mfactor = 3 online = False temp = "Not Recorded" open = False D_ID = input("Bolt device ID:") A_KEY = input("API key:") mybolt = Bolt(A_KEY, D_ID) def device_status(): statmesg = mybolt.isOnline() status = json.loads(statmesg) if status['value'] == 'online': return True else: return False def get_temp(): resp = mybolt.analogRead('A0') tempd = json.loads(resp) if not tempd['success']: return None else:
# Importing the Flask class along with the request and Response Objects from flask import Flask, request, Response # Importing the BolT modules from boltiot import Bolt # Importing the configuration file import conf # Importing the request module to send http requests import requests # Importing the json object to read the data received from the bolt cloud(As the data format is JSON) import json # Instantiate Flask class with a name of __name__ before assignment it to the app variable app = Flask(__name__) # Instantiating the BoLT object using API KEY and Device Id mybolt = Bolt(conf.BOLT_API_KEY, conf.DEVICE_ID) def get_sensor_value_from_pin(pin): """Returns the sensor value. Returns -999 if request fails""" try: # Requesting the BoLT cloud to send the data from the cloud about the specified PIN response = mybolt.analogRead(pin) # Converting the response into JSON object data = json.loads(response) # Returning the sensor value return int(data["value"]) except Exception as e: # If some problem occur I have setup exception handler print("Something went wrong when reading the sensor value") print(e) return -999
import conf from boltiot import Bolt mybolt = Bolt(conf.API_KEY, conf.DEVICE_ID) response = mybolt.isOnline() print(response)
from boltiot import Bolt import json, time, requests api_key = "e90ab9b0-1def-4da5-90cf-2c2c9165fdf9" #Receiver device api device_id = "BOLT1115146" #Receiver device id mybolt = Bolt(api_key, device_id) telegram_chat_id = "@XXXX" #Telegram channel for particular area receiver telegram_bot_id = "botXXXX" #Telegram channel bot for particular area receiver(used for posting message) #Sends telegram message to particular telegram channel def send_telegram_message(message): """Sends message via Telegram""" url = "https://api.telegram.org/" + telegram_bot_id + "/sendMessage" data = {"chat_id": telegram_chat_id, "text": message} try: 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
import json, time, requests from boltiot import Bolt mybolt = Bolt("API Key", "Device ID") while True: response = requests.request( "GET", "https://cloud.boltiot.com/remote/API Key/serialWR?data=getAnalogValues&deviceName=Device ID" ) data = json.loads(response.text) csv = data["value"] temp = csv.split(",") arr = [] for i in range(len(temp) - 1): arr.append(int(temp[i])) print(arr) if arr[0] < 100: print("Water Level below 20%. Turning pump on") requests.request( "GET", "https://cloud.boltiot.com/remote/API Key/serialWR?data=pumpOn&deviceName=Device ID" ) elif arr[4] > 100: print("Water level 100%. Turning pump off") requests.request( "GET", "https://cloud.boltiot.com/remote/API Key/serialWR?data=pumpOff&deviceName=Device ID" ) else: if arr[3] > 100: print("Water level is at 80%")
def __init__(self, api_key=None, device_key=None): self.b = None if api_key is None and device_key is None: print("Non parameterized") else: self.b = Bolt(api_key, device_key)
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) response = mybolt.restart() print(response)
from boltiot import Bolt # importing Bolt from boltiot module import numpy as np # linear algebra import pandas as pd # data processing, CSV file I/O from sklearn.model_selection import train_test_split from sklearn.tree import DecisionTreeClassifier """Configurations for home_automation.py""" # Bolt IoT Credentials api_key = "5aaAPI Key of Bolt Cloud" #API Key of Bolt Cloud device_id = "BOLTXXXXXX" #Device ID # Telegram Credentials telegram_chat_id = "@channel name" telegram_bot_id = "botXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" URL = "https://api.telegram.org/" + telegram_bot_id mybolt = Bolt(api_key, device_id) light_pin1 = "12" light_pin2 = "6" last_message_id = None last_text = None def get_levelsensor_value_from_pin(pin): """Returns the sensor value. Returns -999 if request fails""" try: mybolt.serialWrite("Level") response = mybolt.serialRead('10') print(response) data = json.loads(response)
#!/usr/bin/env python3 from tkinter import * from boltiot import Bolt start = Tk() start.geometry("300x300+100+100") start.title("Led ControL") def on(): mybolt.digitalWrite('0', 'HIGH') print(mybolt.isOnline()) print("High") def off(): mybolt.digitalWrite('0', 'LOW') print(mybolt.isOnline()) print("Low") Butt1 = Button(start, text="ON", command=on) Butt1.pack() Butt2 = Button(start, text="OFF", command=off) Butt2.pack() #Bolt led control code for working API = "" device_id = "" mybolt = Bolt(API, device_id) start.mainloop()
import conf, time, json from boltiot import Bolt, Email mybolt = Bolt(conf.boltApiKey, conf.deviceId) email = Email(conf.mailgunApiKey, conf.sandboxUrl, conf.sender, conf.receiver) min = 9.2 max = 10 while True: response = mybolt.analogRead('A0') data = json.loads(response) sv = int(data["value"]) temp = (100 * sv) / 1024 print("The temperature is ", temp) if temp < min: print("The temperature is lower than ", min) print("Sending Email request") response = email.send_email("Alert", "The temperature is " + str(temp)) print("Mailgun response: ", response.text) elif temp > max: print("The temperature is greater than ", max) print("Sending Email request") response = email.send_email("Alert", "The temperature is " + str(temp)) print("Mailgun response: ", response.text) time.sleep(10)
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)
from boltiot import Bolt import http.client import json api_key = "caXXXXXf2" device_id = "BOLTXXXX" mybolt = Bolt(api_key, device_id) def sms(temp): conn = http.client.HTTPConnection("api.msg91.com") payload = '''{ "sender": "hellos", "route": "4", "country": "91", "sms": [ { "message":"hello how r u?", "to": [ "9XXXXXX" ] } ] }''' x = eval(payload) x['sms'][0]['message'] = "hello temp has exceeded to " + str(temp) y = json.dumps(x) print(y) headers = {'authkey': "2XXXXXXa9", 'content-type': "application/json"} print(payload) conn.request( "POST",
import requests # for making HTTP requests import json # library for handling JSON data import time # module for sleep operation from boltiot import Bolt bolt_api_key = "cxxxxxxf2" # This is your Bolt Cloud API Key device_id = "BOLTXXXXX" # This is the device ID and will be similar to BOLTXXXX where XXXX is some numbers telegram_chat_id = "@bot" # This is the channel ID of the created Telegram channel. Paste after @ symbol. telegram_bot_id = "bot1055783589:AAXXXHqBM" # This is the bot ID of the created Telegram Bot. Paste after bot text. mybolt = Bolt(bolt_api_key, device_id) # this is to send the message to telgram channel def send_telegram_message(message): """Sends message via Telegram""" url = "https://api.telegram.org/" + telegram_bot_id + "/sendMessage" data = {"chat_id": 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 message = 'sat shri akal'
from boltiot import Bolt api_key = "YOUR_API_KEY" device_id = "YOUR_DEVICE_ID" mybolt = Bolt(api_key, device_id) response = mybolt.digitalWrite('0', 'HIGH') print(response)
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)
import json import time from boltiot import Bolt import conf, conf_sms, conf_mail from boltiot import Sms, Bolt from boltiot import Email, Bolt def get_bitcoin_price(): URL = "https://min-api.cryptocompare.com/data/price?fsym=BTC&tsyms=USD,JPY,INR" # REPLACE WITH URL response = requests.request("GET", URL) response = json.loads(response.text) current_price = response["USD"] return current_price mybolt = Bolt(conf.bolt_api_key, conf.device_id) sms=Sms(conf_sms.SID, conf_sms.AUTH_TOKEN, conf_sms.TO_NUMBER, conf_sms.FROM_NUMBER) mailer=Email(conf_mail.MAILGUN_API_KEY, conf_mail.SANDBOX_URL, conf_mail.SENDER_EMAIL, conf_mail.RECIPIENT_EMAIL) def get_bitcoin_price(): try: URL = "https://min-api.cryptocompare.com/data/xxxxxxxxxxxxxxxxxxx=USD,JPY,INR" # REPLACE WITH URL we got from min-api.cryptocompare.com response = requests.request("GET", URL) response = json.loads(response.text) current_price = response["USD"] return current_price except Exception as e: print("Something went wrong when returning the sensor value") print(e) return -999 def send_telegram_message(message):
import connections from boltiot import Sms, Bolt import json, time minimum_limit = 300 maximum_limit = 600 mybolt = Bolt(conf.API_KEY, conf.DEVICE_ID) sms = Sms(conf.SID, conf.AUTH_TOKEN, conf.TO_NUMBER, conf.FROM_NUMBER) while True: print("Reading sensor value") response = mybolt.analogRead('A0') data = json.loads(response) print("Sensor value is: " + str(data['value'])) try: sensor_value = int(data['value']) if sensor_value > maximum_limit or sensor_value < minimum_limit: print("Making request to Twilio to send a SMS") response = sms.send_sms( "The Current temperature sensor value is " + str(sensor_value)) print("Response received from Twilio is: " + str(response)) print("Status of SMS at Twilio is :" + str(response.status)) print( "----------------------------------------------------------------" ) print("Intensity Value: ", sensor_value) print("Dear Prince, Your fieled No: 1 humidity is low") print("Turning on electric motor No: 01..............") response = mybolt.digitalWrite('0', 'HIGH')
from boltiot import Bolt api_key = "YOUR_API_KEY" device_id = "YOUR_DEVICE_ID" mybolt = Bolt(api_key, device_id) response = mybolt.isOnline() print(response)
import sms_conf from boltiot import Sms, Bolt import json, time min_limit = 200 max_limit = 300 mybolt = Bolt(sms_conf.API_KEY, sms_conf.DEVICE_ID) sms = Sms(sms_conf.SID, sms_conf.AUTH_TOKEN, sms_conf.TO_NUMBER, sms_conf.FROM_NUMBER) while True: print("Reading Sensor Value") response = mybolt.analogRead('A0') data = json.loads(response) print("Sensor value is: " + str(data['value'])) try: sensor_value = int(data['value']) if sensor_value > max_limit or sensor_value < min_limit: print("Making request to Twilio to send a SMS") response = sms.send_sms( "The Current temperature sensor value is " + str(response)) print("Response received from Twilio is: " + str(response.status)) except Exception as e: print("Error occured: Below are the details") print(e) time.sleep(10)
import pyttsx3 engine = pyttsx3.init() f = Figlet(font='slant', width=200) print(f.renderText('Hello , Welcome To Temperature Monitoring System')) engine.setProperty('rate', 160) voices = engine.getProperty('voices') engine.setProperty('voice', voices[1].id) engine.say("Hello, Everyone, Welcome To Temperature Monitoring System") engine.runAndWait() engine.say('Please Wait for a while, We are fetching our data') engine.runAndWait() time.sleep(2) minimum_limit = 400 #39.06 Degree Celsius maximum_limit = 600 #58.59 Degree Celsius mybolt = Bolt(conf.API_KEY, conf.DEVICE_ID) sms = Sms(conf.SSID, conf.AUTH_TOKEN, conf.TO_NUMBER, conf.FROM_NUMBER) while True: fb = open("TempData1.txt", "a") fa = open("DangerTemp1.txt", "a") resp = mybolt.analogRead('A0') data = json.loads(resp) try: sensor_value = int(data['value']) Temperature = (100 * sensor_value) / 1024 Temp = round(Temperature, 2) print( f" Room Temperature at {datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')} is : {Temp} Degree Celsius" )
config = { "consumer_key" : tweepy2.consumer_key, "consumer_secret" : tweepy2.consumer_secret, "access_token" : tweepy2.access_token, "access_token_secret" : tweepy2.access_token_secret } # Method to authenticate user via Tweepy and return API object def get_api_object(cfg): auth =tweepy.OAuthHandler(cfg['consumer_key'], cfg['consumer_secret']) auth.set_access_token(cfg['access_token'], cfg['access_token_secret']) return tweepy.API(auth) mybolt = Bolt(tweepy2.bolt_cloud_api_key, tweepy2.device_id) temperature_threshold = 59 while True: response = mybolt.analogRead('A0') data = json.loads(response) print (data['value']) try: sensor_value = int(data['value']) if sensor_value > temperature_threshold: print "Temperature has crossed the threshold." # Call get_api_object to authenticate user and get the API object api_object = get_api_object(config) # Store the tweet message in the variable tweet = "Temperature has crossed the threshold." # Post the tweet on your Twitter account using the update_status method. status = api_object.update_status(status=tweet)