MQTT

MQTT is a standardized messaging protocol for communication between computers. The protocol has a simple implementation and high data transfer efficiency. MQTT supports messaging in both directions: from devices to the cloud and back.

You need to add these parameters to the config.yaml file:

MQTT:
  url: "amqp://guest:guest@localhost:5672/%2F"
  exchange_name: "unicounter"
  queue_name: "unicounter"
  routing_key: "unicounter"
  app_id: "unicounter-1"
  period_sec: 1
  debug: true

We use the standard ampq protocol.

You can use RabbitMQ as an option, but you can change it to your ampq address along with your login and password.

The program sends messages like:

'{"some_camera_1": {"default": 6}}'

That is, one message can contain an update for several cameras, in each camera for several types of counted objects.

Only what was counted comes, that is, not a cumulative total, but simply how much has passed during the period.

For testing, you can install Erlang and Rabbit and run these two Python scripts.

sender_example.py

import pika

connection = pika.BlockingConnection(
    pika.ConnectionParameters(host='localhost'))
channel = connection.channel()

channel.queue_declare(queue='unicounter')

channel.basic_publish(exchange='', routing_key='unicounter', body='Hello World!')
print(" [x] Sent 'Hello World!'")
connection.close()

consumer_example.py

import pika, sys, os

def main():
    connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
    channel = connection.channel()

    channel.queue_declare(queue='unicounter')

    def callback(ch, method, properties, body):
        print(f" [x] Received {body}")

    channel.basic_consume(queue='unicounter', on_message_callback=callback, auto_ack=True)

    print(' [*] Waiting for messages. To exit press CTRL+C')
    channel.start_consuming()

if __name__ == '__main__':
    try:
        main()
    except KeyboardInterrupt:
        print('Interrupted')
        try:
            sys.exit(0)
        except SystemExit:
            os._exit(0)