Skip to content

Getting started

Using MQTT Explorer

Here is an example of how to connect to our MQTT broker using MQTT Explorer:

Validate cerificate: disabled
Encryption: enabled
Protocol: mqtt://
Host: mqtt.ainsite.io
Port: 8883
Username: Your username
Password: Your password

Example from MQTT Explorer

To add subscription click ADVANCED. Then write in your topic on form meters/outbound/[customer-id]/[subscription-id]/[meter-id] click + ADD subscription.

Example of setting up subscription in MQTT Explorer

Python code example:

Install the AIOMQTT python package:

pip install aiomqtt

Try to connect

import asyncio
import aiomqtt
import ssl

# Define broker information
BROKER = "mqtt.ainsite.io"
PORT = 8883
USERNAME = "XXXXX"  # Replace with your actual username
PASSWORD = "XXXXX"  # Replace with your actual password

# Define topic to subscribe to
CUSTOMER_ID = "XXXXX-XXXXX-XXXXX-XXXXX-XXXXX"
SUBSCRIPTION_ID = "XXXXX-XXXXX-XXXXX-XXXXX-XXXXX"
METER_ID = "XXXXX-XXXXX-XXXXX-XXXXX-XXXXX" # "#" for wildcard 
TOPIC = f"meters/outbound/{CUSTOMER_ID}/{SUBSCRIPTION_ID}/{METER_ID}"

tls_params = aiomqtt.TLSParameters(
        cert_reqs=ssl.CERT_REQUIRED,
    )

async def main():
    async with aiomqtt.Client(
        hostname=BROKER,
        port=PORT,
        username=USERNAME,
        password=PASSWORD,
        tls_params=tls_params,
        keepalive=60*30,
    ) as client:

        await client.subscribe(TOPIC, qos=1)
        async for message in client.messages:
            print(f"Topic: {message.topic} | Message: {message.payload}")

if __name__ == "__main__":
    asyncio.run(main())