Пример #1
0
    def run(self):
        # Connect to MQTT broker and start dispatch loop
        dispatch, receive = mqtt.connect(self._mqtt_server, self._routes)

        for action in receive():
            action_type = action["type"]
            payload = _dict(action.get("payload")) or _dict({})
            ag = match_routes.match(action_type)
            if ag:
                ag = ag.groups()
                route_key = ag[0]
                api_method = ag[1]
                if api_method == 'RESULT':
                    # Skip Result topic
                    continue
                api_method = "{0}_{1}".format(route_key, ag[1])
                logging.debug("Action: {0}  Payload {1}".format(
                    action, action.get("payload")))
                id = payload.get("id") or uuid.uuid1()
                try:
                    self.is_whitelisted(api_method)
                    dispatch(getattr(self, api_method)(id, payload))
                except Exception as ex:
                    logging.exception(ex)
                    dispatch(self.failure(route_key, id, repr(ex)))
            else:
                try:
                    logging.error(action)
                except Exception as ex:
                    logging.exception(ex)
Пример #2
0
def update_api(method):
    service = current_app.services.get('update_service')
    api_method = "{0}_{1}".format('api', method)
    payload = _dict(request.args)
    response = {}
    if request.method == 'POST':
        payload = _dict(json.loads(request.data))
    id = payload.get("id") or uuid.uuid1()
    try:
        service.is_whitelisted(api_method)
        response = getattr(service, api_method)(id, payload)
    except Exception as ex:
        logging.exception(ex)
        response = service.failure("api", id, repr(ex))

    return jsonify(response)
Пример #3
0
 def as_dict(self):
     data = _dict({})
     data['name'] = self._port_key
     data['port_num'] = self._port_num
     data['port_name'] = self._port_name
     data['pid'] = self._open_pid
     data['app_path'] = self._open_app
     data['recv_count'] = self._recv_count
     data['send_count'] = self._send_count
     for key in self._attributes:
         data[key] = self._attributes.get(key)
     peer_data = self.peer_dict() or {}
     data.update(peer_data)
     return data
Пример #4
0
 def as_dict(self):
     data = _dict({})
     data['name'] = self._port_key
     data['port_name'] = self._port_key
     data['pid'] = self._vsport.PortOpenAppId
     data['app_path'] = self._vsport.PortOpenAppPath
     data['recv_count'] = self._recv_count
     data['send_count'] = self._send_count
     data['BaudRate'] = self._vsport.Baudrate
     data['DataBits'] = self._vsport.Databits
     data['Parity'] = self._vsport.Parity
     data['StopBits'] = self._vsport.StopBits
     peer_data = self.peer_dict() or {}
     data.update(peer_data)
     return data
Пример #5
0
import time
import importlib
from hbmqtt_broker import MQTTBroker
from admin import start_admin
from helper import _dict
from configparser import ConfigParser
from logging.handlers import TimedRotatingFileHandler
from logging.handlers import RotatingFileHandler
import webbrowser

serivces = [
    'opcdabrg'
]

blueprints = []
context = _dict({})


if __name__ == '__main__':
    formatter = "[%(asctime)s] :: %(levelname)s :: %(name)s :: %(message)s"
    if sys.argv[0] != os.path.split(os.path.realpath(__file__))[1]:
        if os.path.split(sys.argv[0])[0]:
            os.chdir(os.path.split(sys.argv[0])[0])
    log_level = 'INFO'
    log_filenum = 9
    log_maxsize = 4
    webadmin_autorun = 0
    config = ConfigParser()
    if os.access(os.getcwd() + '\\config.ini', os.F_OK):
        config.read('config.ini')
        if config.get('log', 'level'):