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. Jan 21, 2018 at 16:06
  • i already try it but i am still facing the same issue @BenceKaulics Jan 21, 2018 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. Jan 22, 2018 at 7:51
  • I started a meta discussion to see what others think Jan 22, 2018 at 7:51
  • Hey please share that ARN which you changed.
    – Suresh
    Nov 8, 2018 at 7:52

1 Answer 1


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.


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.