Giter Club home page Giter Club logo

m2mqttunity's Introduction

M2MQTT for Unity

This is a simple Unity3d project for using M2MQTT with Unity. The M2MQTT library was modified to run also on UWP/HoloLens.

An example scene is provided with a UI for controlling the connection to the broker and for testing messaging.

Requires Unity 2017.1 or higher.

image

Getting started

To try this project with Unity press the button Clone or download and choose Download ZIP. Save and unzip the archive to your hard disk and then you can open it with Unity. An example scene is provided in M2MqttUnity/Examples/Scenes/M2MqttUnity_Test, with a UI for controlling the connection to a MQTT broker and to test publishing and receiving messages. You can find in the same folder also a scene slightly changed to test the project in VR/AR/MR (M2MqttUnity_TestXR).

Building on different platform and devices

This project was tested with different versions of Unity (2017.1.0, 2017.1.4, 2018.2) with the following platforms:

  • Windows Standalone
  • Android (as simple app and for GearVR)
  • Universal Windows Platform (desktop and HoloLens, using Unity 2017.1.4 or higher).

These setting were used for all the platforms:

  • Other settings:
    • Scripting Define Symbols = SSL
  • Resolution
    • Default is fullscreen = no
    • Run in Background = yes

Specific settings for Android:

  • Set the Package Name
  • for GearVR:
    • check Virtual Reality Supported (or XR for newer versions of Unity)
    • add Oculus in Virtual Reality SDKs
    • set Minimum API Level to 19
    • put your "oculussig..." file(s) in Assets/Plugins/Android/Assets

Specific settings for Universal Windows Platform:

  • build with Unity 2017.1.4 or newer
  • set the Package Name
  • Other settings: set API Compatibility Level to .NET 4.6
  • Publishing settings: check InternetClient in Capabilities
  • Scripting Backend set to .NET (deprecated in 2018.2) or IL2CPP (not for 2017.1)
  • for HoloLens:
    • check Virtual Reality Supported (or XR for newer versions of Unity)
    • add Windows Holographic (Windows Mixed Reality in newer versions) in Virtual Reality SDKs

SSL connection problems found with some combination of Unity versions/platforms.

Contributing

Contributions from you are welcome!

If you find bugs or you have any new idea for improvements and new features you can raise an issue on GitHub (please follow the suggested template, filling the proper sections). To open issues or make pull requests please follow the instructions in CONTRIBUTING.md.

License

Released under the MIT License.

The included (slightly modified) M2MQTT library is licensed under Eclipse Public License 1.0.

m2mqttunity's People

Contributors

cpogolski avatar florianja avatar gpvigano avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

m2mqttunity's Issues

Unable to receive message after reconnection in Unity

Environment

  • version of M2MqttUnity 9a030e5
  • version of Unity3D (e.g. Unity 2020.3.14f1c1)

After disconnecting and reconnecting, the DispatchEventThread method is stuck in this.receiveEventWaitHandle. WaitOne(),
Until the server actively disconnects.

Ui Freeze when broker doesn't respond

  • version of Unity3D 2018.all, 2019.1

Hi, i make mqtt autoconnect true and it works flawless, but if the mqtt broker is down all the ui remain freezed until timeout (put to 30sec). Is there a way to avoid this?

thanks for your great work

Connection Delay not work.

Environment

  • version of M2MqttUnity: 9a030e5
  • version of Unity3D: 2020.3.19f

Expected behavior

We expected connection delay in 10ms. So we code connectionDelay = 10;

Current behavior

But we get approximately 900ms.

Receive: Test message is not displayed and gives the following error

Environment

Windows 10
Unity version 2017.4.3f1
Downloaded the repository on 10/05/2019
Visual Studio Version 2017
HoloLens 1

Steps to reproduce

  1. Build the Unity scene M2MqttUnity_TestXR without any modifications to the code or anything.
  2. Once the build is successful, open the M2MqttUnity.sln from Visual studio 2017
  3. Set settings to Release, x86 and Device
  4. Start Debugging

Expected behavior

To see the following output,

Test message published
Receive: Test message

Current behavior

Following error

Connected to iot.eclipse.org:1883...

