Sanket Bagde
Published © GPL3+

Emergency shutdown and monitoring Temperature system

Controlling the industrial machines (Boiler/Heater) to avoid major disaster to happen. Highest priority with Telegram Alert.

IntermediateFull instructions provided2 hours424
Emergency shutdown and monitoring Temperature system

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
LED (generic)
LED (generic)
×2
Buzzer
Buzzer
×1
Resistor 330 ohm
Resistor 330 ohm
×2
Temperature Sensor
Temperature Sensor
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×3
Jumper wires (generic)
Jumper wires (generic)
×6
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×1

Software apps and online services

Telegram Messenger
Assistant SDK
Google Assistant SDK
Windows 10
Microsoft Windows 10

Story

Read more

Schematics

Schematic of Project

Simple connection. with Resistor of 330 ohm. please don't use resistor with buzzer.

Code

conf.py

Python
Create a config file to hold the configuration variables
"""Configurations for telegram_alert.py"""
bolt_api_key = "XXXX"                 # This is your Bolt Cloud API Key
device_id = "XXXX"                    # This is the device ID and will be similar to BOLTXXXX where XXXX is some numbers
telegram_chat_id = "@XXXX"            # This is the channel ID of the created Telegram channel. Paste after @ symbol.
telegram_bot_id = "botXXXX"           # This is the bot ID of the created Telegram Bot. Paste after bot text.
threshold = 38                       # Threshold beyond which the alert should be sent

Telegram and controlling LEDs and buzzer.

Python
Now we will need to create a new python file for telegram and controlling LED
import requests                 # for making HTTP requests
import json                     # library for handling JSON data
import time                     # module for sleep operation
from boltiot import Bolt        # importing Bolt from boltiot module
import conf                     # config file

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:
response = mybolt.analogRead(pin)
data = json.loads(response)
   if data["success"] != 1:
   print("Request not successfull")
   print("This is the response->", data)
  return -999
  
sensor_value = int(data["value"])
temp = (100*sensor_value)/1024
print("Temperature value is: " + str(temp) + "'C")
return temp
except Exception as e:
print("Something went wrong when returning the sensor value")
print(e)
return -999


def send_telegram_message(message):
"""Sends message via Telegram"""
url = "https://api.telegram.org/" + conf.telegram_bot_id + "/sendMessage"
data = {
"chat_id": conf.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:
# Step 1
temp = get_sensor_value_from_pin("A0")


# Step 2
if temp == -999:
print("Request was unsuccessfull. Skipping.")
time.sleep(10)
continue


# Step 3
if temp >= conf.threshold:
print("Sensor value has exceeded threshold")
message = "Alert! Sensor value has exceeded " + str(conf.threshold) + \
" The current value is " + str(temp)
telegram_status = send_telegram_message(message)
print("This is the Telegram status:", telegram_status)
response = mybolt.digitalWrite('1', 'LOW')
response = mybolt.digitalWrite('2', 'LOW')
response = mybolt.analogWrite('3','145')


# Step 4
if temp <= conf.threshold:
response = mybolt.analogWrite('3','0')
response = mybolt.digitalWrite('2', 'HIGH')


# Step 5
time.sleep(10)

Credits

Sanket Bagde
1 project • 1 follower
Thanks to Team Nitro.

Comments