|
@@ -1,5 +1,6 @@
|
|
|
import asyncio
|
|
import asyncio
|
|
|
import logging
|
|
import logging
|
|
|
|
|
+import logging.handlers
|
|
|
import yaml
|
|
import yaml
|
|
|
from pathlib import Path
|
|
from pathlib import Path
|
|
|
from services.mqtt_service import MQTTService
|
|
from services.mqtt_service import MQTTService
|
|
@@ -9,17 +10,29 @@ from controllers.measurement_controller import MeasurementController
|
|
|
|
|
|
|
|
async def main():
|
|
async def main():
|
|
|
# Load config
|
|
# Load config
|
|
|
- config_path = Path(__file__).parent / "config" / "config.yaml"
|
|
|
|
|
|
|
+ config_path = Path(__file__).parent.parent / "config" / "config.yaml"
|
|
|
with open(config_path) as f:
|
|
with open(config_path) as f:
|
|
|
config = yaml.safe_load(f)
|
|
config = yaml.safe_load(f)
|
|
|
|
|
|
|
|
# Setup logging
|
|
# Setup logging
|
|
|
logging.basicConfig(
|
|
logging.basicConfig(
|
|
|
level=getattr(logging, config['logging']['level']),
|
|
level=getattr(logging, config['logging']['level']),
|
|
|
- filename=config['logging']['file'],
|
|
|
|
|
- format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
|
|
|
|
|
|
+ format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
|
|
|
|
+ handlers=[
|
|
|
|
|
+ logging.handlers.RotatingFileHandler(
|
|
|
|
|
+ filename=config['logging']['file'],
|
|
|
|
|
+ mode=config['logging']['mode'],
|
|
|
|
|
+ maxBytes=config['logging']['max_bytes'],
|
|
|
|
|
+ backupCount=2,
|
|
|
|
|
+ encoding=None,
|
|
|
|
|
+ delay=0
|
|
|
|
|
+ ),
|
|
|
|
|
+ logging.StreamHandler()
|
|
|
|
|
+ ]
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
+ logging.info("Starting battery measurement controller...")
|
|
|
|
|
+
|
|
|
# Initialize services
|
|
# Initialize services
|
|
|
i2c_service = I2CService(config)
|
|
i2c_service = I2CService(config)
|
|
|
http_service = HTTPService(config)
|
|
http_service = HTTPService(config)
|
|
@@ -28,7 +41,7 @@ async def main():
|
|
|
# Setup MQTT client with callback
|
|
# Setup MQTT client with callback
|
|
|
mqtt_service = MQTTService(config)
|
|
mqtt_service = MQTTService(config)
|
|
|
|
|
|
|
|
- async def on_cell_inserted(device_id: str, slot: int, cell_id: str):
|
|
|
|
|
|
|
+ async def on_cell_inserted(device_id: str, slot: int, cell_id: int):
|
|
|
await measurement_controller.start_measurement(device_id, slot, cell_id)
|
|
await measurement_controller.start_measurement(device_id, slot, cell_id)
|
|
|
|
|
|
|
|
mqtt_service.set_callback(on_cell_inserted)
|
|
mqtt_service.set_callback(on_cell_inserted)
|