4ian / GDevelop

🎮 Open-source, cross-platform 2D/3D/multiplayer game engine designed for everyone.
https://gdevelop.io
Other
10.82k stars 848 forks source link

[$150 bounty] MQTT client extension #2135

Closed lapieandalpie closed 3 years ago

lapieandalpie commented 3 years ago

--- I realize this is a fringe feature, so I am happy to pay for it to be added. It was recommended on the forum to post it here in order to add it to the bounty list ---

Request: An mqtt client extension tied into gdevelop gui to alow login to server, subscribe and publish of topics.

The primary reason I'm keen to see an mqtt client in gdevelop is to create games integrated with small iot devices. I've started running school workshops introducing kids to gdevelop and being able to tie together what they've learned about arduino/esp32 with gdevelop would allow them to create enhancements like remote button panels and led strips that react to the game states, relays that unlock from game events, etc. (and hopefully spark new coders) The kids already use arduino micros in keyboard emulation to make joystick/button panels for gdevelop and they (and myself) are really excited about creating games that extend beyond the screen/around the room/building/world.

The target user in my case would be kids using gdevelop to build local "group play" games/escape room style games such as a real world "among us" style game with multiple gdevelop "stations" as well as iot devices like light/sensor/rfid readers/relay controllers all sending simple status and state messages to each other via a local or internet mqtt server.

The problem? the pvp and get/post solutions are a big step for new-to-programming devs who are creating games "without using code" and difficult/complex to to integrate with iot devices.

The solution? There are some robust mqtt js/node clients. If someone were able to package one up as a gdevelop extension (if this is possible) and add a simple interface for server address/ login/ password / topic subscribe / topic publish and a method for subscribed topics to be accessed as variables, not only could all the above be easily implemented, but it could also be useful for other user functions, such as a simpler chat or turn based mechanic to be added by novices.

mqttexample

I'm happy to pay a bounty, write the wiki about mqtt and create a sample project if someone is able to implement it. Cheers!

arthuro555 commented 3 years ago

@4ian What is your opinion on this? It could be also useful for multiplayer in general, but we would need to do some more testing to see if it is better than sockets.io. I don't think having many libraries for networking is a good idea, as it might confuse users on which they should use. Maybe this should be proposed as an events functions extension?

4ian commented 3 years ago

This seems very specific indeed and IoT related so this would probably not qualify for an "official" extension but that could surely be an extension published on the community extension registry as you suggest.

@lapieandalpie If you're interested in offering a bounty for this, you can do some using bountysource: https://www.bountysource.com/teams/gdevelop/issues?tracker_ids=3677421 (or another similar website, I've just tried bountysource so far). or hire a freelancer?

I imagine one could pack an existing Node.js/browser JS client into an extension (or load it from a CDN - I usually don't encourage this but this can be a temporary solution) and then expose feature (all using JavaScript events).

lapieandalpie commented 3 years ago

Cheers, guys. I've put $150 on the issue bountysource. Hopefully that'll spark somebody to look at it.

arthuro555 commented 3 years ago

That definitely sparks my interest! I'm looking into it ;)

lapieandalpie commented 3 years ago

Awesome, Arthuro!

lapieandalpie commented 3 years ago

2 questions: 1. how do we access a suscribed topic? (I was hoping that the subscription function could name a global variable to place the received data... is that possible?) like "subscribe to topic foo to be saved to global variable bar" and 2. the field in "connect to mqtt server" is "host port". Can you clarify if this is the port or the full server address including port?

4ian commented 3 years ago

Sorry I did not meant to close the issue yet. I suggest that:

@lapieandalpie will then close the issue so that the bounty can be claimed.

arthuro555 commented 3 years ago

how do we access a suscribed topic?

Once you subscribed to a topic, you can listen to it with the On Message condition. When a message is received, it will trigger that condition, and you can get the data with the MQTT::GetLastMessage expression. Kind of like this: image

the field in "connect to mqtt server" is "host port"

Whoops, didn't mean to leave it like that, I forgot to write the actual description. What you enter is the host without any protocol. You can also enter a port if you wish. For example, just localhost can be valid, it will connect via websocket to the default http port (ws://localhost:80). You can also add the port like this: image

The port 8081 is used as it is the port of the test mosquitto server for secure websockets. If you want, you can disable tls by disabling the secure connection and using the port 8080, as you can see on http://test.mosquitto.org/. The exact port depends on your broker server.

lapieandalpie commented 3 years ago

I've only been able to glance at it (I'm still at work), but I'm super impressed with how thoroughly you've tied it all together and integrated it into gdevelop. It (without any testing yet) looks to be exactly what I was hoping for. Cheers!

lapieandalpie commented 3 years ago

Hey Arthuro! I haven't had a chance to test with my local mqtt servers but i recreated your connections to mosquitto and it worked great! I'm going to mark the issue closed so you can claim your bounty. Hopefully if there are any problems you can help with them, but it looks like you nailed it! Thanks!

arthuro555 commented 3 years ago

If you want to contact me/ask questions/request changes, you can find me on the discord server of GDevelop and on the GDevelop forum 😉