This Discord bot provides weather data from the FHDW Weatherstation. The bot can subscribe and unsubscribe channels to receive weather updates, list the currently subscribed channels, and unsubscribe all channels at once.
The aim of this repository is to provide a comprehensive example of how to integrate data from an end device in The Things Stack into a Discord bot using the MQTT protocol. By doing so, it bridges the gap between IoT devices using LoRaWAN technology and the popular communication platform, Discord. This enables users and communities to receive real-time updates from their IoT devices, such as weather data, directly in their Discord channels.
Through this demonstration, the repository seeks to empower developers and enthusiasts to explore the potential of integrating IoT data with Discord. The project serves as a foundation for creating more sophisticated applications that leverage LoRaWAN data in innovative ways. Ultimately, this repository aims to inspire the community to find new and creative ways to utilize IoT data and enhance the capabilities of their Discord bots.
The integration of data from The Things Stack into a Discord bot was achieved using the MQTT protocol, a lightweight and efficient messaging protocol designed for IoT devices. MQTT allows for secure and reliable data transfer between the end device and the Discord bot. By subscribing to the appropriate topics in The Things Stack, the Discord bot can receive the data transmitted by the IoT devices.
The necessary code is implemnted in the mqttHandler.js. The integration was achieved by following these steps:
createMqttClient function from the mqttHandler.js file in the index.js.config.json file.createMqttClient() function in the index.js file and providing the necessary credentials and a callback function to handle received messages.
createMqttClient() function sets up the MQTT client by connecting to The Things Stack and subscribing to the specified topic.index.js file:
createWeatherEmbed() function.dataStorage module.dataStorage module.By understanding the process, developers can build upon this knowledge for future projects involving IoT devices. The integration serves as a template for various applications, such as connecting IoT devices to different platforms, transforming and processing the data, and creating custom alerts or notifications. This example showcases how MQTT can be used as a powerful tool to bridge the gap between IoT devices and other applications, fostering more innovative and integrated solutions for the Internet of Things.
Go to the Discord Developer Portal and sign in with your Discord account.
Click on the "New Application" button, give your application a name, and then click "Create".
In the application's settings, click on the "Bot" tab, then click on the "Add Bot" button to create a bot for your application. Confirm by clicking "Yes, do it!".
In the "Bot" tab make sure that the "MESSAGE CONTENT INTENT" is set to true.
Under the "TOKEN" section, click "Copy" to copy your bot token. Keep this token safe, as it will be used to authenticate your bot with Discord.
(Optional) Customize your bot's name, profile picture, and other settings as desired. Open
git clone https://github.com/yourusername/FHDW-Weatherstation-Discord-Bot.git...TheThingsNetwork-DiscordBot-FHDW-WeatherDataBot> npm installYou might have to navigate to the Bot directory before running `npm install`.
To navigate use `cd folder_name`
{
"token": "your_discord_bot_token",
"clientId": "your_discord_bot_client_id",
"guildId": "your_discord_server_guild_id",
"ttnAppUser": "your_ttn_app_user",
"ttnAppPw": "your_ttn_app_pw",
"ttnAdress": "your_ttn_address",
"ttnAppDevice": "your_ttn_app_device"
}Example:
{
"token": "AAA0000aaa000AAAA000AA.AAA00AAA.aaa-AaaaaAA0000AAAAAAAAAAaaaAAAA00AAAAAA",
"clientId": "1234567891234567891",
"guildId": "1234567891234567891",
"ttnAppUser": "hello-world-weather",
"ttnAppPw": "NXYXX.0A0AAAAAAAA0AAAAAAA4AAA00AAAMAAAAAAAAA.AA0AAAAA0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"ttnAdress": "mqtts://eu1.cloud.thethings.network:8883",
"ttnAppDevice": "eui-00a0000aa000a000"
}https://discord.com/api/oauth2/authorize?client_id=your_discord_bot_client_id&permissions=8&scope=bot
Example FHDW-Weather-Bot: https://discord.com/api/oauth2/authorize?client_id=1088555644333867069&permissions=8&scope=bot
...TheThingsNetwork-DiscordBot-FHDW-WeatherDataBot> node deploy-commands.js(You might have to restart your Discord-Client afterwards)
3.1. To start the bot, run:
...TheThingsNetwork-DiscordBot-FHDW-WeatherDataBot> npm start3.2. To run the bot in development mode with nodemon, run:
...TheThingsNetwork-DiscordBot-FHDW-WeatherDataBot> npm run dev/subscribe [channel]: Subscribe a channel to the FHDW-Weatherstation. If no channel is provided, the current channel will be subscribed./unsubscribe [channel]: Unsubscribe a channel from the FHDW-Weatherstation. If no channel is provided, the current channel will be unsubscribed./list: List all channels currently subscribed to the FHDW-Weatherstation./unsubscribe_all: Unsubscribe all channels from the FHDW-Weatherstation.To deploy the bot on a hosting platform, follow the platform-specific instructions for Node.js applications. Make sure to include the config.json file with your credentials in the deployment package.
Ensure that the config.json file is included in your deployment and that your bot token and other sensitive information are kept secure. If the hosting platform supports environment variables, it's recommended to store your credentials as environment variables rather than including them in the config.json file.
For example, you can deploy the bot to Heroku by following these steps:
For more detailed instructions on deploying a Discord bot to Heroku, check out this guide.
This project is licensed under the MIT License.