Giter Site home page Giter Site logo

mqttaws's Introduction

Simple device control using MQTT

This example demonstrates how to perform remote device control over MQTT protocol. Build & flash a firmware and configure WiFi (see quick start guide), and configure MQTT server:

miot build
miot flash
miot config-set wifi............
miot console

The device automatically assigns MQTT publish and subscribe topics. Use miot config-get mqtt to see the values.

Then use an MQTT client to send messages, for example web-based client at http://www.hivemq.com/demos/websocket-client/. Click on "Connect", then "Add new topic subscription", choose topic set mqtt.sub, then publish a message. In the "Topic" field, specify mqtt.pub topic, and in the "Message" field, one of the following:

  • {"method": "gpio_write", "args": {"pin": 2, "state": 0}} - sets GPIO pin X into state Y
  • {"method": "gpio_read", "args": {"pin": 2}} - read GPIO pin X
  • {"method": "handle_button", "args": {"pin": 0}} - start listening on button presses on GPIO pin X. When button is pressed, a message "click" is sent to the /response topic
  • {"method": "i2c_read", "args": {"addr": 143, "len": 10}} - read data from the I2C bus.
  • {"method": "i2c_write", "args": {"addr": 143, "data": "af404c"}} - write byte stream to the I2C bus. In this example, there are 3 bytes 0xaf 0x40 0x4c. Status code 0 in response means success, all other codes mean failure.

You can attach a string tag to any command, it'll be returned in the response: {"method": "gpio_read", "tag": "foo", "args": {"pin": 2}} -> {"result": "gpio_read", "pin": 2, "state": 1, "tag": "foo"}

Screenshot

By default, this firmware connects to the broker.mqttdashboard.com:1883 MQTT server. You can change this default setting by editing src/conf_schema.yaml file and rebuilding/reflashing the firmware. Alternatively, you can change any setting on the fly, for example to choose a different MQTT server:

miot config-set mqtt.server=my_server:my_port

How to use Amazon IoT with this example

First, download the Amazon's aws utility and run aws configure. Then you're ready to onboard

... build, flash, configure wifi
miot aws-iot-setup --aws-iot-policy YOUR_POLICY
miot console

Login to AWS IoT console, use web-based MQTT client to send messages. See https://mongoose-iot.com/blog/esp8266-remote-control-via-aws-iot/ for the step-by-step instructions.

mqttaws's People

Contributors

cpq avatar

Watchers

James Cloos avatar skyformat99 avatar  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.