0

I'm currently developing a dashboard in Unity 3d. I want to connect my Unity app to Azure IoT Hub to receive the data of my sensors:

Sensors + Rapsberry Pi => IoT Hub => Unity App

Azure provides an IoT Hub sdk for python developers : useful for the sensor part. But Azure also provides an IoT Hub sdk for c# developers. It would be nice to use this sdk for unity 3d. Indeed, the scripts in Unity are written in c# through Visual studio. The issue is I don't really understand how to install this SDK on my unity project?

I saw a post about using Universal Window Platform module for Unity to perform the iot hub sdk. But how to install this UWP, and how to install this iot hub sdk?

Thanks for answering!

Anthony
  • 71
  • 1
  • 10

2 Answers2

0

If I understood well, in your scenario you are ingesting the data from RPI and sensors to IoT Hub and showing potentially some information in your unity app, correct?

Sensors + Raspberry Pi => IoT Hub => Unity App

If this is the case, you should store the ingested data somewhere, implement some kind of an API that would serve your unity app with previously ingested data.

Sensors + Raspberry Pi => IoT Hub => Storage => Api => Unity App

Not sure what is the business case, but you also might be looking for something like:

Sensors + Raspberry Pi => IoT Hub => Publish to Service Bus Topic => Unity App(subscribe)

I would not recommend using IoT SDK in your unity SDK, as in this case the Unity app is only 'subscriber'. From the security perspective, that approach does not reflect the best practice, as you would have to add permissions for accessing the service endpoint to the client(via shared access keys), and this might be a security risk.

kgalic
  • 2,441
  • 1
  • 9
  • 21
  • Hi! Thanks for answering, in this case I will need an other SDK (different from IoT HuB Sdk) to subscribe to Azure? I look for the API but it's not so easy from Unity point of view. – Anthony Apr 15 '19 at 10:57
  • Hello. Assuming that you might be looking for something like this Sensors + Raspberry Pi => IoT Hub => Publish to Service Bus Topic => Unity App(subscribe) maybe try the following tutorials: 1. Configure message routing from IoT Hub to Service Bus Topic: https://learn.microsoft.com/en-us/azure/iot-hub/tutorial-routing 2. Check how to receive a message from Service Bus Topic: https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-dotnet-how-to-use-topics-subscriptions Try if you can get Microsoft.Azure.ServiceBus NuGet package working in your Unity project. – kgalic Apr 15 '19 at 12:31
  • Again, not sure what exactly is the requirement here in the details, but please check those links and see if they work well for your case. – kgalic Apr 15 '19 at 12:32
  • The purpose is to send data in real time to Unity. – Anthony Apr 17 '19 at 14:51
  • Have you checked a link with service bus topic and see if that is something it might help you? – kgalic Apr 17 '19 at 14:53
  • This is also an option, that I would consider as well: IoT Hub-> Azure Function-> SignalR -> Unity – kgalic Apr 17 '19 at 15:44
  • https://learn.microsoft.com/en-us/azure/azure-signalr/signalr-concept-azure-functions – kgalic Apr 17 '19 at 15:45
  • Soory my last message wasn't entirely printed : The purpose is to send data in real time to Unity. I got a bench of sensors connected to my raspberry pi. Thanks to the Azure IoT Hub in Python, I can push them on IoT Hub to the end point "Send device to cloud". I was hopping to use the Csharp SDK in Unity to reach the end point "receive device to cloud message", but I have some issues to install the SDK, issues about the framework net 2.0 I think. I get the same issues installing other SDK of Microsoft like Service Bus. – Anthony Apr 18 '19 at 06:30
  • 1
    The best way will be the SDK, I'm thinking to reach this endpoint without the SDK thanks HTTP request. But HTTP request are not going to do the job as well as the sdk. I'm going to try different version of Unity and take a look on SignalR – Anthony Apr 18 '19 at 06:32
  • Ok, please let me know what are the results with SignalR. – kgalic Apr 18 '19 at 13:39
0

I found it’ll save you the frustration of continuously asking questions on solutions such as this which Microsoft is yet of officially support. I’m not sure they plan to though as usually when a (c# compatible)SDK comes out with evident uses in unity, Microsoft usually give support where possible. From @kgalic, I came up with a solution that works although cumbersome

it’s device(Json telemetry) => IOT-Hub => ServiceBusQueue=> (ServicebusTrigger)AzureFunction(decompose json into class) => storage(eg. Device Class data stored Table).

Then to request the telemetry(you choose the frequency of request) Unity App(http GET/POST) => (HTTP trigger)AzureFunction(pulls data from storage and returns Json) => UnityApp(decomposes Json into class and visualizes)

When you want to send a command/message to the device UnityApp(http Get/POST) => AzureFunction(you can actually import and call SDK here) => UnityApp(Receive Acknowledgement).

The main point is that Unity can communicate with Azure Functions over HTTP, and Azure Functions can use the device SDK.

My final year project implements this. I’ll probably upload the files on GitHub later.

Bolu Morawo
  • 189
  • 1
  • 1
  • 6