项目作者: snobu

项目描述 :
Talk raw MQTT to Azure IoT Hub without Device SDK
高级语言: Python
项目地址: git://github.com/snobu/raw-mqtt-to-azure-iot-hub.git
创建时间: 2019-09-05T05:55:51Z
项目社区:https://github.com/snobu/raw-mqtt-to-azure-iot-hub

开源协议:MIT License

下载


Raw MQTT to Azure IoT Hub (in Python) without device SDK

MQTT logotype

A simulated device that implements cloud-to-device and device-to-cloud messaging as well as direct methods over MQTT without using the Azure IoT Device SDK.

This project is using Paho to talk MQTT to Azure IoT Hub.

WARNING

EVERYTHING HERE IS HIGHLY EXPERIMENTAL.

Generate the SAS token with azure-cli

First, install the Azure IoT extension: https://github.com/azure/azure-iot-cli-extension#installation

Then generate the SAS key:

  1. az iot hub generate-sas-token \
  2. --hub-name YOUR_IOT_HUB_NAME \
  3. --device-id YOUR_DEVICE_ID \
  4. --key-type primary \
  5. --duration 3600 \
  6. --output tsv

Place the SAS key into a file named sas.token.

You’ll most probably want a virtual environment first -
https://docs.python.org/3/library/venv.html

Target Python 3.6+.

Run the thing (activate the venv first if using one):

  1. $ python run.py

Send cloud to device message

  1. az iot device c2d-message send \
  2. --hub-name poorlyfundedskynet \
  3. --device-id yolo --data \
  4. '{"hey device": "this is a cloud to device message"}'

Invoke direct method

  1. az iot hub invoke-device-method \
  2. --hub-name poorlyfundedskynet \
  3. --device-id yolo \
  4. --method-name hey \
  5. --method-payload '{"hey device": "this is a direct method invocation"}'

KNOWN ISSUES

Hey, Python is caveman simple, you should rewrite this in C, the language real people use for IoT.