Sorry missed your reply since I'm signed up for digest emails. In reference to this:
> Hi Tony,
>
> publish.single() and multiple() do use loop_forever() which will block
> "forever", but they use callbacks to break out of this. The
> _on_publish() callback calls disconnect() when all of the messages
> have been sent, and this (should) cause it to drop out of the
> loop_forever() call.
>
> If that isn't working for you, can you describe something about your
> setup? (OS, Python version, ...)
>
> Cheers,
>
> Roger
Here's my setup:
Broker server: mosquitto v1.3.1 running on an Ubuntu 14.04 LTS server image on Amazon EC2. Broker is using the stock mosquitto config but with TLS enabled and a self-signed cert being used for TLS.
On another machine I subscribed to a topic using mosquitto_sub (just a simple 'hello/world' topic). On the Rasbperry Pi I ran this simple script to test sending a message to the hello world topic:
import ssl
import paho.mqtt.publish as publish
tls = { 'ca_certs': '/etc/mosquitto/ca_certificates/mqtt_ca.crt',
'certfile': '/etc/mosquitto/certs/mqtt_client.crt',
'keyfile': '/etc/mosquitto/certs/mqtt_client.key',
'tls_version': ssl.PROTOCOL_TLSv1 }
publish.single('hello/world',
payload='hello world',
port=8883,
tls=tls)