DEV Community

Cover image for I Vibe Coded a Multiplayer ASL Game using MQTT! ๐ŸŒ

I Vibe Coded a Multiplayer ASL Game using MQTT! ๐ŸŒ

Last year (2 months ago), I created a game using p5.js and ml5.js that uses Machine Learning to detect the ASL alphabet. I made this project for my course "IoT with Machine Learning" at my University and it taught me a lot about the process and how IoT is shaping the world!

One of the things that I utilize in this project is using MQTT (Message Queuing Telemetry Transport). It is different from Web Sockets because of how it is use for IoT specifically since it is designed for constrained devices such as Arduino, which I used for this project.

But I want to use MQTT for just the multiplayer functionality. I had some practice with Web Sockets, but thought to myself..."How far can I go with MQTT"?


Overview of the Project

This project is a desktop application. It is a simple game where your goal is to spell out as many words as you can in ASL. You can play either Single player or Multiplayer. It utilizes Machine Learning to perform Pose Estimation on the user's hand points using ml5.js. You can learn more about it on their documentation.

Technologies I Used

To make the desktop application, I used Tauri which is framework to create your own desktop/mobile app. It is very nice since you can do Web Development stuff inside of Tauri such as React, Vue, or just Vanilla HTML, CSS, and JavaScript. For this project, I stick to Vanilla HTML, CSS, and JavaScript. I also used p5.js and ml5.js for my libraries as I mentioned earlier. I also used SupaBase to store high scores of the words they accomplished.

ASL Machine Learning Model

Main Menu

This rough flow diagram shows the following of the game functionality. When you do ASL, it detects your hand points and the gesture you are doing. It then feeds the data points into the Machine Learning Model and it predicts which alphabet you are gesturing in real-time. Once the game is done, it uploads your data to the database of your score and coins you have received.

The Arduino part is an extension that shows you data, such as your "Letters per second" and your username, on an LCD which is shown here:

Arduino

MQTT Multiplayer Functionality

To accomplished this, I use Mosquitto as my broker. This diagram shows the flow of how the Multiplayer game works:

MQTT Diagram

In short, you can create a room and it will provide you a code to share with other users to join the room. In the lobby, when everyone clicks "Ready" the game starts. Demo is shown here below:

Demo

Challenges I Faced

There are are few big things I faced when creating this project.

1. MQTT setup

I had the idea of how it works, but it is hard to implement in practice since I am not really using an IoT device to communicate to the broker (Unless you count the camera as an IoT device). Since it was vibe coded, I had to take the time to understand the flow and how data is being pass/received.

2. Creating my own Model

I started with Image Classification. But the problem is that it captures the WHOLE image in addition to your hands. Meaning if I use the model in a different setting, it would not predict it accurately. I then learn about Hand pose in ml5.js documentation and I start building my own model. I had to create a separate vibe coded project that is design to create your own Hand pose Model.

Own Model

3. Training problems

For context, I trained letters from A-Z ("J" and "Z" are excluded). For each letter, it captures around 2000 Post Estimation data. After training is complete, it forgets the last last two letters, which are "X" and "Y". The solution I came up with is that during data collecting, if I reach either "X" or "Y", collect more than 2000 Post Estimation data. In this case, "X" will get 4000 and "Y" gets 6000 (Just to be safe). If anyone knows why this is the case, please let me know!

Code


Summary

It was a fun project! I learned a lot about not only how to connect the Arduino to the web, but also how to use MQTT to the limit (to my knowledge). If you are interested more about this project, check out the GitHub Repository here!


Any questions, or comments? I would love to hear from you!

Top comments (13)

Collapse
 
itsugo profile image
Aryan Choudhary

Wow, Francis, that's incredible work! You've really made this project come together, and I'm loving the fact that you were able to get MQTT working for multiplayer functionality. I can imagine how tough it must have been to figure out the Hand pose model and train it, but you persisted and got great results.

Collapse
 
francistrdev profile image
๐Ÿ‘พ FrancisTRDev ๐Ÿ‘พ

Thanks Aryan! It did took me a bit since I was conformable doing Image Classification. What helped was watching an Overview of the Hand pose from The Coding Train. I think @richardpascoe would love this channel since he does web development related stuff in terms of Creative Coding.

But overall, I was happy to make the multiplayer game work since that was one of my goals I wasn't able to accomplish perfectly till now. Thanks for your reply!

Collapse
 
richardpascoe profile image
Richard Pascoe • Edited

Thanks for the heads-up, Francis! Will check it out, and re-read this post, when I have a little more time! Sounds rather interesting though!

Collapse
 
itsugo profile image
Aryan Choudhary

Wow - just wow - congratulations on accomplishing that goal you set for yourself! Looking forward to learning so much more from you!! This is great!

Collapse
 
richardpascoe profile image
Richard Pascoe

Due to a meeting delay, had time to read the post this morning - truly incredible stuff and testament to your hard work and determination. Will keep this bookmarked to re-read again, so I get a deep understanding of what was involved. Well done!

Collapse
 
francistrdev profile image
๐Ÿ‘พ FrancisTRDev ๐Ÿ‘พ

Thanks Richard! Let me know your thoughts when you deep dive into the post!

Collapse
 
richardpascoe profile image
Richard Pascoe

Will do, Francis!

Collapse
 
bhavin-allinonetools profile image
Bhavin Sheth

This is a really creative use of MQTT beyond the usual IoT sensor examples.

Using it just for multiplayer game state + combining it with ML hand-pose detection and Tauri is a very cool mix of technologies. Also loved the practical workaround you found for the X/Y training issue โ€” thatโ€™s real problem-solving in action.

Curious: did you notice any latency differences between MQTT and WebSockets during gameplay?

Collapse
 
francistrdev profile image
๐Ÿ‘พ FrancisTRDev ๐Ÿ‘พ

Hey Bhavin! Hope you are well!

For context, I use Web Sockets when I was building my Chat App using Flask back around 2023-2024.

With that said, I didn't see any latency differences when it comes to using MQTT compare using Web Sockets, which was surprising giving the fact that I was publishing data points and the skeleton coordinates to the broker and then receiving that and displaying on the user side, which is a lot!

The only thing I notice was that one of the requirements for this project was making an offline mode. Because I was using libraries, I had to get it locally installed and direct it on file instead of the traditional API calling to the web.

Not only that, the libraries I locally instead ALSO does an API call to the web. For example, when I installed ml5.js locally, I notice that it was calling TensorFlow Mediapipe on the Web since ml5.js is built on TOP of TensorFlow. So, I had to install Mediapipe files locally.

It was a massive headache, but it improve responsiveness DRASTICALLY, which was awesome to see!

Thank you for the reply and hope you have a good week!

Collapse
 
fithappensml profile image
Fit Happens ML

it's really cool man! Congrats!

Collapse
 
francistrdev profile image
๐Ÿ‘พ FrancisTRDev ๐Ÿ‘พ

Thanks for reading Fit!

Collapse
 
liam_grey_9321f5e1dd03b2f profile image
Liam Grey

Really impressive project! Love how you combined ML with multiplayer functionalityโ€”makes me think of innovative ways to enhance interactive gameplay.

Collapse
 
francistrdev profile image
๐Ÿ‘พ FrancisTRDev ๐Ÿ‘พ

Thanks Liam! ML with Multiplayer is quite interesting to experience!