# Path: config.py
# def editbatconfig(section,item,itemvalue):
# def loadconfig():


from paho.mqtt import client as mqtt_client
from time import sleep
from config import editbatconfig, config
import logger
      print(fail)
      log.error(fail)

  client = mqtt_client.Client(config['mqtt']['clientname'],clean_session=False)
  if config['mqtt']['username']:
    client.username_pw_set(config['mqtt']['username'],config['mqtt']['password'])
  client.on_connect = on_connect
  client.connect(config['mqtt']['brokerip'],config['mqtt']['brokerport'])
  return client

client=connect_mqtt()
client.on_message=on_message
client.on_disconnect=on_disconnect
client.subscribe(config['mqtt']['subscribetopic'],qos=1)
client.loop_start()

def publish(topic,data):
  result = client.publish(topic, data)
  # result: [0, 1]
  status = result[0]
  if status == 0:
    print(f"Send `{data}` to topic `{topic}`")
  else:
    fail=f"MQQT Failed to send message to topic {topic}"
    print(fail)
    log.error(fail)


def test():
  client.loop_start()

# Path: config.py
# def editbatconfig(section,item,itemvalue):
# def loadconfig():


# Path: mqtt.py
from paho.mqtt import client as mqtt_client
from time import sleep
from config import editbatconfig, config
import logger

      print(fail)
      log.error(fail)

  client = mqtt_client.Client(config['mqtt']['clientname'],clean_session=False)
  if config['mqtt']['username']:
    client.username_pw_set(config['mqtt']['username'],config['mqtt']['password'])
  client.on_connect = on_connect
  client.connect(config['mqtt']['brokerip'],config['mqtt']['brokerport'])
  return client

client=connect_mqtt()
client.on_message=on_message
client.on_disconnect=on_disconnect
client.subscribe(config['mqtt']['subscribetopic'],qos=1)
client.loop_start()

def publish(topic,data):
  result = client.publish(topic, data)
  # result: [0, 1]
  status = result[0]
  if status == 0:
    print(f"Send `{data}` to topic `{topic}`")
  else:
    fail=f"MQQT Failed to send message to topic {topic}"
    print(fail)
    log.error(fail)


def test():
  client.loop_start()

  count =0