I coded an Android application for publishing and suscribing to Mosquitto broker using MQTT paho library and I tested it under different scenarios.
I've already tested my application and it works perfectly in a LAN scenario, but it doesn't work anymore when the message comes from remote. I've also configured the forwarding ports on the router of the IoT device network.
The problem is when publishing a message to IoT device (Pico-pi-iMX7 with Android Things running on it), and the message is being sent from remote broker.
I tested recieving the message on a computer under the same network as the IoT device by the forwarding rules and it works. Since the device is unix-based, I used iptables to be sure to accept all the network traffic with the following comands as super user:
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -A INPUT -p tcp -sport 1883 -j ACCEPT
When I send the message, I get the following error:
Error: Cannot establish a connection with the target - Connection refused.
Any ideas?