Giter Club home page Giter Club logo

esp-azure's Introduction

a MQTT Demo that Connect ESP32 to Azure Cloud

Table of Contents

Introduction

ESP32 is one of gorgeous ioT device that can interface with other systems to provide Wi-Fi and Bluetooth functionality through the SPI / SDIO or I2C / UART interfaces.for more details, click https://espressif.com/en/products/hardware/esp32/overview
Azure cloud is one of wonderful cloud that could collect data from lot device or push data to lot device,for more details, click https://www.azure.cn/home/features/iot-hub/

Aim:

This page would guide you connecting your device(ESP32 or lot device with ESP32) to Azure by MQTT protocol, and then send data to Azure,receive message from Azure.Main workflow:

ESP32workflowhttps://github.com/ustccw/RepoForShareData/blob/master/Microsoft/AzureData/Photos/ESP32AzureWorkflow.png

Part 1: Prerequisites

Part 2: Prepare your iothub

follow the guide: https://github.com/ustccw/RepoForShareData/blob/master/Microsoft/AzureData/start_Iothub.docx you would get an iothub login connect string like that:

HostName=yourname-ms-lot-hub.azure-devices.cn;SharedAccessKeyName=iothubowner;SharedAccessKey=zMeLQ0JTlZXVcHBVOwRFVmlFtcCz+CtbDpUPBWexbIY=

Part 3: SDK and Tools Preparation

3.1 iothub-explorer install

The iothub-explorer tool enables you to provision, monitor, and delete devices in your IoT hub. It runs on any operating system where Node.js is available.

  • Download and install Node.js from here. https://nodejs.org/en/
  • From a command line (Command Prompt on Windows, or Terminal on Mac OS X), execute the following:
      npm install -g iothub-explorer
    
if success, you can get version information like:
$ node -v
v6.9.5
$ iothub-explorer -V
1.1.6
after finished:

then you can use your iothub-explorer to manager your iot-device.click https://github.com/ustccw/RepoForShareData/blob/master/Microsoft/AzureData/iothub-explorer

login with: iothub login connect string that gets from Part 2

then you can get one device connect string after you create one device like that:

"HostName=esp-hub.azure-devices.net;DeviceId=yourdevice;SharedAccessKey=L7tvFTjFuVTQHtggEtv3rp+tKEJzQLLpDnO0edVGKCg=";

keep this device connect string in mind.

3.2 SDK get

you can get AZURE-SDK from https://github.com/ustccw/AzureESP32
this SDK can implement that connect ESP32 to Azure by MQTT protocol.
you can get IDF-SDK from https://github.com/espressif/esp-idf
this SDK can make ESP32 work well

3.3 Compiler get

follow the guide: http://esp-idf.readthedocs.io/en/latest/get-started/linux-setup.html

Part 4: Configuring and building

4.1 Update Variables

/examples/project_template/user/iothub_client_sample_mqtt.c

Update the connectionString variable to the device-specific connection string you got earlier from the Setup Azure IoT step:

static const char* connectionString = '[azure connection string]'

The azure connection string contains Hostname, DeviceId, and SharedAccessKey in the format:

"HostName=<host_name>;DeviceId=<device_id>;SharedAccessKey=<device_key>"

4.2 config your Wifi

make menuconfig

choose example configuration to set Wifi SSID and Password!

4.3 build your demo and flash to ESP32

$make flash

if failed,try:

  • make sure that ESP32 had connect to PC by serial port
  • make sure you flash to correct serial port
  • try type command:

    sudo usermod -a -G dialout $USER

Part 5: Result shows

login iothub-explorer,and monitor events:

iothub-explorer monitor-events AirConditionDevice_001 --login 'HostName=youriothub-ms-lot-hub.azure-devices.cn;SharedAccessKeyName=iothubowner;SharedAccessKey=zMeLQ0JTlZXVcHBVOwRFVmlFtcCz+CtbDpUPBWexbIY='
  • restart ESP32 after bin had flashed,you would see the ESP32 send data to lothub-explorer by minicom,and iothub-explorer would receive data!
  • At the same time,you can send message to ESP32 by iothub-explorer until you send a quit message

TroubleShoot

esp-azure's People

Contributors

ustccw avatar jetstreamroysprowl avatar wujiangang 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.