Working with multiple MQTT servers
Add the following lines to the existing surfboard_monitor.py in the main virtual environment folder. The following lines declare the main block. The code file for the sample is included in the mqtt_python_gaston_hillar_06_01 folder, in the surfboard_monitor.py file:
if __name__ == "__main__":
surfboard = Surfboard(device_id=device_id,
status=SURFBOARD_STATUS_IDLE,
speed_mph=0,
altitude_feet=0,
water_temperature_f=0)
pubnub_client_id = "{}/{}/{}".format(
pubnub_publish_key,
pubnub_subscribe_key,
device_id)
pubnub_client = mqtt.Client(client_id=pubnub_client_id,
protocol=mqtt.MQTTv311)
pubnub_client.on_connect = on_connect_pubnub
pubnub_client.on_disconnect = on_disconnect_pubnub
pubnub_client.connect(host=pubnub_mqtt_server_host,
port=pubnub_mqtt_server_port,
keepalive=pubnub_mqtt_keepalive)
pubnub_client.loop_start()
mosquitto_client...