generated by BotFather. It will look similar to this: 123456789:ABCdefGhIJKlmNoPQRsTUVwxyZ Step 2: Retrieve Your Chat ID
Before starting the setup process, ensure you have the following:
For DIY enthusiasts, this ultra-affordable ($5–$10) microcontroller features an integrated camera module. It can be flashed with open-source firmware designed to read Wi-Fi credentials directly from a generated QR code. Software Infrastructure
Ensure your Python security script starts automatically whenever your computer or Raspberry Pi boots up. Create a system service file: sudo nano /etc/systemd/system/camera_security.service Use code with caution. Add the following configuration: ip camera qr telegram full
[ Your IP Camera / NVR Server ] │ ▼ (Triggers Motion Event) [ Python Script / Curl Command ] │ ▼ (Sends HTTPS POST Request) [ Telegram API ] │ ▼ (Instant Notification) [ Your Smartphone / Telegram App ] Step 1: Initialize BotFather
Alternatively, click the web link provided (usually https://t.me ). 3. Activating the Telegram Bot Once the bot opens in Telegram, press the button.
A Telegram bot acts as the intelligent bridge between your camera and your phone. It is a lightweight program that can listen for commands from you or for events from your camera. generated by BotFather
import cv2 import requests import time from datetime import datetime # --- CONFIGURATION VARIABLES --- TELEGRAM_TOKEN = "YOUR_BOT_API_TOKEN" CHAT_ID = "YOUR_TELEGRAM_CHAT_ID" RTSP_URL = "rtsp://username:password@IP_ADDRESS:554/stream_path" # Motion Detection Tuning Parameter MIN_CONTOUR_AREA = 5000 # Higher values reduce false positives (shadows, bugs) COOLDOWN_SECONDS = 10 # Delay between consecutive alert dispatches # ------------------------------- def send_telegram_alert(image_path): """Sends a photo alert with a timestamp layout via Telegram Bot API.""" url = f"https://telegram.orgTELEGRAM_TOKEN/sendPhoto" timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S") caption_text = f"🚨 *SECURITY ALERT* 🚨\nMotion detected on security camera!\n📅 Time: timestamp" payload = "chat_id": CHAT_ID, "caption": caption_text, "parse_mode": "Markdown" try: with open(image_path, "rb") as image_file: files = "photo": image_file response = requests.post(url, data=payload, files=files, timeout=15) if response.status_code == 200: print("[INFO] Telegram notification delivered successfully.") else: print(f"[ERROR] Telegram delivery failed: response.text") except Exception as e: print(f"[CRITICAL] Networking error transmitting to Telegram: e") def main(): print("[INFO] Connecting to the IP Camera feed...") cap = cv2.VideoCapture(RTSP_URL) if not cap.isOpened(): print("[CRITICAL] Failed to establish connection to RTSP stream link.") return print("[INFO] Stream linked. Initializing background baseline subtraction...") # Initialize background subtractor for motion processing back_sub = cv2.createBackgroundSubtractorMOG2(history=500, varThreshold=25, detectShadows=True) last_alert_time = 0 while True: ret, frame = cap.read() if not ret: print("[WARNING] Frame dropped. Attempting reconnection protocol...") time.sleep(5) cap = cv2.VideoCapture(RTSP_URL) continue # Convert frame to grayscale and blur to remove pixel noise gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) blurred = cv2.GaussianBlur(gray, (21, 21), 0) # Apply background subtraction fg_mask = back_sub.apply(blurred) # Clean up mask using thresholding and dilation _, thresh = cv2.threshold(fg_mask, 200, 255, cv2.THRESH_BINARY) dilated = cv2.dilate(thresh, None, iterations=2) # Find structural contours of moving elements contours, _ = cv2.findContours(dilated, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) motion_detected = False for contour in contours: if cv2.contourArea(contour) < MIN_CONTOUR_AREA: continue motion_detected = True break # Valid motion found within parameters if motion_detected: current_time = time.time() if current_time - last_alert_time > COOLDOWN_SECONDS: print("[ALERT] Motion detected! Saving snapshot image frame...") filename = "security_snapshot.jpg" cv2.imwrite(filename, frame) # Execute alert thread send_telegram_alert(filename) last_alert_time = current_time # Sleep briefly to lower host CPU consumption time.sleep(0.05) cap.release() if __name__ == "__main__": main() Use code with caution. 6. Hardening and Optimizing Your System
🛡️
What (Windows, Mac, Linux/Raspberry Pi) do you have available for hosting the bridge? Share public link
The app translates these strings into a localized QR code matrix.
To help refine this layout, what are you using? If you encounter any issues during setup, Share public link
I wrote this program after severe frustration of having my layout trashed every time I switched screen resolutions. Sometimes other programs will switch screen size and trash your layout as well. This program is an answer to this problem, and I thought other people might find it useful too.
TIP: Even with Desktop restore installed, does Windows seem to scramble your icons now every time you reboot, or press F5 to refresh? If so, after you restore your icons the way you want them, manually move one icon a space or two over and then move it back. After that Windows should remember their placement for a much longer time.
Contact: Please direct all requests, bug reports and comments to the Desktop Restore area of the MIDI-OX Forum.
| Copyright 2020 by Jamie O'Connell. All rights reserved. |
| email: |
This page was last modified on 01/13/20
|
This tiny application operates as a Shell extension. It records the layout and positions of icons and programs on the Windows Desktop, and permits restoration of the layout. It appears to operate correctly under Windows 98, Windows ME, Windows 2000, Windows XP, Windows Vista and Windows 7.