This script opens a web view that can be controlled by receiving MQTT messages.
The webview is displayed in fullscreen without window decorators, like a kioskbrowser.
The messages contain the URL that has to be loaded in the web view.
It uses the paho-mqtt
library for MQTT communication and the pywebview
library for creating the web view.
-
Clone the repository or download the script file.
-
Install the required dependencies by running the following command:
pip install -r dependencies.txt
Make sure to have Python and pip installed on your system.
-
Update the script with your MQTT broker configuration:
# MQTT broker configuration broker_address = "mqtt.broker.com" # Replace with your broker's address broker_port = 1883 # Replace with your broker's port topic = "webview/url" # Topic to subscribe for URL updates
Replace
"mqtt.broker.com"
with the address of your MQTT broker, and1883
with the appropriate port number if different. Set thetopic
variable to the desired topic for receiving URL updates. -
Run the script using the following command:
python mqtt_webview.py
The script will connect to the MQTT broker, subscribe to the specified topic, and open a web view window. It will wait for MQTT messages containing URLs to load in the web view.
-
To control the web view, publish MQTT messages with the desired URL to the specified topic from another client. For example, using the
paho-mqtt
library, you can publish a message like this:import paho.mqtt.publish as publish # MQTT broker configuration broker_address = "mqtt.broker.com" # Replace with your broker's address broker_port = 1883 # Replace with your broker's port topic = "webview/url" # Topic to publish URL updates # URL to open url = "http://example.com" # Publish URL to the MQTT topic publish.single(topic, payload=url, hostname=broker_address, port=broker_port)
Replace
"mqtt.broker.com"
with the address of your MQTT broker,1883
with the appropriate port number, and set thetopic
variable to the desired topic for URL updates. Modify theurl
variable with the URL you want to load in the web view. -
The script will receive the MQTT message, load the URL in the web view, and display the webpage.
The following dependencies are required:
- paho-mqtt
- pywebview
You can install the dependencies by running the following command:
pip install -r dependencies.txt
Make sure to run the command in the same directory where the dependencies.txt
file is located.