Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法在Azure IoT hub Java上创建模拟设备应用程序_Java_Azure - Fatal编程技术网

无法在Azure IoT hub Java上创建模拟设备应用程序

无法在Azure IoT hub Java上创建模拟设备应用程序,java,azure,Java,Azure,我是Azure物联网中心的新手。我正在使用Java进行开发,作为第一步,我将遵循本教程。 我能够创建一个设备标识,我从云模块接收的消息也可以正常执行。但当我尝试执行设备模拟模块时,我得到: 错误:错误{condition=amqp:connection:framing Error,description='org.apache.qpid.proton.engine.TransportException:connection aborted',info=null} 错误:org.apache.qp

我是Azure物联网中心的新手。我正在使用Java进行开发,作为第一步,我将遵循本教程。 我能够创建一个设备标识,我从云模块接收的消息也可以正常执行。但当我尝试执行设备模拟模块时,我得到:

错误:错误{condition=amqp:connection:framing Error,description='org.apache.qpid.proton.engine.TransportException:connection aborted',info=null}

错误:org.apache.qpid.proton.engine.TransportException:连接中止

我认为这与AMQPS配置有关,但不确定这里可能会出什么问题

有人遇到过这样的问题吗?

@UmerF92, 谢谢你的耐心。 请在您的环境中尝试下面的代码好吗?该示例遵循教程()的要求,在我这方面效果很好

private static String connString = "HostName=<your hub>.azure-devices.net;"
            + "DeviceId=< your device >;"
            + "SharedAccessKey=<your share key >";
    private static IotHubClientProtocol protocol = IotHubClientProtocol.AMQPS;//or HTTPS
    private static boolean stopThread = false;


private static String DEVICEID="<your device id>";

private static class TelemetryDataPoint {
    public String deviceId;
    public double windSpeed;

    public String serialize() {
        Gson gson = new Gson();
        return gson.toJson(this);
    }
}

protected static class EventCallback implements IotHubEventCallback {
    public void execute(IotHubStatusCode statusCode, Object context) {
        System.out.println("IoT Hub responded to message with status " + statusCode.name());

        if (context != null) {
            synchronized (context) {
                context.notify();
            }
        }
    }
}

private static class MessageSender implements Runnable {
    public volatile boolean stopThread = false;

    public void run() {
        try {
            double avgWindSpeed = 10;
            Random rand = new Random();
            DeviceClient client;

            client = new DeviceClient(connString, protocol);
            client.open();

            while (!stopThread) {
                double currentWindSpeed = avgWindSpeed + rand.nextDouble() * 4 - 2;
                TelemetryDataPoint telemetryDataPoint = new TelemetryDataPoint();

                telemetryDataPoint.deviceId = DEVICEID;
                telemetryDataPoint.windSpeed = currentWindSpeed;

                String msgStr = telemetryDataPoint.serialize();
                Message msg = new Message(msgStr);

                System.out.println(msgStr);

                Object lockobj = new Object();
                EventCallback callback = new EventCallback();

                client.sendEventAsync(msg, callback, lockobj);

                synchronized (lockobj) {
                    lockobj.wait();
                }

                Thread.sleep(1000);
            }
            client.close();
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }
}

public static void main(String[] args) throws IOException, URISyntaxException, InterruptedException {
    MessageSender messageSender = new MessageSender();
    Thread t0 = new Thread(messageSender);

    t0.start();

    System.out.println("Press ENTER to exit...");
    System.in.read();
    messageSender.stopThread = true;
    t0.join();
} 
private static String connString=“HostName=.azure devices.net;”
+“设备ID=;”
+“SharedAccessKey=”;
专用静态IoTubClientProtocol=IoTubClientProtocol.AMQPS//或HTTPS
私有静态布尔stopThread=false;
私有静态字符串DEVICEID=“”;
专用静态类遥测数据点{
公共字符串设备ID;
公众双风速;
公共字符串序列化(){
Gson Gson=新的Gson();
返回gson.toJson(this);
}
}
受保护的静态类EventCallback实现IoTubEventCallback{
public void execute(IoTubStatusCode状态码,对象上下文){
System.out.println(“IoT Hub以状态“+statusCode.name()”响应消息);
if(上下文!=null){
已同步(上下文){
context.notify();
}
}
}
}
私有静态类MessageSender实现Runnable{
public volatile boolean stopThread=false;
公开募捐{
试一试{
双平均速度=10;
Random rand=新的Random();
设备客户端;
客户端=新设备客户端(连接字符串、协议);
client.open();
而(!stopThread){
双电流风速=avgWindSpeed+rand.nextDouble()*4-2;
遥测数据点遥测数据点=新遥测数据点();
telemetryDataPoint.deviceId=设备ID;
遥测数据点.windSpeed=当前风速;
字符串msgStr=telemetryDataPoint.serialize();
消息消息=新消息(msgStr);
系统输出打印LN(msgStr);
Object lockobj=新对象();
EventCallback callback=新的EventCallback();
sendEventAsync(消息、回调、lockobj);
已同步(lockobj){
lockobj.wait();
}
睡眠(1000);
}
client.close();
}
捕获(例外e){
e、 printStackTrace();
}
}
}
publicstaticvoidmain(字符串[]args)抛出IOException、URISyntaxException、InterruptedException{
MessageSender MessageSender=新建MessageSender();
线程t0=新线程(messageSender);
t0.start();
System.out.println(“按回车键退出…”);
System.in.read();
messageSender.stopThread=true;
t0.join();
} 
请试一试


任何更新或问题,请告诉我。

我复制了该问题并收集了更多错误信息。我正试图让熟悉这个话题的人来进一步研究这个问题。可能会有一些时间延迟。谢谢你的耐心。嘿,谢谢你,彼得。如果问题得到解决,那么等待是值得的。