Closed scopelemanuele closed 4 years ago
Can you, please, show me how are trying to receive those values from AMQP? No errors in the log means that the message is really published to an amq.topic exchange with the relevant data. Also notice, that in the mqtt publish you use .../app/stazione/.. while in amqp you use .../apps/...
The broker is RabbitMQ on docker image rabbitmq:3.8.9-alpine with enabled mqtt plugin.
This is the log on connection (LoRaWan Server): 2020-10-26 18:38:53.327 [info] <0.1503.0> accepting AMQP connection <0.1503.0> (172.17.0.1:40726 -> 172.17.0.4:5672) 2020-10-26 18:38:53.330 [info] <0.1503.0> connection <0.1503.0> (172.17.0.1:40726 -> 172.17.0.4:5672): user 'gateway' authenticated and granted access to vhost 'gateway'
This in the consumer python script:
import pika
import json
from EVOencoder import EvoTranscoder
def on_data(ch, method, properties, body):
print(body)
decoder = EvoTranscoder()
payload = json.loads(body.payload.decode("utf-8", "ignore"))
print(payload["text"])
print(decoder.decode(payload["text"]))
credentials = pika.PlainCredentials(
'gateway', 'password')
connection = pika.BlockingConnection(
pika.ConnectionParameters('mqtt.silvergeko.it', credentials=credentials, virtual_host="gateway"))
channel = connection.channel()
channel.queue_declare(queue='LoRaWan.gateway.apps.stazione.data.upload')
channel.basic_consume(queue='LoRaWan.gateway.apps.stazione.data.upload',
auto_ack=True,
on_message_callback=on_data)
print(' [*] Waiting for messages. To exit press CTRL+C')
channel.start_consuming()
This is a log of a simple producer python script: 2020-10-26 18:41:53.161 [info] <0.1741.0> accepting AMQP connection <0.1741.0> (93.41.226.151:50998 -> 172.17.0.4:5672) 2020-10-26 18:41:53.206 [info] <0.1741.0> connection <0.1741.0> (93.41.226.151:50998 -> 172.17.0.4:5672): user 'gateway' authenticated and granted access to vhost 'gateway' 2020-10-26 18:41:53.316 [info] <0.1741.0> closing AMQP connection <0.1741.0> (93.41.226.151:50998 -> 172.17.0.4:5672, vhost: 'gateway', user: 'gateway')
This is the code of the producer script:
import pika
credentials = pika.PlainCredentials(
'gateway', 'password')
connection = pika.BlockingConnection(
pika.ConnectionParameters('mqtt.silvergeko.it', credentials=credentials, virtual_host="gateway"))
channel = connection.channel()
channel.queue_declare(queue='LoRaWan.gateway.apps.stazione.data.upload')
channel.basic_publish(
exchange="", routing_key='LoRaWan.gateway.apps.stazione.data.upload', body='Hello World!')
print(" [x] Sent 'Hello World!'")
connection.close()
The message written with the producer script is successfully received by the consumer script.
You missing amq.topic exchange binding for your clients. As your producer lower uses default exchange, so does your consumer. You can run your producer and your consumer will get it. But server doesn't publish to default gateway, it publishes to amq.topic you need to bind your queue to get the data.
For your consumer. (You can check this by changing exchange="" to exchange="amq.topic" in your producer).
result = channel.queue_declare(exclusive=True)
queue = result.method.queue
channel.queue_bind(exchange="amq.topic", queue=queue)
Resolved!!!! Thank you very much for your information!!!
LoraServer connects correctly to the Brocker, but does not publish any data and does not generate any errors on the log:
2020-10-25 21: 26: 12.589 [debug] <0.308.0> @lorawan_connector_sup: stop_child: 23 Stop {amqp, << "RabbitRouter" >>} 2020-10-25 21: 26: 12.589 [debug] <0.11147.5> @lorawan_connector_amqp: log_termination: 160 Connector RabbitRouter terminated: shutdown 2020-10-25 21: 26: 12.592 [debug] <0.308.0> @lorawan_connector_sup: start_child: 16 Start {amqp, << "RabbitRouter" >>} 2020-10-25 21: 26: 12.593 [debug] <0.11177.5> @lorawan_connector_amqp: handle_info: 51 Connecting RabbitRouter to amqp: //mqtt.silvergeko.it/gateway 2020-10-25 21: 26: 12.593 [debug] <0.307.0> Supervisor lorawan_connector_sup started lorawan_connector_amqp: start_link ({connector, << "RabbitRouter" >>, << "Station" >>, << "json"> >, << "amqp: //mqtt.silvergeko.it/gateway" >>, ...}) at pid <0.11177.5> 2020-10-25 21: 26: 12.593 [debug] <0.11178.5> Supervisor {<0.11178.5>, amqp_connection_sup} started amqp_connection_type_sup: start_link () at pid <0.11179.5> 2020-10-25 21: 26: 12.593 [debug] <0.11178.5> Supervisor {<0.11178.5>, amqp_connection_sup} started amqp_gen_connection: start_link (<0.11179.5>, {amqp_params_network, << "my_user" >>, << "my_pass" >>, << "gateway" >>, "mqtt.silvergeko.it", 5672,2047, ...}) at pid <0.11180.5> 2020-10-25 21: 26: 12.595 [debug] <0.11179.5> Supervisor {<0.11179.5>, amqp_connection_type_sup} started amqp_channel_sup_sup: start_link (network, <0.11180.5>, << "client 172.17.0.3:55313 -> 95.110.131.118:5672 ">>) at pid <0.11181.5> 2020-10-25 21: 26: 12.596 [debug] <0.11179.5> Supervisor {<0.11179.5>, amqp_connection_type_sup} started amqp_channels_manager: start_link (<0.11180.5>, << "client 172.17.0.3:55313 -> 95.110.131.118:5672 ">>, <0.11181.5>) at pid <0.11182.5> 2020-10-25 21: 26: 12.596 [debug] <0.11179.5> Supervisor {<0.11179.5>, amqp_connection_type_sup} started rabbit_writer: start_link (#Port <0.74084>, 0, 4096, rabbit_framing_amqp_0_9_1, <0.11180.5> , << "client 172.17.0.3:55313 -> 95.110.131.118:5672" >>) at pid <0.11183.5> 2020-10-25 21: 26: 12.596 [debug] <0.11179.5> Supervisor {<0.11179.5>, amqp_connection_type_sup} started amqp_main_reader: start_link (#Port <0.74084>, <0.11180.5>, <0.11182.5> , {method, rabbit_framing_amqp_0_9_1}, << "client 172.17.0.3:55313 -> 95.110.131.118:5672" >>) at pid <0.11184.5> 2020-10-25 21: 26: 12.597 [debug] <0.11179.5> Supervisor {<0.11179.5>, amqp_connection_type_sup} started rabbit_heartbeat: start_heartbeat_sender (#Port <0.74084>, 10, #Fun, { heartbeat_sender, << "client 172.17.0.3:55313 -> 95.110.131.118:5672" >>}) at pid <0.11185.5>
2020-10-25 21: 26: 12.598 [debug] <0.11179.5> Supervisor {<0.11179.5>, amqp_connection_type_sup} started rabbit_heartbeat: start_heartbeat_receiver (#Port <0.74084>, 10, #Fun , { heartbeat_receiver, << "client 172.17.0.3:55313 -> 95.110.131.118:5672" >>}) at pid <0.11186.5>
2020-10-25 21: 26: 12.598 [debug] <0.11187.5> Supervisor {<0.11187.5>, amqp_channel_sup} started amqp_gen_consumer: start_link (amqp_selective_consumer, [], {<< "client 172.17.0.3:55313 -> 95.110.131.118:5672">>,1}) at pid <0.11188.5>
2020-10-25 21: 26: 12.598 [debug] <0.11187.5> Supervisor {<0.11187.5>, amqp_channel_sup} started amqp_channel: start_link (network, <0.11180.5>, 1, <0.11188.5>, { << "client 172.17.0.3:55313 -> 95.110.131.118:5672">>,1}) at pid <0.11189.5>
2020-10-25 21: 26: 12.598 [debug] <0.11187.5> Supervisor {<0.11187.5>, amqp_channel_sup} started rabbit_writer: start_link (#Port <0.74084>, 1, 131072, rabbit_framing_amqp_0_9_1, <0.11189.5> , {<< "client 172.17.0.3:55313 -> 95.110.131.118:5672">>,1}) at pid <0.11190.5>
2020-10-25 21: 26: 12.599 [debug] <0.11177.5> @lorawan_connector_amqp: handle_subscribe: 175 Subscribing RabbitRouter to LoRaWan.gateway.apps.station.data.download
2020-10-25 21:45:19.408 [info] <0.11102.5> [ServerLoRaWan1@172.17.0.3:44559] SENT: PINGREQ(Q0, R0, D0)
2020-10-25 21:45:19.408 [info] <0.11102.5> [ServerLoRaWan1@172.17.0.3:44559] SENT: <<192,0>>
2020-10-25 21:46:19.407 [info] <0.11102.5> [ServerLoRaWan1@172.17.0.3:44559] SENT: PINGREQ(Q0, R0, D0)
2020-10-25 21:46:19.407 [info] <0.11102.5> [ServerLoRaWan1@172.17.0.3:44559] SENT: <<192,0>>
2020-10-25 21:47:19.407 [info] <0.11102.5> [ServerLoRaWan1@172.17.0.3:44559] SENT: PINGREQ(Q0, R0, D0)
2020-10-25 21:47:19.407 [info] <0.11102.5> [ServerLoRaWan1@172.17.0.3:44559] SENT: <<192,0>>
2020-10-25 21:48:19.408 [info] <0.11102.5> [ServerLoRaWan1@172.17.0.3:44559] SENT: PINGREQ(Q0, R0, D0)
2020-10-25 21:48:19.408 [info] <0.11102.5> [ServerLoRaWan1@172.17.0.3:44559] SENT: <<192,0>>
2020-10-25 21:49:15.456 [warning] <0.11932.5> node 240AC427 {uplinks_missed,1}
2020-10-25 21:49:15.657 [debug] <0.11932.5>@lorawan_mac_commands:build_fopts:77 240AC427 <- [dev_status_req]
2020-10-25 21:49:15.659 [info] <0.11102.5> [ServerLoRaWan1@172.17.0.3:44559] SENT: PUBLISH(Q1, R0, D0, TopicName=LoRaWan/gateway/app/stazione/data/upload, PacketId=5, Payload=<<"{\"app\":\"Stazione\",\"best_gw\":{\"lsnr\":7.8,\"mac\":\"9876543210ABCDEF\",\"rssi\":-41,\"time\":\"2020-10-25T21:49:15.446424Z\"},\"data\":\"343062303030303530623030303031666530313964326665306136383130383030303131312B30303964323062303030303130393030303330623030303031306130303130323034373130312B303039633131303031313033313764353731303730303031306230303030\",\"datetime\":\"2020-10-25T21:49:15Z\",\"devaddr\":\"240AC427\",\"fcnt\":4974,\"lsnr\":7.8,\"rssi\":-41,\"text\":\"40b000050b00001fe019d2fe0a68108000111+009d20b000010900030b000010a00102047101+009c1100110317d5710700010b0000\"}">>)
2020-10-25 21:49:15.659 [info] <0.11102.5> [ServerLoRaWan1@172.17.0.3:44559] SENT: <<50,204,4,0,40,76,111,82,97,87,97,110,47,103,97,116,101,119,97,121,47,97,112,112,47,115,116,97,122,105,111,110,101,47,100,97,116,97,47,117,112,108,111,97,100,0,5,123,34,97,112,112,34,58,34,83,116,97,122,105,111,110,101,34,44,34,98,101,115,116,95,103,119,34,58,123,34,108,115,110,114,34,58,55,46,56,44,34,109,97,99,34,58,34,57,56,55,54,53,52,51,50,49,48,65,66,67,68,69,70,34,44,34,114,115,115,105,34,58,45,52,49,44,34,116,105,109,101,34,58,34,50,48,50,48,45,49,48,45,50,53,84,50,49,58,52,57,58,49,53,46,52,52,54,52,50,52,90,34,125,44,34,100,97,116,97,34,58,34,51,52,51,48,54,50,51,48,51,48,51,48,51,48,51,53,51,48,54,50,51,48,51,48,51,48,51,48,51,49,54,54,54,53,51,48,51,49,51,57,54,52,51,50,54,54,54,53,51,48,54,49,51,54,51,56,51,49,51,48,51,56,51,48,51,48,51,48,51,49,51,49,51,49,50,66,51,48,51,48,51,57,54,52,51,50,51,48,54,50,51,48,51,48,51,48,51,48,51,49,51,48,51,57,51,48,51,48,51,48,51,51,51,48,54,50,51,48,51,48,51,48,51,48,51,49,51,48,54,49,51,48,51,48,51,49,51,48,51,50,51,48,51,52,51,55,51,49,51,48,51,49,50,66,51,48,51,48,51,57,54,51,51,49,51,49,51,48,51,48,51,49,51,49,51,48,51,51,51,49,51,55,54,52,51,53,51,55,51,49,51,48,51,55,51,48,51,48,51,48,51,49,51,48,54,50,51,48,51,48,51,48,51,48,34,44,34,100,97,116,101,116,105,109,101,34,58,34,50,48,50,48,45,49,48,45,50,53,84,50,49,58,52,57,58,49,53,90,34,44,34,100,101,118,97,100,100,114,34,58,34,50,52,48,65,67,52,50,55,34,44,34,102,99,110,116,34,58,52,57,55,52,44,34,108,115,110,114,34,58,55,46,56,44,34,114,115,115,105,34,58,45,52,49,44,34,116,101,120,116,34,58,34,52,48,98,48,48,48,48,53,48,98,48,48,48,48,49,102,101,48,49,57,100,50,102,101,48,97,54,56,49,48,56,48,48,48,49,49,49,43,48,48,57,100,50,48,98,48,48,48,48,49,48,57,48,48,48,51,48,98,48,48,48,48,49,48,97,48,48,49,48,50,48,52,55,49,48,49,43,48,48,57,99,49,49,48,48,49,49,48,51,49,55,100,53,55,49,48,55,48,48,48,49,48,98,48,48,48,48,34,125>>
2020-10-25 21:49:15.659 [debug] <0.11933.5> Supervisor {<0.11933.5>,amqp_channel_sup} started amqp_gen_consumer:start_link(amqp_selective_consumer, [], {<<"client 172.17.0.3:56525 -> 95.110.131.118:5672">>,2}) at pid <0.11934.5>
2020-10-25 21:49:15.659 [debug] <0.11933.5> Supervisor {<0.11933.5>,amqp_channel_sup} started amqp_channel:start_link(network, <0.11696.5>, 2, <0.11934.5>, {<<"client 172.17.0.3:56525 -> 95.110.131.118:5672">>,2}) at pid <0.11935.5>
2020-10-25 21:49:15.659 [debug] <0.11933.5> Supervisor {<0.11933.5>,amqp_channel_sup} started rabbit_writer:start_link(#Port<0.74279>, 2, 131072, rabbit_framing_amqp_0_9_1, <0.11935.5>, {<<"client 172.17.0.3:56525 -> 95.110.131.118:5672">>,2}) at pid <0.11936.5>
The publication queue is: LoRaWan.gateway.apps.station.data.upload
While with the MQTT protocol it works correctly.
Thank you very much for helping