One of the difficult aspects of creating an IoT project is how to control it from outside the home. While it's possible to set up a dedicated server or use a cloud service, this comes with significant costs and maintenance hassle.
In this project, by implementing it as a Discord Bot, we've achieved a convenient UI, low cost, real-time performance, and zero maintenance.
## Communication with Discord API Server:A Discord Bot can be implemented by sending HTTP requests and receiving WebSocket events. The ESP32 can connect to the Discord API server on its own.
Importantly, the ESP32 itself does not need to listen on a port. Since the connection to the Discord API server is made from the ESP32, it is not dependent on the home network environment, as long as there is an internet connection.
The Discord API exchanges JSON messages. For small messages, JSON decoding is possible on the ESP32 itself.
## How it works:The device connects to WiFi and Discord API server after start up. If success, the device listens the event on your Discord server like new messages and mentions. If mentioned and valid command included, executes the command and send the response as Discord message.
If WiFi or WebSocket connection lost, tries to re-connect automatically. You can check the connection of the bot on your Discord server' member list.
## Development Environment and Libraries:- Arduino IDE
- HTTPClientSecure (built-in)
- WebSockets by Markus Sattler
- ArduinoJson by Benoit Blanchon.
AtomS3R-M12
(NOTE: AtomS3R-Cam is also available. Since the GC0308 image sensor lacks JPEG format support, a small change is needed in the firmware code.)
## How to Make:Create a bot in Discord.
Invite the bot to your server.
Create `secrets.h` file and place your WiFi SSID, Password, Bot token and MAC address to send magic packet.
Flash firmware to the AtomS3R-M12.
Power the AtomS3R-M12. That's all!
## How to Use:When the device starts up, the bot will come online. Send commands via reply. (The bot name is `@AtomBot`.)
Turns GPIO on and off:
@AtomBot on
@AtomBot offSends a magic packet to boot the computer:
@AtomBot bootTakes a photo with the AtomS3R-M12 and uploads it to Discord:
@AtomBot photo## Conclusion:The IoT project in your home got a convenient UI with real time message and file attachment support without dedicated server. M5Stack controllers allows you to make a such device rapidly because of all-in-one for hardware prototyping.









Comments