GithubHelp home page GithubHelp logo

aws's Introduction

AWS

AWS IoT

AWS IoT SDK for Java: http://docs.aws.amazon.com/iot/latest/developerguide/iot-sdks.html#iot-java-sdk

AWS IoT SDK for Java on GitHub: https://github.com/aws/aws-iot-device-sdk-java

Install the SDK

Install the SDK Using Maven

<dependencies>
    <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-iot-device-sdk-java</artifactId>
        <version>1.1.1</version>
    </dependency>
</dependencies>

Publisher/Subscriber Example

  1. Login on AWS console and click on AWS IoT service.

  2. Register a device / thing.

+INFO: http://docs.aws.amazon.com/iot/latest/developerguide/register-device.html

  1. Create and Activate a Device Certificate.

+INFO: http://docs.aws.amazon.com/iot/latest/developerguide/create-device-certificate.html

¡¡¡IMPORTANT!!!: Choose Download for the certificate, private key, and the root CA for AWS IoT. Save each of them to your computer.

  1. Create and Attach a policy.

+INFO: http://docs.aws.amazon.com/iot/latest/developerguide/create-iot-policy.html

After the policy has been created, click on it and check Policy Document:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": "iot:Connect",
      "Resource": "*"
    },
    {
      "Effect": "Allow",
      "Action": "iot:Subscribe",
      "Resource": "*"
    },
    {
      "Effect": "Allow",
      "Action": "iot:Publish",
      "Resource": "arn:aws:iot:<your-region>:<your-endpoint>:topic/MyIoTButtonTopìc"
    }
  ]
}
  1. Attach a Certificate to a Thing

+INFO: http://docs.aws.amazon.com/iot/latest/developerguide/attach-cert-thing.html

  1. Create a rule and add an action, e.g. SNS email.

+INFO: http://docs.aws.amazon.com/iot/latest/developerguide/config-and-test-rules.html

  1. Create config-publisher.properties file.

    7.1 Fill in resources/config.properties template.

    7.2 Save it as config-publisher.properties.

  2. Run the Publisher:

    mvn exec:java -Dexec.mainClass="aws.iot.publisher" -Dexec.args="config-publisher.properties"

Your output should be similar:

...
Cert file:<your-certf-file> Private key: <your-key-file>
nov 24, 2017 12:24:16 PM com.amazonaws.services.iot.client.core.AwsIotConnection onConnectionSuccess
INFORMACIÓN: Connection successfully established
nov 24, 2017 12:24:16 PM com.amazonaws.services.iot.client.core.AbstractAwsIotClient onConnectionSuccess
INFORMACIÓN: Client connection active: <your-client-id>
nov 24, 2017 12:24:16 PM com.amazonaws.services.iot.client.core.AwsIotConnection onConnectionClosed
INFORMACIÓN: Connection permanently closed
nov 24, 2017 12:24:16 PM com.amazonaws.services.iot.client.core.AbstractAwsIotClient onConnectionClosed
INFORMACIÓN: Client connection closed: <your cliend-id>
...

Check your email.

  1. Create config-subscriber.properties file.

    9.1 Fill in resources/config.properties template. Make sure that the clientId is different from the previous one.

    9.2 Save it as config-subscriber.properties.

  2. Run the Subscriber:

    mvn exec:java -Dexec.mainClass="aws.iot.subscriber" -Dexec.args="config-subscriber.properties"

Your output should be similar:

...
Cert file:<your-certf-file> Private key: <your-key-file>
nov 24, 2017 12:26:52 PM com.amazonaws.services.iot.client.core.AwsIotConnection onConnectionSuccess
INFORMACIÓN: Connection successfully established
nov 24, 2017 12:26:52 PM com.amazonaws.services.iot.client.core.AbstractAwsIotClient onConnectionSuccess
INFORMACIÓN: Client connection active: <your-client-id>
New message: {
    "deviceid" : "iot123",
        "temp" : 54.98,
        "humidity" : 32.43,
    "coords" : {
        "latitude" : 47.615694,
        "longitude" : -122.3359976
    }
}
...

aws's People

Contributors

dwarfcu avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.