Skip to content

Instantly share code, notes, and snippets.

@kurokobo
Last active June 17, 2020 12:38
Show Gist options
  • Save kurokobo/079faae1c739c27bded7a2e3e92b6fab to your computer and use it in GitHub Desktop.
Save kurokobo/079faae1c739c27bded7a2e3e92b6fab to your computer and use it in GitHub Desktop.

My working sample for MQTT Device Service for EdgeX Foundry Geneva release

Directory structure

Same as official tutorial.

- device-service-demo
  |- docker-compose.yml
  |- mqtt
     |- configuration.toml
     |- mqtt.test.device.profile.yml

docker-compose.yml

The section volumes and entrypount is important to inform device service where the configuration file is.

  device-mqtt:
    image: edgexfoundry/docker-device-mqtt-go:1.2.0
    ports:
      - "127.0.0.1:49982:49982"
    container_name: edgex-device-mqtt
    hostname: edgex-device-mqtt
    networks:
      edgex-network:
        aliases:
          - edgex-device-mqtt
    environment:
      <<: *common-variables
      Service_Host: edgex-device-mqtt
    volumes:
      - ./mqtt:/custom-config
    depends_on:
      - data
      - command
    entrypoint:
      - /device-mqtt
      - --cp=consul://edgex-core-consul:8500
      - --confdir=/custom-config
      - --registry

configuration.toml

This is based on examples in repository.

Please note 192.168.0.238 is my MQTT broker.

[Writable]
LogLevel = 'DEBUG'

[Service]
BootTimeout = 30000
CheckInterval = '10s'
ClientMonitor = 15000
Host = 'localhost'
Port = 49982
Protocol = 'http'
StartupMsg = 'device mqtt started'
Timeout = 5000
ConnectRetries = 10
Labels = []
EnableAsyncReadings = true
AsyncBufferSize = 16

[Registry]
Host = 'localhost'
Port = 8500
Type = 'consul'

[Logging]
EnableRemote = false
File = ''

[Clients]
  [Clients.Data]
  Protocol = 'http'
  Host = 'localhost'
  Port = 48080

  [Clients.Metadata]
  Protocol = 'http'
  Host = 'localhost'
  Port = 48081

  [Clients.Logging]
  Protocol = 'http'
  Host = 'localhost'
  Port = 48061

[Device]
  DataTransform = true
  InitCmd = ''
  InitCmdArgs = ''
  MaxCmdOps = 128
  MaxCmdValueLen = 256
  RemoveCmd = ''
  RemoveCmdArgs = ''
  ProfilesDir = './res/example'
  UpdateLastConnected = false

# Pre-define Devices
[[DeviceList]]
  Name = 'MQ_DEVICE'
  Profile = 'Test.Device.MQTT.Profile'
  Description = 'MQTT device is created for test purpose'
  Labels = [ 'MQTT', 'test' ]
  [DeviceList.Protocols]
    [DeviceList.Protocols.mqtt]
       Schema = 'tcp'
       Host = '192.168.0.238'
       Port = '1883'
       ClientId = 'CommandPublisher'
       User = ''
       Password = ''
       Topic = 'CommandTopic'
    [[DeviceList.AutoEvents]]
       Frequency = '20s'
       OnChange = false
       Resource = 'testrandfloat64'

# Driver configs
[Driver]
IncomingSchema = 'tcp'
IncomingHost = '192.168.0.238'
IncomingPort = '1883'
IncomingUser = ''
IncomingPassword = ''
IncomingQos = '0'
IncomingKeepAlive = '3600'
IncomingClientId = 'IncomingDataSubscriber'
IncomingTopic = 'DataTopic'
ResponseSchema = 'tcp'
ResponseHost = '192.168.0.238'
ResponsePort = '1883'
ResponseUser = ''
ResponsePassword = ''
ResponseQos = '0'
ResponseKeepAlive = '3600'
ResponseClientId = 'CommandResponseSubscriber'
ResponseTopic = 'ResponseTopic'

mqtt.test.device.profile.yml

Nothing special. Just download example file and place this under ./mqtt directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment