Browse Source

fix: update HTTP service configuration and improve authentication handling

Silas Gruen 6 tháng trước cách đây
mục cha
commit
00adf74276

+ 8 - 8
config/config.yaml

@@ -17,19 +17,19 @@ i2c:
   timeout_ms: 100  # Timeout for I2C communications # TODO implement
 
 http:
-  debug: true
-  server_url: "https://batteries.up-cell.de"
+  debug: false
+  server_url: "https://batteries-int.up-cell.de"
   timeout: 5
   endpoint: "cells"
-  username: "test"
-  password: "123"
+  username: ""  # Optional, if authentication is needed
+  password: ""  # Optional, if authentication is needed
 
 measurement:
   cycles: 3
-  c_rate: 0.25
-  cut_off_curr: 100
-  min_voltage: 2.5
-  max_voltage: 4.2
+  c_rate: 0.25 
+  cut_off_curr: 100 # in mA
+  min_voltage: 2.5 # in Volts
+  max_voltage: 4.2 # in Volts
 
 devices:
   - id: 1

+ 4 - 4
src/controllers/measurement_controller.py

@@ -106,12 +106,12 @@ class MeasurementController:
     def _update_inserted_cell(self, insertion_info: InsertedCell):
         """Update the inserted cell id for a device."""
         cell_info = self.http_service.fetch_cell_info(insertion_info.cell_id)
-        min_volt = max(cell_info['cell_type']['min_voltage'], self.config['measurement']['min_voltage'])
-        max_volt = min(cell_info['cell_type']['max_voltage'], self.config['measurement']['max_voltage'])
-        charge_fraction = self.config['measurement']['c_rate']
+        min_volt = int(max(cell_info['cell_type']['min_voltage'], self.config['measurement']['min_voltage'])*1000)  # Convert to mV
+        max_volt = int(min(cell_info['cell_type']['max_voltage'], self.config['measurement']['max_voltage'])*1000)  # Convert to mV
+        charge_fraction = int(self.config['measurement']['c_rate']*100)  # Convert to percentage
         capacity = cell_info['cell_type']['capacity']
         cut_off_curr = self.config['measurement']['cut_off_curr']
-        limits = CellLimits(min_volt, max_volt, charge_fraction, capacity, cut_off_curr, 0)
+        limits = CellLimits(min_volt, max_volt, charge_fraction, capacity, cut_off_curr, 0) # cycle_num is set to 0 initially
         self.devices[insertion_info.device_id].slots[insertion_info.slot_id].insert_cell(Cell(insertion_info.cell_id, limits, capacity))
         
     def _process_done(self, device: Device, slot: Slot):

+ 8 - 7
src/services/http_service.py

@@ -34,8 +34,8 @@ class HTTPService:
         self.debug = config['http'].get('debug', False)
         self.base_url = config['http'].get('server_url')
         self.endpoint = config['http'].get('endpoint')
-        self.username = config['http'].get('username')
-        self.password = config['http'].get('password')
+        self.username = config['http'].get('username', "")
+        self.password = config['http'].get('password', "")
 
     def fetch_cell_info(self, cell_id):      
         if self.debug:
@@ -43,16 +43,17 @@ class HTTPService:
         
         url = f"{self.base_url}/{self.endpoint}/{cell_id}/"
         
-        # Basic Authentication (if required)
-        auth = (self.username, self.password)
-        
         # Headers
         headers = {
             "Accept": "application/json"
         }
         
-        # Making the GET request
-        response = requests.get(url, auth=auth, headers=headers)
+        # Basic Authentication (if required)
+        if self.username and self.password:
+            auth = (self.username, self.password)
+            response = requests.get(url, auth=auth, headers=headers, verify=False)
+        else:
+            response = requests.get(url, headers=headers, verify=False)
         
         # Check if the request was successful
         if response.status_code == 200: