Azure / azure-iot-cli-extension

Azure IoT extension for Azure CLI
Other
82 stars 64 forks source link

[bug] az iot device send-d2c-message doesn't allow for different data formats, only utf-8 #647

Closed cbellee closed 1 year ago

cbellee commented 1 year ago

az iot device send-d2c-message -n {iothub_name} -d {device_id} --data doesn't allow for different data formats to be used, only utf-8.

Description

Steps to reproduce the behavior: $ az iot device send-d2c-message -n {iothub_name} -d {device_id} --data

Expected behavior An additional parameter for the command would allow the user to specify a data format type, such as --data-type {utf8 | binary | json}

Environment

azure-cli 2.46.0 core 2.46.0 telemetry 1.0.8

Extensions: aks-preview 0.5.132 azure-devops 0.26.0 azure-firewall 0.14.5 azure-iot 0.21.0 containerapp private-preview-1.0.5 front-door 1.0.17 k8s-configuration 1.7.0 k8s-extension 1.4.0 load 0.2.0 ml 2.14.1 ssh 1.1.5 storage-preview 0.8.3 virtual-wan 0.2.16 webpubsub 1.2.0

Dependencies: msal 1.20.0 azure-mgmt-resource 21.1.0b1

Python location '/opt/az/bin/python3' Extensions directory '/home/cbellee/.azure/cliextensions'

Python (Linux) 3.10.10 (main, Mar 6 2023, 09:39:55) [GCC 9.4.0]

Elsie4ever commented 1 year ago

Hi @cbellee, my coworker followed up on this issue by replied your email, we are wondering can you try set up the content type and content encoding using this flag below and see now if the routing applies correctly? (the help text show up when you do az iot device send-d2c-message)

--properties --props -p : Message property bag in key-value pairs with the following format: a=b;c=d. For mqtt messaging - you are able to send system properties using $.<name>=value. For instance $.cid=12345 sets the system correlation Id property. Other system property identifier examples include $.ct for content type, $.mid for message Id and $.ce for content encoding.

For your case you can do for example: az iot device send-d2c-message -n <hubname> -p "$.ct=application/json;$.ce=utf-8" -d <deviceid> --data <json content>

Also I have some questions:

  1. In what scenario do you need to send data in binary, and can I get an example so we can understand how we can assist further?
  2. Are you trying to send message that in pure binary or encode it into string and sent it out?

Thanks a lot!

digimaun commented 1 year ago

On top of the prior relayed information, we have a recent release v0.20.2 that improves binary support with the addition of a --data-file-path parameter.

For example:

az iot device send-d2c-message -n {iothub_name} -d {device_id} --props '$.ct=application/octet-stream' --data-file-path {file_path}

Let us know if you have any further feedback or questions.