Rajat Kumar
Published © LGPL

Telegram Bitcoin Notifier with Buzzer using Bolt IOT

The user gets alert in his mobile as soon as the price of the bitcoin falls below a threshold and a buzzer sounds up to notify him.

IntermediateFull instructions provided3 hours508
Telegram Bitcoin Notifier with Buzzer using Bolt IOT

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
You can buy it from Amazon
×1
Android device
Android device
Any android device just to install telegram in it.
×1
Buzzer
Buzzer
×1

Software apps and online services

Telegram app

Story

Read more

Schematics

Buzzer connection

Connect buzzer to Bolt Iot

Code

conf.py

Python
configuration file
"""Configurations for 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 = 700000                       # Threshold beyond which the alert should be sent

alert.py

Python
Main program
import requests, time, json, conf                    
from boltiot import Bolt       
                
mybolt = Bolt(conf.bolt_api_key, conf.device_id)

def get_bitcoin_price():
   URL = "https://min-api.cryptocompare.com/" # REPLACE WITH CORRECT URL
   response = requests.request("GET", URL)
   response = json.loads(response.text)
   current_price = response["INR"]
   return current_price

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:
    current_price = get_bitcoin_price()
    if current_price <= conf.threshold:
        print("Bitcoin has exceeded threshold")
        message = "Alert! The current Bitcoin Price is " + str(current_price)
        telegram_status = send_telegram_message(message)
        response = mybolt.digitalWrite('0', 'HIGH')
        print(response)
        time.sleep(5)
        response = mybolt.digitalWrite('0', 'LOW')
    time.sleep(10)

Credits

Rajat Kumar

Rajat Kumar

1 project • 0 followers

Comments