Commit 36776b90 authored by Guillaume Blanchy's avatar Guillaume Blanchy
Browse files

Merge branch 'MQTT' of gitlab-ssh.irstea.fr:reversaal/OhmPi into MQTT

Showing with 15 additions and 4 deletions
+15 -4
...@@ -15,7 +15,8 @@ OHMPI_CONFIG = { ...@@ -15,7 +15,8 @@ OHMPI_CONFIG = {
'version': 2, 'version': 2,
'max_elec': 64, 'max_elec': 64,
'board_address': {'A': 0x70, 'B': 0x71, 'M': 0x72, 'N': 0x73}, # def. {'A': 0x76, 'B': 0x71, 'M': 0x74, 'N': 0x70} 'board_address': {'A': 0x70, 'B': 0x71, 'M': 0x72, 'N': 0x73}, # def. {'A': 0x76, 'B': 0x71, 'M': 0x74, 'N': 0x70}
} 'settings': 'ohmpi_settings.json'
} # TODO: add a dictionary with INA models and associated gain values
CONTROL_CONFIG = { CONTROL_CONFIG = {
'tcp_port': 5555, 'tcp_port': 5555,
......
...@@ -20,7 +20,7 @@ from datetime import datetime ...@@ -20,7 +20,7 @@ from datetime import datetime
from termcolor import colored from termcolor import colored
import threading import threading
from logging_setup import setup_loggers from logging_setup import setup_loggers
from config import CONTROL_CONFIG from config import CONTROL_CONFIG, OHMPI_CONFIG
from subprocess import Popen from subprocess import Popen
# finish import (done only when class is instantiated as some libs are only available on arm64 platform) # finish import (done only when class is instantiated as some libs are only available on arm64 platform)
...@@ -118,6 +118,7 @@ class OhmPi(object): ...@@ -118,6 +118,7 @@ class OhmPi(object):
self.ads_voltage = ads.ADS1115(self.i2c, gain=2 / 3, data_rate=860, address=0x49) self.ads_voltage = ads.ADS1115(self.i2c, gain=2 / 3, data_rate=860, address=0x49)
# Starts the command processing thread # Starts the command processing thread
self.cmd_listen = True
self.cmd_thread = threading.Thread(target=self.process_commands) self.cmd_thread = threading.Thread(target=self.process_commands)
self.cmd_thread.start() self.cmd_thread.start()
...@@ -650,7 +651,7 @@ class OhmPi(object): ...@@ -650,7 +651,7 @@ class OhmPi(object):
print(colored(f'Listening to commands on tcp port {tcp_port}.' print(colored(f'Listening to commands on tcp port {tcp_port}.'
f' Make sure your client interface is running and bound to this port...', 'blue')) f' Make sure your client interface is running and bound to this port...', 'blue'))
self.exec_logger.debug(f'Start listening for commands on port {tcp_port}') self.exec_logger.debug(f'Start listening for commands on port {tcp_port}')
while True: while self.cmd_listen:
message = socket.recv() message = socket.recv()
self.exec_logger.debug(f'Received command: {message}') self.exec_logger.debug(f'Received command: {message}')
e = None e = None
...@@ -780,6 +781,15 @@ class OhmPi(object): ...@@ -780,6 +781,15 @@ class OhmPi(object):
if self.thread is not None: if self.thread is not None:
self.thread.join() self.thread.join()
self.exec_logger.debug(f'Status: {self.status}') self.exec_logger.debug(f'Status: {self.status}')
def quit(self):
"""Quit OhmPi.
"""
self.cmd_listen = False
if self.cmd_thread is not None:
self.cmd_thread.join()
self.exec_logger.debug(f'Stopped listening to tcp port.')
exit()
...@@ -812,7 +822,7 @@ if __name__ == "__main__": ...@@ -812,7 +822,7 @@ if __name__ == "__main__":
# start interface # start interface
#Popen(['python', CONTROL_CONFIG['interface']]) #Popen(['python', CONTROL_CONFIG['interface']])
ohmpi = OhmPi(settings='ohmpi_settings.json') ohmpi = OhmPi(settings=OHMPI_CONFIG['settings'])
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