Skip to main content

EMQX Setup

EMQX is an MQTT platform that handles data sent from Agripad devices and forwards it to the dashboard via webhooks.

1. Download EMQX

Download from EMQX website

2. Start EMQX

sudo emqx start

3. Create Admin User

sudo emqx ctl admins add <ADMIN_USERNAME> <ADMIN_PASSWORD>

# Example
sudo emqx ctl admins add admin1 @adminpass

4. Access EMQX Dashboard

Open http://localhost:18083/ in your browser and log in with the credentials created above.

5. Set Up a Webhook

  1. Navigate to http://localhost:18083/#/webhook
  2. Create a new webhook with the following details:
    • Name: Agripad
    • Note: Main dashboard (optional)
    • Trigger: Select "message publish" only
    • Topic Filter: agripad
    • Method: POST
    • URL: http://main.localhost:8000/api/agric/mqtt-webhook-receiver/
    • Headers:
      • content-type: application/json
      • API-key: <API_KEY_VALUE>

6. Test the Webhook

  1. Open the Websocket client tab or visit http://localhost:18083/#/websocket
  2. Connect to the websocket client
  3. Subscribe to the agripad topic
  4. Publish test data to the topic using the following JSON format:
{
"k": 11,
"n": 10,
"p": 10,
"ec": 10,
"ph": 13,
"time": "04/07/24 10:06:22",
"device": "device_001",
"booking": "9",
"humidity": 0,
"latitude": -1.305787,
"longitude": 36.80276,
"temperature": 24.2
}
  1. Verify that the data is received in the "Received" section
  2. Check the webhook status to confirm successful data transmission

EMQX Configuration

Creating Swap Memory for EMQX

EMQX may require additional memory. Create a swap file:

sudo fallocate -l 1G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

To make the swap permanent:

echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

Restart EMQX after configuring swap:

sudo systemctl restart emqx