-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
365 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
FROM erlang:latest | ||
|
||
# Set working directory | ||
WORKDIR /app | ||
|
||
# Copy your Erlang application code into the container | ||
COPY . /app | ||
|
||
# Install any additional dependencies or packages if needed | ||
#RUN apt-get update && apt-get install -y <package-name> | ||
|
||
# Run your Erlang application | ||
CMD ["erl"] | ||
|
||
|
||
#docker build -t my-erlang-app . | ||
|
||
#docker run -it my-erlang-app | ||
#erl -version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
|
||
|
||
```Dockerfile | ||
FROM erlang:latest | ||
|
||
# Set working directory | ||
WORKDIR /app | ||
|
||
# Copy your Erlang application code into the container | ||
COPY . /app | ||
|
||
# Install any additional dependencies or packages if needed | ||
RUN apt-get update && apt-get install -y <package-name> | ||
|
||
# Run your Erlang application | ||
CMD ["erl"] | ||
``` | ||
|
||
```sh | ||
docker build -t my-erlang-app . | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import adafruit_dht | ||
import time | ||
import os | ||
import paho.mqtt.client as mqtt | ||
|
||
# Set default sensor type to DHT22 | ||
dht_sensor_type = os.environ.get('DHT_SENSOR_TYPE', 'DHT22') | ||
|
||
if dht_sensor_type == 'DHT11': | ||
DHT_SENSOR = Adafruit_DHT.DHT11 | ||
elif dht_sensor_type == 'DHT22': | ||
DHT_SENSOR = Adafruit_DHT.DHT22 | ||
else: | ||
print(f"Invalid DHT sensor type '{dht_sensor_type}'. Defaulting to DHT22.") | ||
DHT_SENSOR = Adafruit_DHT.DHT22 | ||
|
||
DHT_PIN = int(os.environ.get('DHT_PIN', '4')) | ||
|
||
# Configure MQTT connection parameters | ||
mqtt_broker = os.environ.get('MQTT_BROKER', '192.168.3.200') | ||
mqtt_port = int(os.environ.get('MQTT_PORT', '1883')) | ||
mqtt_topic_temp = os.environ.get('MQTT_TOPIC_TEMP', 'sensor/temperature') | ||
mqtt_topic_hum = os.environ.get('MQTT_TOPIC_HUM', 'sensor/humidity') | ||
mqtt_username = os.environ.get('MQTT_USERNAME', '') | ||
mqtt_password = os.environ.get('MQTT_PASSWORD', '') | ||
|
||
# Initialize MQTT client and connect to the broker | ||
client = mqtt.Client() | ||
if mqtt_username and mqtt_password: | ||
client.username_pw_set(mqtt_username, mqtt_password) | ||
client.connect(mqtt_broker, mqtt_port, 60) | ||
|
||
while True: | ||
humidity, temperature = Adafruit_DHT.read_retry(DHT_SENSOR, DHT_PIN) | ||
if humidity is not None and temperature is not None: | ||
# Publish temperature and humidity to their respective topics | ||
client.publish(mqtt_topic_temp, '{:.2f}'.format(temperature)) | ||
client.publish(mqtt_topic_hum, '{:.2f}'.format(humidity)) | ||
print("Temperature sent to MQTT topic: {}".format(mqtt_topic_temp)) | ||
print("Humidity sent to MQTT topic: {}".format(mqtt_topic_hum)) | ||
else: | ||
print("Sensor failure. Check wiring.") | ||
time.sleep(5) | ||
|
||
#python3 DHT_to_MQTT.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import streamlit as st | ||
import paho.mqtt.client as mqtt | ||
import time | ||
|
||
# Define the MQTT client | ||
client = mqtt.Client() | ||
|
||
# MQTT Settings | ||
MQTT_BROKER = "192.168.3.200" # Example broker, replace with your broker's address | ||
MQTT_PORT = 1883 | ||
MQTT_TOPIC = "python/mqtt" | ||
|
||
# Callback when connecting to the MQTT broker | ||
def on_connect(client, userdata, flags, rc): | ||
if rc == 0: | ||
print("Connected to MQTT Broker!") | ||
else: | ||
print("Failed to connect, return code %d\n", rc) | ||
|
||
# Callback when receiving a message from the MQTT broker | ||
def on_message(client, userdata, msg): | ||
message = msg.payload.decode() | ||
st.session_state['last_message'] = message | ||
print(f"Received `{message}` from `{msg.topic}` topic") | ||
|
||
client.on_connect = on_connect | ||
client.on_message = on_message | ||
|
||
client.connect(MQTT_BROKER, MQTT_PORT, 60) | ||
|
||
# Subscribe to the topic | ||
client.subscribe(MQTT_TOPIC) | ||
|
||
# Start the loop in another thread | ||
client.loop_start() | ||
|
||
# Streamlit app | ||
st.title('MQTT Streamlit Real-time Data Viewer') | ||
|
||
# Initialize session state | ||
if 'last_message' not in st.session_state: | ||
st.session_state['last_message'] = "Waiting for data..." | ||
|
||
# Display the last message | ||
st.write(f"Last message: {st.session_state['last_message']}") | ||
|
||
# Use a button to update messages manually (for demonstration) | ||
if st.button('Update'): | ||
st.write(f"Last message: {st.session_state['last_message']}") | ||
|
||
# Stop the loop before exiting | ||
st.stop() | ||
client.loop_stop() | ||
|
||
#python3 MQTT_to_Streamlit.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
* <https://pypi.org/project/paho-mqtt/> | ||
|
||
```sh | ||
pip install paho-mqtt | ||
``` |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
version: "2.1" | ||
services: | ||
homeassistant: | ||
image: lscr.io/linuxserver/homeassistant:latest | ||
container_name: homeassistant | ||
#network_mode: host | ||
environment: | ||
- PUID=1000 | ||
- PGID=1000 | ||
- TZ=Europe/Rome | ||
volumes: | ||
- ~/Docker/HomeAssistant:/config | ||
ports: | ||
- 8123:8123 #optional | ||
#devices: | ||
# - /path/to/device:/path/to/device #optional | ||
restart: unless-stopped |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
* <https://jalcocert.github.io/RPi/posts/rpi-iot-dht11-influxdb/#integrating-home-assistant-with-influxdb> | ||
* <https://jalcocert.github.io/RPi/posts/rpi-mqtt/> |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
* <https://github.com/getredash/redash> | ||
* <https://redash.io/help/data-sources/querying/supported-data-sources> | ||
|
||
* <https://hub.docker.com/r/redash/redash/tags?page=1> | ||
|
||
|
||
https://github.com/getredash/redash | ||
|
||
|
||
```sh | ||
# git clone https://github.com/getredash/redash | ||
# cd redash | ||
# cd setup | ||
|
||
git clone https://github.com/getredash/setup | ||
cd setup | ||
chmod +x setup.sh | ||
./setup.sh | ||
``` | ||
|
||
* <https://raw.githubusercontent.com/getredash/setup/master/setup.sh> | ||
* <https://github.com/getredash/setup/blob/master/data/docker-compose.yml> | ||
|
||
`localhost:5000` | ||
|
||
https://redash.io/help/user-guide/visualizations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
## Presto | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.