parent
87521ddce2
commit
982680a1c3
25
README.md
25
README.md
|
@ -83,7 +83,7 @@ For the professionals out there, most of you will already know how to pixel cont
|
||||||
### Commands to install all the required packages:
|
### Commands to install all the required packages:
|
||||||
|
|
||||||
```
|
```
|
||||||
sudo apt update -y && sudo apt upgrade -y && sudo apt install python3 python3-pip git python3-flask apache2 php mariadb-server mariadb-client ola ola-python dnsmasq hostapd rfkill -y
|
sudo apt update -y && sudo apt upgrade -y && sudo apt install python3 python3-pip git python3-flask apache2 php mariadb-server mariadb-client ola ola-python dnsmasq hostapd rfkill mosquitto mosquitto-clients -y
|
||||||
sudo rm /usr/lib/python3.11/EXTERNALLY-MANAGED
|
sudo rm /usr/lib/python3.11/EXTERNALLY-MANAGED
|
||||||
pip3 install Flask
|
pip3 install Flask
|
||||||
pip3 install adafruit_circuitpython_neopixel
|
pip3 install adafruit_circuitpython_neopixel
|
||||||
|
@ -236,6 +236,29 @@ exit;
|
||||||
sudo systemctl restart apache2
|
sudo systemctl restart apache2
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Setup a MQTT broker for the communication between the master and the tubes:
|
||||||
|
|
||||||
|
Enable the service
|
||||||
|
|
||||||
|
`sudo systemctl enable mosquitto.service`
|
||||||
|
|
||||||
|
Now we are going to enable remote access to the broker.
|
||||||
|
|
||||||
|
Edit the config file
|
||||||
|
|
||||||
|
`sudo nano /etc/mosquitto/mosquitto.conf`
|
||||||
|
|
||||||
|
Paste the following two lines in the config file:
|
||||||
|
|
||||||
|
```
|
||||||
|
listener 1883
|
||||||
|
allow_anonymous true
|
||||||
|
```
|
||||||
|
|
||||||
|
Now save and exit and restart the services:
|
||||||
|
|
||||||
|
`sudo systemctl restart mosquitto`
|
||||||
|
|
||||||
### Clone the project to your Pi
|
### Clone the project to your Pi
|
||||||
|
|
||||||
You can just clone the project itself into your home directory.
|
You can just clone the project itself into your home directory.
|
||||||
|
|
|
@ -6,6 +6,7 @@ import requests
|
||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
import paho.mqtt.client as mqtt
|
||||||
|
|
||||||
# Replace with your server's IP address and port
|
# Replace with your server's IP address and port
|
||||||
SERVER_IP = '192.168.0.1' # Change to the actual IP of the PiXelTube Master
|
SERVER_IP = '192.168.0.1' # Change to the actual IP of the PiXelTube Master
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
from flask import Flask, render_template, request, jsonify
|
from flask import Flask, render_template, request, jsonify
|
||||||
import json
|
import json
|
||||||
import MySQLdb
|
import MySQLdb
|
||||||
|
import paho.mqtt.client as mqtt
|
||||||
|
import threading
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
@ -30,6 +32,8 @@ db = MySQLdb.connect(
|
||||||
database=config['mysql']['database'],
|
database=config['mysql']['database'],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
mqttc = mqtt.Client("localhost", 1883, 60)
|
||||||
|
|
||||||
# Function to retrieve registered tubes from the database
|
# Function to retrieve registered tubes from the database
|
||||||
def get_tubes():
|
def get_tubes():
|
||||||
cur = db.cursor()
|
cur = db.cursor()
|
||||||
|
@ -79,8 +83,12 @@ def get_assigned_params(tube_unique_id):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return jsonify({'success': False, 'message': f'Error: {e}'})
|
return jsonify({'success': False, 'message': f'Error: {e}'})
|
||||||
|
|
||||||
def main():
|
def flask_api():
|
||||||
app.run(host='0.0.0.0', port=5000)
|
app.run(host='0.0.0.0', port=5000)
|
||||||
|
|
||||||
|
def mqtt_publisher(mqtt):
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
mqtt_publisher(mqtt)
|
||||||
|
flask_api()
|
||||||
|
|
Loading…
Reference in New Issue