I want to send Messages with MQTT-Client to IoT Hub - SAS token is not accepted

UK 21 Reputation points
2022-02-01T08:57:22.193+00:00

Hello,

I use the C-example of https://github.com/Azure-Samples/IoTMQTTSample to send messages to my IoT Hub.

When I try to get the required SAS-Token with command:

az iot hub generate-sas-token -d <DeviceId> -n <MyIoTHub>

I get error:

'generate-sas-token' is misspelled or not recognized by the system.

When I use the SAS-Token from IoT Explorer in my sample program, I get the following error:

Connection Refused, please check your SAS Token, expired ?

Where can I get a working example (C-Code) using mosquitto to send messages to IoT Hub?

Uwe

=====================

Edit:

When I change the API from api-version=2018-06-30 to api-version=2020-09-30 I get another error:

Connect Callback returned : 3=Connection Refused, Server unavailable

Azure IoT Hub
Azure IoT Hub
An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.
1,272 questions
0 comments No comments
{count} votes

Accepted answer
  1. AshokPeddakotla-MSFT 35,971 Reputation points Moderator
    2022-02-02T07:59:54.01+00:00

    @UK Welcome to Microsoft Q&A forum!

    When I try to get the required SAS-Token with command:
    az iot hub generate-sas-token -d <DeviceId> -n <MyIoTHub>

    I get error:
    'generate-sas-token' is misspelled or not recognized by the system.

    You get these type of errors when Microsoft Azure IoT extension for Azure CLI is not added to the Azure CLI.

    What is the CLI version you are using and can you confirm if you have added the Microsoft Azure IoT extension for Azure CLI?

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.