AutoPi with Alexa - Receiving MQTT messge failed

Thank you for your support!

Subject of the issue

I installed Amazon Alexa AVS on my autopi to control my car with my voice.
The Alexa works properly.
And then, I installed paho-mqtt and wrote mqtt client program below. The program works.
It can subscribe to a topic and publish a message to the topic but can not receive any message from mqtt broker. So I checked /etc/iptables/rules.v4 file and add new rule like below.
But message can not still be received from the mqtt broker.
I used port 19418 for mqtt communication.

mqtt client

import os
import configparser
try:
from urllib.parse import urlparse
except ImportError:
from urlparse import urlparse
import paho.mqtt.client as mqtt
import subprocess

Define event callbacks

def on_connect(client, userdata, flags, rc):
print("rc: " + str(rc))

def n_messagoe(client, obj, msg):
print(msg.topic + " " + str(msg.qos) + " " + str(msg.payload))

if int(msg.payload) == 1:
    checker()
    subprocess.call(["aplay","./piano2.wav"])
else:
	print("Unknown value")

def on_publish(client, obj, mid):
print("mid: " + str(mid))

def on_subscribe(client, obj, mid, granted_qos):
print("Subscribed: " + str(mid) + " " + str(granted_qos))

def on_log(client, obj, level, string):
print(string)
#call back
def checker():
print(“callback works”)

client = mqtt.Client()

Assign event callbacks

client.on_message = on_message
client.on_connect = on_connect
client.on_publish = on_publish
client.on_subscribe = on_subscribe

Uncomment to enable debug messages

#client.on_log = on_log

Get CLOUDMQTT settings from config.ini

CONFIG = configparser.ConfigParser()
CONFIG.read(‘config.ini’)
CONFIG_MQTT = CONFIG[‘Cloudmqtt’]
TOPIC = CONFIG_MQTT[‘TOPIC’]
FIRST_MESSAGE = CONFIG_MQTT[‘MESSAGE’]

Connect

client.username_pw_set(CONFIG_MQTT[‘USER’], CONFIG_MQTT[‘PASSWORD’])
client.connect(CONFIG_MQTT[‘CLOUDMQTT_URL’], int(CONFIG_MQTT[‘PORT’]))

Start subscribe, with QoS level 0

client.subscribe(TOPIC, 0)

Publish a message

client.publish(TOPIC, FIRST_MESSAGE)

Continue the network loop, exit when an error occurs

rc = 0
while rc == 0:
rc = client.loop()
print("rc: " + str(rc))

Your environment

iptables -L -n

ifconfig -a

  • What version is the dongle? (Find on software state page on my.autopi.io)

Steps to reproduce

Tell us how to reproduce this issue.

Expected behaviour

Tell us what you expect should happen

Actual behaviour

Tell us what happens instead

Output of power.status command

If your issue is in any way related to the device shutting down or behaving in a unexpected way, please provide the output of the power.status command to help us diagnose the issue.

Run the command

power.status

in the terminal on local.autopi.io, and paste the result here.

Do’s & dont’s

  • Do not write your unit-id anywhere.