Commit fa5008bb authored by Gezer's avatar Gezer
Browse files

fixed docker-compose

parent 5851d8d7
Showing with 22 additions and 7 deletions
+22 -7
......@@ -2,7 +2,7 @@
INFLUXDB_URL=http://influxdb2:8086
INFLUXDB_ORG=docs
INFLUXDB_BUCKET=co2-test
INFLUXDB_TOKEN=35aKI6fq8SRli6cTmSGgvrqn8t4jYKp-ABgL7HGjwez9rh6YXqEt2F4ZGf_jJ_yATjcE8d4aMlqsmu_VaybTWA==
INFLUXDB_TOKEN=w-Isk1D35T90Srj_auFTxsbksn1zRB5MiNZf6h6RuNdb9-2s9ie5c1488JqoYILKrceVm0LaE5KCN2dXdDM-jA==
# MQTT config
MQTT_BROKER_URL=mosquitto
MQTT_BROKER_URL=mosquitto-broker
MQTT_TOPIC="co2/#"
\ No newline at end of file
......@@ -5,10 +5,16 @@ from datetime import datetime
import paho.mqtt.client as mqtt
from stream_processing import jsonhandler
from utils.influx import InfluxDBHelper
import os
class MQTTClientHandler:
MAPPING_FILE_NAME = "backend/stream_processing/mac_to_room.json"
MAPPING_FILE_NAME = os.path.join(
os.path.dirname(os.path.abspath(__file__)),
"mac_to_room.json"
)
MEASUREMENT_NAME = "sensor_data"
TAG_ROOM = "room"
TAG_MAC = "mac"
......@@ -83,6 +89,7 @@ class MQTTClientHandler:
f"Wrote to InfluxDB: {msg}"
)
print(f"Token: {self.influx_writer.get_token()}")
print(f"Url: {self.influx_writer.get_url()}")
print(f"Wrote to InfluxDB: {msg}")
print(f"Ping: {self.influx_writer.ping()}")
except Exception as e:
......
......@@ -15,5 +15,7 @@
"TE:ST:TE:ST:TE:ST": "",
"AB:CD:EF:12:34:56": "",
"a1:b2:c3:d4:e5:f6": "",
"77:88:99:aa:bb:cc": ""
"77:88:99:aa:bb:cc": "",
"test": "",
"aaron": ""
}
\ No newline at end of file
......@@ -5,6 +5,7 @@ from influxdb_client.client.write_api import WriteOptions
class InfluxDBHelper:
def __init__(self, url: str, token: str, org: str, bucket: str):
self.url = url
self.token = token
self.client = InfluxDBClient(url=url, token=token, org=org)
self.bucket = bucket
......@@ -27,9 +28,14 @@ class InfluxDBHelper:
if timestamp:
point.time(timestamp, WritePrecision.NS)
self.write_api.write(bucket=self.bucket, org=self.org, record=point)
def get_token(self):
return self.token
def get_url(self):
return self.url
def ping(self):
return self.client.ping()
......
......@@ -10,7 +10,7 @@ services:
volumes:
- ./backend/stream_processing:/app/backend/stream_processing
env_file:
- ./backend/.env
- ./backend/.env.docker
restart: unless-stopped
depends_on:
- influxdb2
......@@ -23,7 +23,7 @@ services:
image: django-backend
container_name: django-backend
env_file:
- ./backend/.env
- ./backend/.env.docker
ports:
- "8000:8000"
volumes:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment