I have been able to get the Pico LTE to connect with ThinkSpeak and publish data without issue. But many users including myself would need to use a self-hosted generic Mosquitto server. I have been unable to get this to work. Unfortunately all the supplied solutions are for commercial server solutions. Any plans to include code for a generic self hosted MQTT server? This would be most helpful. Thanks! Nice device!
Apart from the apps provided, there are options to use the modules such as HTTP and MQTT by their own – with your desired server, data, method etc. You can check out the MQTT module for your Mosquitto server in here: https://github.com/sixfab/pico_lte_micropython-sdk/blob/master/pico_lte/modules/mqtt.py
I guess you could use:
# Open a MQTT connection. pico.mqtt.open_connection(YOUR_HOST, YOUR_PORT) # Login to broker. pico.mqtt.connect_broker(username=YOUR_USERNAME, password=YOUR_PASSWORD) # Publish a message. pico.mqtt.publish_message("SOME_MESSAGE", topic=TOPIC_TO_PUBLISH) # Subscribe to topics topics = [(SUBSCRIPTION_ADDR, QoS_VALUE)] pico.mqtt.subscribe_topics(topics) # Read messages first_time = time.time() while time.time() - first_time < TIMEOUT_SEC: result = pico.mqtt.read_messages() print(result["messages"]) # Unsubscribe from the topics modem.mqtt.unsubscribe_topic(SUBSCRIPTION_ADDR) # Close connection modem.mqtt.close_connection()
It’s an example. Remember to check the result statuses of each function you use.
Thanks so much electricalgorithm! That was really helpful in getting me started. I got the publishing working perfectly. Had to tweak the mqtt.py a bit. Now I’ll start on the subscribe. This is a really nice device.