Skip to Content

abapMQ

abapMQ is a custom open source implementation of MQTT 3.1.1, it currently implements all the packages defined in the protocol, and works over websockets and TCP., it works on 750sp01 and up.

It is now possible to connect to brokers on the internet and send or receive messages via the MQTT protocol:

There is still some work to be done, but the basics are in place, you can now connect your dishwasher(or other IoT devices) to your ABAP instance.

 

TCP Hacky Hack

ABAP supports 3 approaches for defining the TCP frame length,

A TCP frame can be of one of the following frame types, which has to be specified using the attribute frame_type in the frame structure (of type APC_TCP_FRAME).

  • Frame type is IF_APC_TCP_FRAME_TYPES=>CO_FRAME_TYPE_TERMINATOR: The TCP frame (message) is terminated by one or several bytes, e.g. line feed (LF) or carriage return line feed (CRLF). The terminator bytes have to be passed as hex code (00-FF) representation, e.g. for LF is this 0A or for CRLF is this 0D0A, to the terminatorattribute of the frame structure.
  • Frame type is IF_APC_TCP_FRAME_TYPES=>CO_FRAME_TYPE_FIXED_LENGTH: The TCP frame (message) has a constant length in bytes. The frame length in bytes has to be passed to the attribute fixed_length of the frame structure (as decimal number).
  • Frame type is IF_APC_TCP_FRAME_TYPES=>CO_FRAME_TYPE_LENGTH_FIELD: The frame length in bytes is part of the frame (message) itself and in a fixed position of the frame, i.e. a length field exists with a predefined offset and a predefined size. This type of frames (as an example RFC 1006) have the length field in position x of the frame, i.e. offset is x, and the length of the field length is of fixed length, i.e. 1,2,4 or 8 bytes. The length field specifies the whole/gross frame length. In this case the offset in bytes has to be passed to the attribute length_field_offset and the length of the length field in bytes has to be passed to the attribute length_field_length of the of frame structure.

However, in MQTT 3.1.1 the length of the package varies so none of the above can be used directly. To solve this I have set the frame length of all TCP packages to 1 byte, this is very evil, but it works, take care if you choose to use this in a productive environment. Websockets does not have this problem.

    DATA(ls_frame) = VALUE apc_tcp_frame(
      frame_type   = if_apc_tcp_frame_types=>co_frame_type_fixed_length
      fixed_length = 1 ).

    lo_tcp->mi_client = cl_apc_tcp_client_manager=>create(
      i_host          = iv_host
      i_port          = iv_port
      i_frame         = ls_frame
      i_event_handler = lo_tcp ).

 

Over’n’out

abapMQ is MIT licensed and can be found via http://abapmq.org, pull requests welcome :o)

 

Find more open source ABAP on http://dotabap.org

 

To report this post you need to login first.

6 Comments

You must be Logged on to comment or reply to a post.

  1. Jelena Perfiljeva

    Thanks for sharing. For those who’re also wondering what the heck is MQTT here is a summary (source):

    MQTT is a machine-to-machine (M2M)/”Internet of Things” connectivity protocol. It was designed as an extremely lightweight publish/subscribe messaging transport.

    (0) 

Leave a Reply