Send a Message on Discord Using Esp32 / Arduino MKR1010

About: I build projects using arduino nano / esp32 / arduino micro and also arduino mkr1010

Discord server has a system to send messages automatically to a channel.

This system uses webhook, so you just have to send a web request to a URL and a message will be written on the selected channel.

https://en.wikipedia.org/wiki/Webhook

This could be used in many ways, for example:

  • Make a badge reader using RFID to send a message when someone is at your fablab.
  • Display the temperature of a room each hour.

Step 1: Create a Webhook

First we need to create a webhook in our server:

https://support.discordapp.com/hc/en-us/articles/2...

Click on your discord server nameDiscord Settings Then click on WebhookCreate WebHook

Copy the Webhook URL


Step 2: Arduino Code

I used Arduino Create to write my code, but you can also use the classic IDE.
Here is a link to the code: https://create.arduino.cc/editor/madnerd/429197a3...

Settings

Settings are inside arduino_secrets.h or the Secret tab

  • SECRET_SSID: your Wi-Fi network name
  • SECRET_PASS: your Wi-Fi password
  • SECRET_WEBHOOK: your Webhook URL without https://discordapp.com
  • SECRET_TTS: true to enable text to speech or false to disable it

Upload your code on your Arduino MKR 1010, you should see a message on your discord server.

Library
I used two libraries for this code:

  • WiFiNINA: Wi-Fi managerArduino
  • HttpClient: Web request

Step 3: ESP32 Code

I tried to make a code that are as much similar as possible for the ESP32.

The code are available : https://github.com/maditnerd/discord_test

Settings
Settings are inside arduino_secrets.h

  • SECRET_SSID: your Wi-Fi network name
  • SECRET_PASS: your Wi-Fi password
  • SECRET_WEBHOOK: your entire Webhook URL
  • SECRET_TTS: true to enable text to speech or false to disable it

Step 4: Send a Message on Discord

Most of the code are inside discord.h

To send a message on discord, just type:
discord_send("Hello World");

If you want to reuse for my code with others webhooks, you will need
to get the certificate of the domain on which you are sending your request.

This is not needed on Arduino MKR1010 as it didn't check the domain.

You can find how to do this in this video:

Share

    Recommendations

    • Pocket Sized Contest

      Pocket Sized Contest
    • Epilog X Contest

      Epilog X Contest
    • Tape Contest

      Tape Contest

    Discussions