15.Interface and Application Programming¶
Assignment¶
Individual assignment:
write an application that interfaces a user with an
input &/or output device that you made
Group assignment:
compare as many tool options as possible
My work¶
APP INVENTOR + ARDUINO¶
App Inventor is a visual programming platform that allows users to create Android mobile apps using a simple drag-and-drop block coding method. It's a great tool for those who want to develop apps without programming experience.
My experience with App Inventor:¶
- I used App Inventor to create apps, including:
- Controlling a robot and a smart flowerpot via Bluetooth modules HC-05 and HC-06.
- Developing an assistant app for teachers to help automate various classroom processes and improve interaction with students.
App desgin
Result
My final project robot remote control system¶
My robot architecture
Robot Architecture Overview:¶
The architecture of the robot is designed to control a BLDC motor via Arduino using Flask on a Raspberry Pi 4 as the server. The entire system utilizes the UART protocol for communication between Raspberry Pi 4 and Arduino. Below is a breakdown of the components and their interaction.
Components:¶
- Raspberry Pi 4:
- Acts as the server.
-
Runs a Flask web application to control the robot.
-
Flask Application:
- Handles HTTP requests and provides a web interface for controlling the robot.
-
Communicates with Python code to send data to Arduino via the UART protocol.
-
Python Code:
- Runs on Raspberry Pi.
-
Responsible for sending commands to Arduino via UART based on user input from the Flask web interface.
-
UART Communication:
- Data is sent from Raspberry Pi (via Python) to Arduino using the UART protocol (serial communication).
-
Ensures real-time communication between the server and the robot hardware.
-
Arduino:
- Receives commands from Raspberry Pi via UART.
-
Controls the BLDC motor driver.
-
BLDC Motor Driver:
- Controlled by Arduino based on the commands received.
-
Manages the operation of the BLDC motor.
-
BLDC Motor:
- The main actuator of the robot.
- Controlled via the BLDC motor driver to drive the robot's movement.
Data Flow:¶
- The user interacts with the Flask web interface hosted on the Raspberry Pi 4.
- Commands are sent through Python code to the Arduino via UART.
- The Arduino processes the commands and controls the BLDC motor driver, which in turn controls the BLDC motor.
This architecture allows the robot to be remotely controlled via a web interface, making it ideal for autonomous or semi-autonomous delivery tasks.
MQTT protocol on esp32¶
MQTT Protocol Overview:¶
MQTT (Message Queuing Telemetry Transport) is a lightweight messaging protocol designed for low-bandwidth, high-latency, or unreliable networks. It's ideal for IoT (Internet of Things) applications where devices need to communicate efficiently with minimal overhead.
How MQTT Works:¶
-
Client-Server Model: MQTT operates on a publish-subscribe model, where devices (clients) can publish messages to a topic or subscribe to receive messages on a topic. The MQTT broker acts as the server, managing message distribution between clients.
-
Broker: The MQTT broker is responsible for routing messages from the publisher to the appropriate subscribers. Popular brokers include Mosquitto, HiveMQ, and EMQX.
-
Publish/Subscribe Mechanism:
- Publisher: A device that sends data (e.g., temperature readings, sensor status).
- Subscriber: A device that listens for messages on a specific topic.
-
Topic: A hierarchical string (e.g.,
home/livingroom/temperature
) used to categorize messages. -
Quality of Service (QoS): MQTT supports three levels of QoS:
- QoS 0: At most once (no acknowledgment).
- QoS 1: At least once (message is acknowledged).
-
QoS 2: Exactly once (ensures no duplicates).
-
Protocol: MQTT works over TCP/IP but can also run over other transport protocols like TLS/SSL for encrypted communication.
My Experience with MQTT:¶
I have worked with MQTT in several projects, specifically with ESP32 and Raspberry Pi devices to control IoT systems remotely.
-
IoT Projects: I used Mosquitto MQTT broker to enable communication between multiple devices (ESP32, Raspberry Pi) for real-time control and monitoring of sensors, such as temperature, humidity, and motion detection.
-
Remote Control: In one of my projects, I integrated MQTT to remotely control an IoT-based lighting system. The MQTT protocol allowed seamless communication between the backend server (running on Go with an MQTT broker) and the ESP32 devices over the internet. This enabled remote control of devices with minimal delay.
-
Security: For secure communication, I implemented TLS/SSL encryption between the MQTT broker and clients, ensuring that data sent over the network was encrypted and protected from unauthorized access.
-
Challenges: One of the challenges I faced was ensuring reliable message delivery across unstable networks, which was handled using QoS 1 to guarantee at least one delivery.
Control led lamp witch mqtt protocol