This question is related to this one after you helped me to fix my mistake I have connected to Eclipse broker, it worked just fine, connection and publishing, then I switched to AWS IoT broker with this code

import paho.mqtt.client as mqtt
import RPi.GPIO as GPIO
import time
import ssl
import _thread

GPIO.setup(4, GPIO.IN)

# Define Variables
MQTT_PORT = 8883
MQTT_TOPIC = "ldr"
MQTT_MSG = "there is a product"
#MQTT_HOST = "iot.eclipse.org"

MQTT_HOST = "xxxxxxx"
THING_NAME = "LDRsensor"
CLIENT_ID ="LDRsensor"
CA_ROOT_CERT_FILE = "xxxxxxx"
THING_CERT_FILE = "xxxxxxxxxxxx"
THING_PRIVATE_KEY = "xxxxxxxxxxx"

# Define on_publish event function
def on_publish(client, userdata, mid):
    print ("Message Published...")

# Initiate MQTT Client
mqttc = mqtt.Client()

# Register publish callback function
mqttc.on_publish = on_publish

# Configure TLS Set
mqttc.tls_set(CA_ROOT_CERT_FILE, certfile=THING_CERT_FILE, keyfile=THING_PRIVATE_KEY, cert_reqs=ssl.CERT_REQUIRED, tls_version=ssl.PROTOCOL_TLSv1_2, ciphers=None)

# Connect with MQTT Broker
print ("Connected Successfully")

def publishMessage(Variable):

    while (1):
        input_value = GPIO.input(4)
        if input_value == 1:
            #print ("message published")

But what I get is that, I can connect successfully but I can not publish the mesages. Is it because of forever loop or there is some thing else.I tried debug method, on line _thread.start_new_thread(publishMessage,("publishMessage",)) i got [Errno 32] Broken pipe what is that mean and how i can fix it?

should i install AWSIoTPythonSDK?

  • Well, I suspect that THING_NAME name is the MQTT client ID that should be defined for sure. – Bence Kaulics Jan 21 '18 at 16:06
  • i already try it but i am still facing the same issue @BenceKaulics – Balsam Qassem Jan 21 '18 at 16:10
  • As I said in my accepted answer to your previous question, I am not sure that this is actually an IoT question. Even if it is, you would probably get better help on Stack OVerflow. We currently have a total of 34 AWS questions on 3 tags, where they have that many ASW-xxx specialized tags with many thousands of questions. Furthermore, this question suits their format - post some code, say what it should do and what it is doing wrongly. I am unsure here, and more interested in getting you an answer than which site you should post on. – Mawg says reinstate Monica Jan 22 '18 at 7:51
  • I started a meta discussion to see what others think – Mawg says reinstate Monica Jan 22 '18 at 7:51
  • Hey please share that ARN which you changed. – Suresh Nov 8 '18 at 7:52

I finally figured out what my mistake is. It was in the ARN Resources of policy I wrote a wrong topic in the end of policy resources line. I wrote ldr instead of LDRsensor.

  • After 2 days you can accept your own answer, which will help others who read this question in future – Mawg says reinstate Monica Jan 22 '18 at 7:52
  • OK, I will do it – Balsam Qassem Jan 22 '18 at 7:53
  • Good. I am glad to see that you are making progress. Feels good, doesn't it? :-) Please keep an eye on that met-question to see where you can get the best help. – Mawg says reinstate Monica Jan 22 '18 at 7:56
  • 1
    yeah, i am really comfortable now, ok, you are right – Balsam Qassem Jan 22 '18 at 7:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.