(Filename: C:\buildslave\unity\build\artifacts/generated/Metro/runtime/DebugBindings.gen.cpp Line: 51)

Test message published

(Filename: C:\buildslave\unity\build\artifacts/generated/Metro/runtime/DebugBindings.gen.cpp Line: 51)

'M2MqttUnity.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Data\Users\DefaultAccount\AppData\Local\DevelopmentFiles\M2MqttUnityVS.Release_x86.per287\System.Diagnostics.StackTrace.dll'. Cannot find or open the PDB file.
Exception thrown: 'System.InvalidOperationException' in Assembly-CSharp.dll
Exception thrown: 'uPLibrary.Networking.M2Mqtt.Exceptions.MqttCommunicationException' in Assembly-CSharp.dll
Exception thrown: 'System.AggregateException' in System.Private.CoreLib.ni.dll
The thread 0x13b8 has exited with code 0 (0x0).
The thread 0xfdc has exited with code 0 (0x0).
The thread 0x700 has exited with code 0 (0x0).
The thread 0x179c has exited with code 0 (0x0).
Exception thrown: 'uPLibrary.Networking.M2Mqtt.Exceptions.MqttCommunicationException' in Assembly-CSharp.dll
Failed to connect to iot.eclipse.org:1883:
uPLibrary.Networking.M2Mqtt.Exceptions.MqttCommunicationException: Exception of type 'uPLibrary.Networking.M2Mqtt.Exceptions.MqttCommunicationException' was thrown.
at uPLibrary.Networking.M2Mqtt.MqttClient.SendReceive(Byte[] msgBytes, Int32 timeout)
at uPLibrary.Networking.M2Mqtt.MqttClient.SendReceive(MqttMsgBase msg, Int32 timeout)
at uPLibrary.Networking.M2Mqtt.MqttClient.Connect(String clientId, String username, String password, Boolean willRetain, Byte willQosLevel, Boolean willFlag, String willTopic, String willMessage, Boolean cleanSession, UInt16 keepAlivePeriod)
at M2MqttUnity.M2MqttUnityClient.d__38.MoveNext()

(Filename: C:\buildslave\unity\build\artifacts/generated/Metro/runtime/DebugBindings.gen.cpp Line: 51)

Connection failed, no route to host on iOS?

Hello. I've set up the connection in Unity based on this Git repository and I'm in the process of creating an app for iOS. When I test it on my PC everything works fine and I can connect to the broker just fine. The broker runs on Node-RED on a home PC.
But as soon as I build the app and start it on my phone, I get the error message: "no route to host" and "connection failed". Anyone know why that is? However, when I use an online broker like: broker.mqttdashboard.com, it works fine on mobile. But as soon as I try it with my Node-RED broker, it doesn't work. The IP address is 192.168 etc.. and I use port 1883.

The app must necessarily connect to a broker that is on the local network. It's not my broker's settings or any other authentication issues.

Could anyone help me, please? Would be very grateful!

il2cpp build hololens connection problem

If I build the unity app with il2cpp and deploy it to hololens2, I am getting an error during client connection. While compiling it with .NET, no such error appears. The issue is that ,NET compatibility has been removed in recent Unity releases.

subscribe

hello, im new to m2mqtt and im trying to use this project to subscribe from a broker, is it compatbile?

WebGL + MQTT authentication

Hi, I am using this for my android and iOS game, and is working flawlessly

Thank you for that.

Now, i wanted to use MQTT for my another project which is for WebGL and it also requires authentication.
So, is there any chance of it supporting this?

Any help will be highly appreciated.

NullReferenceException: Object reference not set to an instance of an object

I'm hoping I can get some help with an issue I'm having.
After running a build for 2-3 hours with no interactivity, I start getting this error and the app no longer receives any data from MQTT.

NullReferenceException: Object reference not set to an instance of an object
  at M2MqttUnity.M2MqttUnityClient.ProcessMqttMessageBackgroundQueue () [0x00016] in <a142f2b118d44b049fd51176acc445ad>:0 
  at M2MqttUnity.M2MqttUnityClient.ProcessMqttEvents () [0x00012] in <a142f2b118d44b049fd51176acc445ad>:0 
  at M2MqttUnity.M2MqttUnityClient.Update () [0x00000] in <a142f2b118d44b049fd51176acc445ad>:0 
  at MyM2MqttUnityScript.Update () [0x00000] in <a142f2b118d44b049fd51176acc445ad>:0 

