Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IoT Device Control Script #1105

Merged
merged 6 commits into from
Nov 10, 2024
Merged

IoT Device Control Script #1105

merged 6 commits into from
Nov 10, 2024

Conversation

dino65-dev
Copy link
Contributor

Pull Request for PyVerse 💡

Requesting to submit a pull request to the PyVerse repository.


Issue Title

Please enter the title of the issue related to your pull request.
IoT Device Control Using MQTT and Python

  • I have provided the issue title.

Info about the Related Issue

What's the goal of the project?
The aim of this project is to develop a Python-based application for controlling IoT devices using the MQTT protocol. It focuses on establishing secure, reliable communication between the application and IoT devices through an MQTT broker. The project incorporates advanced features such as TLS/SSL for secure data transmission, dynamic topic management for flexible device interaction, and robust error handling to ensure seamless operation. Additionally, it includes logging capabilities to monitor and troubleshoot the application's behavior. This setup is designed to facilitate two-way communication, allowing the application to send commands to IoT devices and receive responses, making it suitable for complex IoT environments.

  • I have described the aim of the project.

Name

Please mention your name.
Dinmay Kumar Brahma

  • I have provided my name.

GitHub ID

Please mention your GitHub ID.
dino65-dev

  • I have provided my GitHub ID.

Email ID

Please mention your email ID for further communication.
[email protected]

  • I have provided my email ID.

Identify Yourself

Mention in which program you are contributing (e.g., WoB, GSSOC, SSOC, SWOC).

  • GSSOC-EXT 24

  • CONTRIBUTOR

  • I have mentioned my participant role.


Closes

Enter the issue number that will be closed through this PR.
*Closes: #1042 *

  • I have provided the issue number.

Describe the Add-ons or Changes You've Made

Give a clear description of what you have added or modified.

  1. Secure Communication:

    • TLS/SSL: The script now uses TLS/SSL for secure communication with the MQTT broker. This is achieved by setting up the tls_set() method on the MQTT client, which ensures that data exchanged between the client and broker is encrypted.
  2. Dynamic Topic Management:

    • The script allows for dynamic subscription to a response topic (response_topic) upon successful connection. This enables the client to listen for messages from the IoT device.
  3. Enhanced Error Handling:

    • Connection Handling: The on_connect callback function checks the connection result code (rc) and logs whether the connection was successful or failed.
    • Publishing Errors: The script includes try-except blocks around the connection and publishing operations to catch and log any exceptions that occur, providing clear error messages for troubleshooting.
  4. Logging:

    • The script uses the logging module to provide detailed logs for various events, such as successful connections, message receipt, and errors. This helps in monitoring the application's behavior and diagnosing issues.
  5. Callback Functions:

    • on_connect: Handles connection events and subscribes to the response topic.
    • on_message: Processes incoming messages from the subscribed topic and logs them.
    • on_log: Provides additional logging for debugging purposes.
  6. Loop Management:

    • The script uses client.loop_start() to handle network traffic and callbacks in a separate thread, allowing the script to remain responsive and continuously listen for incoming messages.

These enhancements make the script more robust, secure, and suitable for advanced IoT applications where secure communication and feedback from the device are necessary.

  • I have described my changes.

Type of Change

Select the type of change:

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Code style update (formatting, local variables)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Describe how your changes have been tested.
I have described my testing process in readme file.

  • I have described my testing process.

Checklist

Please confirm the following:

  • My code follows the guidelines of this project.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly wherever it was hard to understand.
  • I have made corresponding changes to the documentation.
  • My changes generate no new warnings.
  • I have added things that prove my fix is effective or that my feature works.
  • Any dependent changes have been merged and published in downstream modules.

Copy link

github-actions bot commented Nov 5, 2024

👋 Thank you for opening this pull request! We're excited to review your contribution. Please give us a moment, and we'll get back to you shortly!

Feel free to join our community on Discord to discuss more!

@UTSAVS26 UTSAVS26 added Contributor Denotes issues or PRs submitted by contributors to acknowledge their participation. Status: Review Ongoing PR is currently under review and awaiting feedback from reviewers. level1 gssoc-ext labels Nov 6, 2024
@github-actions github-actions bot force-pushed the main branch 2 times, most recently from 609b090 to c1dc75e Compare November 7, 2024 02:42
@TheChaoticor TheChaoticor merged commit 4ed10cf into UTSAVS26:main Nov 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Contributor Denotes issues or PRs submitted by contributors to acknowledge their participation. gssoc-ext level1 Pass : Other Mentor Review Status: Review Ongoing PR is currently under review and awaiting feedback from reviewers.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Code Addition Request]: IoT Device Control Script
4 participants