Unity (PC/Mac) communication with Non-Unity (Android/iOS) over LAN?
I'm developing a PC/Mac game where you fly a pedal-powered glider around the countryside, controlled by a smart indoor bike trainer. Sort of a modern clone of Namco's arcade game PropCycle. The bike trainer is a Wahoo Kickr Snap and I already have it interacting with an Android app using Wahoo's own Android API, controlling resistance and reporting wattage. The Unity game on the desktop is also working well. My problem is that I just don't know how to get the two applications to communicate with each other over the LAN.
I'm aware that for Unity-to-Unity communication you can use the HLAPI, and that you can define custom communication with the Transport Layer API. But I have no idea if either of these can help me talk to a regular old Android app, and if so how. I'm of intermediate skill and have never done any network programming so I don't really know where to start. But I know that this trainer-app-desktop bridge setup has been done before by Zwift via their Zwift Mobile Link for Android/iOS, I just can't find info on how they did it. I'd only need to communicate a few floats between the app and desktop, roughly once per second. And I assume the app would have to discover the desktop game on the network, or vice versa.
Is there a standard way of doing this unity-to-non-unity connection / communication? Or maybe a plugin / library that can facilitate, either on the Android or Unity side? Those would both be ideal, but if the correct way forward is to educate myself about sockets or something low-level like that I'd just as much appreciate being pointed in the right direction for my research.
PS if anyone is curious as to why I have the bike connected to an Android app and not just an ANT+ dongle on the PC it's because I just don't own one nor do many others, but everyone has a Bluetooth-capable phone, and I can make the app talk to more trainer APIs besides the Wahoo in the future.
Now, I am going to develop the Unity video game using Wahoo Kickr bike and HR.
It seems like you are connected Wahoo Kickr with Unity game.
I hope to know if you can help us.
Looking forward to hearing back from you.
Best regards
Robert
Answer by WazzaM · Aug 14, 2016 at 12:37 AM
Hello, @infinitesunrise your question was posted about 5 months ago so I don't know if you're still looking for an answer but here's a one anyway.
The Unity Networking Low Level API lets you send messages between Unity games/apps running on Android and PC - that is both running some Unity app you build. Not necessarily same app but both built with Unity. Android <-> PC very doable. See Scripting reference for UnityEngine.Networking.NetworkTransport for details. https://docs.unity3d.com/ScriptReference/Networking.NetworkTransport.html
The Unity API documentation is not super great and the API itself gives bad names for things ('AddHost' which should be "CreateSocket") so I've written a wrapper and have a nice demo for it. My wrapper go beyond the the static NetworkTransport class and has classes for LowLevelClient and LowLevelServer that make that easier and there's a nice demo that's a chat client using this library.
Here's a short video of me running it on my PC. (PC EXE file to Unity Editor Run). https://www.youtube.com/watch?v=VTA83d52MY4
I have also tried building the project for Android and it runs great on my mobile - discovering PC server via broadcasting, connecting, sending and disconnecting just the same from Android as on PC.
Hi Wazza$$anonymous$$, do you have any examples of the code you linked in the video?
Answer by SyafiqBahrin · Jan 17 at 03:32 AM
Hi @infinitesunrise , this is a very old post, so I hope that you have solved your problem.
I'm here to ask you you a question instead, for research purpose. I have trouble to get the data from the wahoo kickr into my unity for dekstop game development. Couldn't find the UUID from the wahoo fitness equipment services provided in here https://docplayer.net/42079050-Wahoo-fitness-equipment-profile.html
How did you managed to get it done in Unity for desktop?