Any one might be of help as to why this might be happening?

Thanks you in advance.

can not connect to the mqtt broker with the (WebGL) output I got from Unity

I made a game scene in Unity that has several objects and each object displays the value of a sensor, such as a temperature sensor. These sensors should communicate with our broker and display the values. I did this with M2MQTT and in game mode in Unity, I can connect to the broker located on another server and receive the values. . When I exit the game in WebGL format, I see that it cannot connect to the broker, not even any other broker. What is the solution? Thankful.

Subscribe to multiple topics at once?

Hello there!

I'm using a single MQTT client, but when I try to subscribe tu multiple MQTT topics at the same time I'm receiving errors (when only one topic is subscribed everything works well)

M2MqttUnity not working with HiveMQ Broker

Hello,

The code works well for Eclipse IoT MQTT broker (iot.eclipse.org and mqtt.eclipseprojects.io), but if i try the MQTT project with other MQTT brokers like HiveMQ, the script is throwing an exception (screenshot attached).

Has anyone tried to use this package with a different MQTT broker other than Eclipse IoT Broker?
2021-11-10_19h59_21
.

Problems with encryption enabled

Environment

M2MqttUnity commit: 2ce51ed
Unity 3D versions: 2017.1.0f3, 2017.1.4f1, 2018.1.9f1, 2018.2.5f1

Steps to reproduce

Open the M2MqttUnity_Test example scene.
Run it in Editor or build on Windows Standalone or Android.
Enable encryption, try to connect to a broker (e.g. iot.eclipse.org).

Expected behavior

Connection successful (activating encryption and choosing the proper port, e.g. 8883 for mosquitto brokers).

Current behavior

While no problem was found using a not encrypted connection,
testing the included example also with encryption
it does not work on Windows Standalone, Android (and even in Unity Editor), but
it works when built on UWP/Windows 10 (PC and HoloLens).

Failed to connect to iot.eclipse.org:8883:
uPLibrary.Networking.M2Mqtt.Exceptions.MqttConnectionException: Exception connecting to the broker ---> System.IO.IOException: The authentication or decryption has failed. ---> Mono.Security.Protocol.Tls.TlsException: The authentication or decryption has failed.
  at Mono.Security.Protocol.Tls.RecordProtocol.ProcessAlert (AlertLevel alertLevel, AlertDescription alertDesc) [0x00000] in <filename unknown>:0 
  at Mono.Security.Protocol.Tls.RecordProtocol.InternalReceiveRecordCallback (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at Mono.Security.Protocol.Tls.SslStreamBase.AsyncHandshakeCallback (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at uPLibrary.Networking.M2Mqtt.MqttClient.Connect (System.String clientId, System.String username, System.String password, Boolean willRetain, Byte willQosLevel, Boolean willFlag, System.String willTopic, System.String willMessage, Boolean cleanSession, UInt16 keepAlivePeriod) [0x00039] in D:\Unity3D\Projects\IoT\M2MqttUnity\Assets\M2Mqtt\MqttClient.cs:565 
  at uPLibrary.Networking.M2Mqtt.MqttClient.Connect (System.String clientId) [0x0000d] in D:\Unity3D\Projects\IoT\M2MqttUnity\Assets\M2Mqtt\MqttClient.cs:485 
  at M2MqttUnity.M2MqttUnityClient+<DoConnect>c__Iterator0.MoveNext () [0x001d2] in D:\Unity3D\Projects\IoT\M2MqttUnity\Assets\M2MqttUnity\Scripts\M2MqttUnityClient.cs:304 
UnityEngine.Debug:LogErrorFormat(String, Object[])
M2MqttUnity.<DoConnect>c__Iterator0:MoveNext() (at Assets/M2MqttUnity/Scripts/M2MqttUnityClient.cs:309)

(see also eclipse/paho.mqtt.m2mqtt#21)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.