Skip to content

Messaging Protocols MQTT openHAB AWS IoT

Duho David Kim edited this page Oct 12, 2015 · 4 revisions

Messaging Protocols - MQTT openHAB AWS IoT

MQTT

  • About
  • MQTT (Message Queue Telemetry Transport - comes from IBM's MQ product line) on top of TCP/IP
  • machine-to-machine (M2M) / Internet of Things connectivity protocol
  • extremely lightweight publish / subscribe messaging transport
  • connections with remote locations where a small code footprint
  • limited network bandwidth
  • example-1: sensors communicating to a broker via satellite link
  • example-2: home automation, small devices
  • example-3: mobile applications (small size, low power, minimized packets, efficient distribution of information to one or many receivers)
  • MQTT Specification
  • MQTT v3.1.1 - OASIS Standard (pdf)
  • MQTT-SN v1.2 - Sensor Networks (pdf)
  • MQTT Server (/or Brokers): links
  • Mosquitto
  • HiveMQ
  • RabbitMQ + MQTT Plugin, MQTT Plugin
  • MQTT Client
  • Eclipse Paho, Paho Client Example, Paho-MQTT 1.1 document
  • MQTT Applications
  • Facebook Messenger
  • Amazon IoT (Oct 8, 2015): link
  • IECC Scalable
  • Installation
  • Useful Links
  • MQTT Official

openHAB

AWS IoT

  • Reference Link
  • Free Tier: AWS Free Tier includes 250,000 free messages (published or delivered) per month, for 12 months
  • AWS IoT Architecture
  • Device SDK: provides an SDK to help you easily and quickly connect your hardware device or your mobile application
  • Device Gateway: enables devices to securely and efficiently communicate with AWS IoT, exchange messages using a publication/subscription model, which enables one-to-one and one-to-many communications, supports MQTT and HTTP 1.1 protocols, scales automatically to support over a billion devices without provisioning infrastructure
  • Authentication and Authorization: provides mutual authentication and encryption at all points of connection, so that data is never exchanged between devices and AWS IoT without proven identity (supports SigV4, X.509)
  • Registry: establishes an identity for devices and tracks metadata such as the devices’ attributes and capabilities
  • Device Shadows: create a persistent, virtual version, or “shadow,” of each device that includes the device’s latest state so that applications or other devices can read messages and interact with the device
  • Rules Engine: makes it possible to build IoT applications that gather, process, analyze and act on data generated by connected devices at global scale without having to manage any infrastructure, evaluates inbound messages published into AWS IoT and transforms and delivers them to another device or a cloud service, can also route messages to AWS endpoints including AWS Lambda, Amazon Kinesis, Amazon S3, Amazon Machine Learning, and Amazon DynamoDB. External endpoints can be reached using AWS Lambda, Amazon Kinesis, and Amazon Simple Notification Service (SNS), author rules within the management console or write rules using a SQL-like syntax, provides dozens of available functions that can be used to transform your data link
  • [http://docs.aws.amazon.com/iot/latest/developerguide/iot-rules.html#aws-iot-create-rule] AWS IoT How it works
  • Security and Identity of AWS IoT: link AWS IoT Security and Identity
  • Create an IAM role (AWS CLI)
$ aws iam create-role --role-name my-iot-role --assume-role-policy-document file://my-iot-role-trust-policy-document.json
  • trust policy document:
{
    "Version":"2012-10-17",
    "Statement":[{
        "Effect": "Allow",
        "Principal": {
            "Service": "iot.amazonaws.com"
        },
        "Action": "sts:AssumeRole"
    }]
}
  • Command output: includes ARN (Amazon Resource Name)
{
  "Role": {
      "AssumeRolePolicyDocument": "url-encoded-json",
      "RoleId": "AKIAIOSFODNN7EXAMPLE",
      "CreateDate": "2015-09-30T18:43:32.821Z",
      "RoleName": "my-iot-role",
      "Path": "/",
      "Arn": "arn:aws:iam::123456789012:role/my-iot-role"
  }
}
  • grant AWS IoT access to your AWS resources
$ aws iam create-policy --policy-name my-iot-policy --policy-document file://my-iot-policy-document.json
  • e.g. grants AWS IoT admin access to DynamoDB:
{
    "Version": "2012-10-17",
    "Statement": [{
        "Effect": "Allow",
        "Action": "dynamodb:*",
        "Resource": "*"
    }]
}
  • command response:
{
    "Policy": {
        "PolicyName": "my-iot-policy",
        "CreateDate": "2015-09-30T19:31:18.620Z",
        "AttachmentCount": 0,
        "IsAttachable": true,
        "PolicyId": "ZXR6A36LTYANPAI7NJ5UV",
        "DefaultVersionId": "v1",
        "Path": "/",
        "Arn": "arn:aws:iam::123456789012:policy/my-iot-policy",
        "UpdateDate": "2015-09-30T19:31:18.620Z"
    }
}
  • attach the policy to my role:
$ aws iam attach-role-policy --role-name my-iot-role --policy-arn "arn:aws:iam::123456789012:policy/my-iot-policy"
Rule name: name of the rule
Optional description: purpose of the rule
SQL statement: simplified SQL syntax to filter messages on MQTT topic and push the data to elsewhere
One or more actions: the actions AWS IoT takes when executing the rule
  • AWS CLI rule creation:
$ aws iot create-topic-rule --rule-name my-rule --topic-rule-payload file://my-rule.json
{
  "sql": "SELECT * FROM 'iot/test'",
  "ruleDisabled": false,
  "actions": [{
      "dynamoDB": {
          "tableName": "my-dynamodb-table",
          "roleArn": "arn:aws:iam::123456789012:role/my-iot-role",
          "hashKeyField": "topic",
          "hashKeyValue": "${topic(3)}",
          "rangeKeyField": "timestamp",
          "rangeKeyValue": "${timestamp()}"
      }
  }]
}
{
  "sql": "expression",
  "ruleDisabled": false,
  "actions": [{
      "lambda": {
          "functionArn": "arn:aws:lambda:us-west-2:123456789012:function:my-lambda-function"
      }
  }]
}
{
  "sql": "expression",
  "ruleDisabled": false,
  "actions": [{
      "sns": {
          "targetArn": "arn:aws:sns:us-west-2:123456789012:my-sns-topic",
          "roleArn": "arn:aws:iam::123456789012:role/my-iot-role"
      }
  }]
}
{
  "sql": "expression",
  "ruleDisabled": false,
  "actions": [{
      "republish": {
          "topic": "my-mqtt-topic",
          "roleArn": "arn:aws:iam::123456789012:role/my-iot-role"
      }
  }]
}
  • list rules:
$ aws iot list-topic-rules
$ aws iot get-topic-rule --rule-name my-rule
  • deleting a rule (AWS CLI):
$ aws iot delete-topic-rule --rule-name my-rule

About AWS IoT (media reference link)