R
So my bandwidth is not really the problem here. The problem is that the umqtt / simple library is slow in use. When my FiPy is already connected to LTE, and it then tries to connect to Azure IoT Hub, establishing the connection takes around 30 seconds, whereas simply publishing is fast and not a issue at all. So i am currently looking into optimizing / speeding up the connect routine if possible in the simple.py library.
Here is the code i use to connect:
def iot_connect(self):
if self.IoTConnectedFlag == False:
self.password = self.generate_sas_token(self.uri, self.primary_key, self.policy_name)
beforeConn = utime.ticks_us()
self.username_fmt = "{}/{}/api-version=2018-06-30"
self.username = self.username_fmt.format(self.hostname, self.device_id)
self.client = MQTTClient(client_id=self.device_id, server=self.hostname, port=8883, user=self.username, password=self.password, keepalive=4000, ssl=True)
self.client.connect()
print("IoT Connected!")
self.IoTConnectedFlag = True
afterConn = utime.ticks_us()
connDone = afterConn - beforeConn
print(connDone)
the utime.ticks_us() are used to observe how long time the method takes to execute.
Whole method = 28.61 secs
Whole method minus SAS Token generation = 27.27 secs
self.client.connect() = 16.94 secs
Any ideas on how to optimize this speed is very welcome! Thanks
/RM