Skip to content

starting without mqtt #183

Description

@pan64

If I try to start my esp32 when the mqtt server is offline the connection to mqtt will crash with an exception (no connection), the app cannot start at all.
If mqtt is lost later it can recover, that works perfectly, but you know, the situation is that after a power outage, the ESP32 boots up much faster than the router or the MQTT server.
Currently I have a simple workaround, trying to connect in an endless loop, like this (see example 2.3):

    async def connect(self):                                                                                                                                                                        
        """connect to broker"""                                                                                                                                                                     
        while True:                                                                                                                                                                                 
            try:                                                                                                                                                                                    
                await self.client.connect()                                                                                                                                                         
                for coroutine in (self.up, self.messages):                                                                                                                                          
                    asyncio.create_task(coroutine())                                                                                                                                                
                return                                                                                                                                                                              
            except Exception as e:                                                                                                                                                                  
                sys.print_exception(e)                                                                                                                                                              
                syslog.error("cannot connect to mqtt broker")                                                                                                                                       
            asyncio.sleep_ms(10)      

But I think it is ugly and resilience is already there (somewhere).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions