GithubHelp home page GithubHelp logo

andrei-markeev / azureiothubmqttclient Goto Github PK

View Code? Open in Web Editor NEW

This project forked from andriyadi/azureiothubmqttclient

1.0 3.0 0.0 54 KB

Azure IoT Hub client for ESP8266 using MQTT

CMake 1.97% C++ 93.65% C 4.37%

azureiothubmqttclient's Introduction

AzureIoTHubMQTTClient

It's unofficial Azure IoT Hub client library for ESP8266. The main class AzureIoTHubMQTTClient extends PubSubClient class in order to access Azure IoT Hub using MQTT protocol.

PubSubClient I use is the one that's optimized for ESP8266, and I included all classes into this project to ease the pain, hope it's OK. I also use NTPClientLib to get current timestamp from NTP server, and use the timestamp to determine the SAS token expiration time. All needed classes are also included in this repo.

I try to write the client library to be as familiar as possible. I name the method sendEvent instead of publish, so it's similar as another Azure IoT Hub client library. If you're familiar with MQTT, you know you should use topic in order to publish payload to MQTT broker. But since the MQTT topic used to publish message to Azure IoT Hub cannot be arbitrary, library sets it for you.

Why?

You know how hard/cryptic Azure IoT Hub client library for Arduino (and ESP8266) is, right? Well, at least to me. It's written in C (remember the song?).

Hey, Azure IoT Hub already supports MQTT protocol since the GA, doesn't it? Why don't we just access it using MQTT? Yes, you can, go ahead and deal with that SAS token :)

I took a liberty to write an easy to use class AzureIoTHubMQTTClient, all you need to provide are:

  • Azure IoT Hub name --> the name you use to create the IoT Hub
  • Device ID --> the ID you use to register a device, either via DeviceExplorer or iothub-explorer
  • Device Key --> the primary key that you can get using DeviceExplorer app or using iothub-explorer get "[device_id]" --connection-string

Get started

First thing first, you should have already set up an Azure IoT Hub and add a device. To create your Microsoft Azure IoT Hub and add a device, follow the instructions outlined in the Setup IoT Hub Microsoft Azure Iot SDK page. Then, download this library and add to your Arduino IDE like usual.

To get started, just take a look the example TempToIoTHub.ino sketch. Change the followings:

  • [YOUR_SSID_NAME] and [YOUR_SSID_PASS] to connect to WiFi
  • [YOUR_IOTHUB_NAME]
  • [YOUR_DEVICE_ID]
  • [YOUR_DEVICE_KEY]

Upload the sketch to your ESP8266 board. I'll recommend to use the ESP8266-based dev board designed by my team: ESPectro, it will make your maker life easier :P

And after that, (hopefully) you're good to go. Hey, would be great if you can connect a temperature sensor as the sketch is about reading temperature data and publish it to Azure IoT Hub. I use BMP180 and Adafruit's BMP085/BMP180 library. You can change #define USE_BMP180 from 1 to 0 if you don't have the sensor and let the random on your side.

Or... get a PlatformIO-based sample project from here

Enjoy!

Credits

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.