mozilla / connected-devices-experiments

INACTIVE - http://mzl.la/ghe-archive - A place to publish experiments and investigations from the Connected Devices team
10 stars 6 forks source link

AWS IoT #22

Closed mikehenrty closed 2 months ago

mikehenrty commented 8 years ago

Let's create an experiment with Amazon's IoT Service.

https://aws.amazon.com/iot/

mikehenrty commented 8 years ago

@sfoster should we close this issue in favor of #6? and just rename that one to something like "Smart Mirror with AWS-IoT?"

sfoster commented 8 years ago

No I think I'll probably make use of the smart mirror as the platform to build on but will treat it as its own distinct investigation/experiment

sfoster commented 8 years ago

So 2nd thoughts, my plan here is to make an "IoT Useless Box". I'll have a toggle switch, which when toggled on fires a message up to AWS, where it should be processed by a rule that generates another message which causes the servo to turn the switch off again.

This should exercise the MQTT publish/subscribe via AWS, the filtering and rules engine and a little hardware thrown in.

sfoster commented 8 years ago

New repo for this experiment at: https://github.com/sfoster/mqtt-useless-box I also posted a short WIP video: https://www.youtube.com/watch?v=4F5_a7Dry58

sfoster commented 8 years ago

I've just spent a couple of hours trying and failing to connect/subscribe/publish to the MQTT service I've set up on AWS' IoT service. I'm not an old hand at AWS or cloud services/platforms in general and this might be trivial for someone who does more of this kind of thing, but I can read docs like the best of them and .. it's not working for me yet.

I've worked my way through the setup guide and the "secure communication" section. I've got the CLI installed, I've created my policy, my certificates, my test device. The console shows these resources and AFAICT they are correctly attached and linked together. I've installed the MQTT.fx application and fed it the correct hostname and these certs and key files, I click connect and it fails with a MQTTException that doesnt give any more detail in the stacktrace beyond the attempt to connect with the given details didn't work out.

I can probably work through this - and I'll keep trying. But this does reinforce what I have read elsewhere (e.g. "thingpin" project that abstracts AWS and Adafruit's MQTT services) that AWS IoT is a slightly complicated and awkward thing to get started with.

sfoster commented 8 years ago

In lieu of a successful experiment, in the meantime I'll describe the AWS IoT offering: The IoT service is closely integrated with the other AWS services, using their IAM identity/auth solution, and extending the CLI tool to create and manage IoT devices, certificates etc.

The service is built around the notion of "things" or devices, and device shadows. The shadows represent the last-known-state for a given thing, and so enable intermittent connectivity or periodic state or data updates from a sensor or other connected thing, while presenting real-time responses for any consumer of this data. There is a REST API and MQTT for pushing and pulling data. The MQTT protocol seems to be quite widely adopted for IoT use cases - it is relatively lightweight, with clients available for embedded C, python, javascript (node.js) etc. It appears AWS is building their broker on the Mosquitto broker, as they indicate the same WebSockets support.

Filtering and a rules engine are built into the IoT service, so you can define actions to take when a state or message of a matching value is received. Actions include relaying messages to other devices, logging, making API calls to other services etc.

In practice, you use the CLI or AWS console to define devices and attach certificates and access policies to them. Each device gets its own endpoint. An SDK is offered with basic client implementations in Javascript (node.js) and C for setting up MQTT publishers and subscribers using the AWS IoT service. At this time there's no python support in the SDK, but it appears to be fairly straighforward to accomplish.