gpt4 book ai didi

php - 通过rabbitmq(amqp协议(protocol))从云端向设备物联网中心发送消息时遇到问题

转载 作者:行者123 更新时间:2023-12-03 04:13:37 24 4
gpt4 key购买 nike

我想使用 amqp 协议(protocol)将消息从云发送到设备物联网中心,为此我使用rabbitmq消息代理和 reference在 PHP 中。我在本地主机上尝试了以下代码:

//send.php
<?php
require_once __DIR__ . '/vendor/autoload.php';
use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;

$connection = new AMQPStreamConnection('HUBNAME.azure-devices.net', 5671
, 'HUBNAME.azure-devices.net/DEVICENAME/?api-version=2018-06-30'
, 'SharedAccessSignature sr=HUBNAME.azure-devices.net
&sig=XXXX&se=XXXX&skn=iothubowner');

$channel = $connection->channel();
$channel->queue_declare('hello', false, false, false, false);
$json = '{"id":123, "value":"xyz"}';
$msg = new AMQPMessage($json);
$channel->basic_publish($msg, '', 'hello');
echo " [x] Sent 'Hello World!'\n";
$channel->close();
$connection->close();

当我运行这个 send.php 文件时,我收到错误:

fatal error: Uncaught PhpAmqpLib\Exception\AMQPConnectionClosedException: Broken pipe or closed connection in C:\xampp\htdocs\amqp\vendor\php-amqplib\php-amqplib\PhpAmqpLib\Wire\IO\StreamIO.php:222

请帮帮我。

最佳答案

您无法使用rabbitmq从IotHub发送云到设备消息。

”您可以通过面向服务的端点(/messages/devicebound)发送云到设备的消息。然后,设备通过设备特定的端点(/devices/{deviceId}/messages/devicebound)接收消息。

为了将每条云到设备消息定位到单个设备,IoT 中心将 to 属性设置为 /devices/{deviceId}/messages/devicebound。”

了解更多 here .

您可以\应该利用 Azure IoT 中心服务 SDK - 请参阅 here .

关于php - 通过rabbitmq(amqp协议(protocol))从云端向设备物联网中心发送消息时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54997937/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com