简体   繁体   English

将消息从Android移动应用发送到Azure IoT中心

[英]Send message from Android mobile app to Azure IoT Hub

For an IoT project, we need to send messages from mobile application (iOS and Android) to Azure IoT Hub. 对于IoT项目,我们需要将消息从移动应用程序(iOS和Android)发送到Azure IoT中心。 We were able to do it connecting as a device using MQTT library. 我们能够使用MQTT库将其作为设备连接。 However, the device simulator too connect as a device and since both uses same device ID, the existing connection is dropped when both connect to IoT Hub at the same time. 但是,设备模拟器也作为设备连接,并且由于两者都使用相同的设备ID,因此当两者同时连接到IoT中心时,现有连接将被丢弃。

We realized we need to connect mobile apps as a service (not as a device) and for that some research shows we need to use following library. 我们意识到我们需要将移动应用程序作为服务(而不是作为设备)进行连接,为此,一些研究表明我们需要使用以下库。

https://github.com/Azure/azure-iot-sdk-java https://github.com/Azure/azure-iot-sdk-java

https://github.com/Azure/azure-iot-sdk-java/blob/master/service/iot-service-samples/service-client-sample/src/main/java/samples/com/microsoft/azure/sdk/iot/ServiceClientSample.java https://github.com/Azure/azure-iot-sdk-java/blob/master/service/iot-service-samples/service-client-sample/src/main/java/samples/com/microsoft/azure/ SDK / IOT / ServiceClientSample.java

However, this java sample uses lot of java specific implementations and which are not supported by Android. 但是,此Java示例使用了许多Java特定的实现,而Android不支持这些实现。

Has anyone faced the same problem? 有没有人遇到过同样的问题?

  1. Which library can we use to achieve above from Android mobile application? 我们可以使用哪个库通过Android移动应用程序实现以上目标?
  2. Which library can we use to achieve above from iOS mobile application? 我们可以使用哪个库通过iOS移动应用程序实现以上目标?

Please let me know if any alternate solution is available. 请让我知道是否有其他替代解决方案。

You can use a REST API for sending a D2C message to the Azure IoT Hub. 您可以使用REST API将D2C消息发送到Azure IoT中心。 The following screen snippet shows an example of this call. 以下屏幕片段显示了此调用的示例。 Note, that no library is required for this request. 请注意,此请求不需要任何库。

发送D2C消息

  • another solution for your scenario is to use an Azure Function as a pre-processor to the Azure IoT Hub, see the following example: 针对您的方案的另一种解决方案是将Azure功能用作Azure IoT中心的预处理器,请参见以下示例:

AzureFunction

Thanks Roman 谢谢罗曼

Just as additional content about another solution for your scenario. 就像有关您方案的其他解决方案的其他内容一样。 Based on my understanding and per my experience, I think you can try to create an App service, such as Mobile App for using Custom API at the side of client & backend , or WebApps, etc, to receive the payload which includes custom json properties from your Android App, and forward the payload message using Azure IoTHub SDK for NodeJS or Java to IoTHub. 根据我的理解和经验,我认为您可以尝试创建一个应用程序服务,例如用于在客户端后端使用自定义API的移动应用程序或WebApps等,以接收包含自定义json属性的有效负载从您的Android应用程序中,然后使用适用于NodeJS或Java的Azure IoTHub SDK将有效负载消息转发到IoTHub。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM