2017-04-18 3 views
1

나는 모스 닛토 브로커가있는 라즈베리를 가지고 있고 아마존 IoT 서비스로 연결되어있다. https://aws.amazon.com/es/blogs/iot/how-to-bridge-mosquitto-mqtt-broker-to-aws-iot/지속성을 사용하는 mosquitto MQTT 브로커를 amazon IoT 서비스로 변환

이 내 mosquitto.conf 파일입니다

# Place your local configuration in /etc/mosquitto/conf.d/ 
# 
# A full description of the configuration file is at 
# /usr/share/doc/mosquitto/examples/mosquitto.conf.example 

pid_file /var/run/mosquitto.pid 

persistence true 
persistence_location /var/lib/mosquitto/ 

log_dest file /var/log/mosquitto/mosquitto.log 

include_dir /etc/mosquitto/conf.d 

# ================================================================= 
# Bridges to AWS IOT 
# ================================================================= 

# AWS IoT endpoint, use AWS CLI 'aws iot describe-endpoint' 
connection awsiot 
address xxxxxxxxx.iot.eu-central-1.amazonaws.com:8883 

# Specifying which topics are bridged 
topic awsiot_to_localgateway in 1 
topic localgateway_to_awsiot/iot out 1 
topic both_directions both 1 

# Setting protocol version explicitly 
bridge_protocol_version mqttv311 
bridge_insecure false 

# Bridge connection name and MQTT client Id, 
# enabling the connection automatically when the broker starts. 
cleansession true 
clientid bridgeawsiot 
start_type automatic 
notifications false 
log_type all 

# ================================================================= 
# Certificate based SSL/TLS support 
# ----------------------------------------------------------------- 
#Path to the rootCA 
bridge_cafile /etc/mosquitto/certs/rootCA.pem 

# Path to the PEM encoded client certificate 
bridge_certfile /etc/mosquitto/certs/cert.crt 

# Path to the PEM encoded client private key 
bridge_keyfile /etc/mosquitto/certs/private.key 

모든 작품을 잘 /etc/mosquitto/conf.d 내부에있는 bridge.conf이다. 하지만, 만약 내가 이더넷 케이블을 제거하여 페니스를 테스트하십시오. 통신이 다시 시작될 때. 브로커는 amazon IoT 서비스에 반복적 인 메시지를 보냅니다.

이것은 내가

char dataToSend[] = "Message Id: "; 
counter++; 

snprintf(dataToSend, sizeof(dataToSend) + 10, "Message Id: %d", counter); 
app_mqtt_publish(&dataToSend); 

이 정상적인 행동인가를 보낸다 메시지는?

+0

해당 구성에서 브리지의 세부 정보를 포함하지 않았습니다. 또한 어떤 종류의 메시지를 보내고 있습니까? QOS는 무엇입니까? – hardillb

+0

죄송합니다. @hardillb ... 질문이 수정되었습니다. QOS는 1입니다. – JosepB

답변

2

(의 일부) MQTT 사양의 짧은 버전 :

  • QOS 0 -> 메시지
  • QOS 1 전달 될 수있다 - 메시지는 적어도 한번 전달한다>를
  • QOS 2 - > 메시지는 한 번만 배달됩니다.

메시지가 수신 확인되지 않은 경우 QOS 1 메시지가 다시 배달 될 가능성이 있습니다. 수신 브로커가 전달되었을 수 있으므로 헤더에 DUP 플래그가 설정되어 있어야합니다.

IIRC AWS-IoT는 QOS 2를 지원하지 않으므로이 문제를 해결할 수 있습니다.

+0

10 초 후에, 보존 된 메시지가 삭제됩니다. 짧은 시간 동안 통신이 끊어지면 대기열에있는 메시지가 전송되기 때문입니다. 그러나 내가 1 분 이상 comunications을 잃어 버리면 아마 IOT에 메시지를받지 못하기 때문에 대기열에있는 모든 메시지가 삭제 된 것으로 보인다. – JosepB

0

AWS IoT는 cleansession false을 지원하지 않습니다. 다리에 대한 결과는 때이다 :

  • 당신이 메시지를 보내는 오류가
  • 하고 persistence true
  • 을 가지고 효과적으로
  • 를 분리하지 않았고 QoS를> 0 또는 QoS를 = 0이면 queue_qos0_messages true

=> 메시지가 db에 저장됩니다.

그러나 클라이언트가 브리지에 자동으로 연결을 끊으면 실제로 연결이 끊어 지므로 cleansession true은 데이터를 유지하지 않도록 브로커에 알리고이 클라이언트의 db를 지 웁니다.

소원 당신이 cleansession false를 보낼 때 AWS의 IoT는 분리하지 않았다, 그래서 우리는 ...

추신이 로컬 캐시를 유지할 수 있다는 : "자동 다리로 설정 클라이언트가"입니다, 당신은 다리를 설정할 때 두 브로커간에 클라이언트는 하나의 브로커에 가입하고 항상 다른 브로커에 게시하도록 생성됩니다.

관련 문제