Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    is pycom.rgbled thread safe?

    Scheduled Pinned Locked Moved WiPy 2&3
    threadaws mqttmqtt
    1 Posts 1 Posters 315 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M Offline
      Martinnn
      last edited by

      I modified the Pycom AWS MQTT library and put an LED blink into the transmit routine:

              self._out_packet_mutex.acquire()
              if self._ping_failures == 0:
                  if self._out_packet_mutex.locked() and len(self._output_queue) > 0:
                      packet=self._output_queue[0]
                      pycom.rgbled(0xff0000) # red
                      if self._send_packet(packet):
                          self._output_queue.pop(0)
                          if self.wdt is not None:
                              self.wdt.feed()
                          pycom.rgbled(0x000010) # dark blue
              self._out_packet_mutex.release()
      

      Also, I feed the WDT here so the Wipy gets a reset in case of a connection loss. As the MQTT library starts a thread for this transmit routine and I also set the LED from the main code (running in parallel), could there be the case that the main code is interrupted while executing a pycom.rgbled and then pycom.rgbled be called in the transmit thread? Is it safe to do so? Or would I need to encapsulate the LED update with another mutex?

      1 Reply Last reply Reply Quote 0

      Hello! It looks like you're interested in this conversation, but you don't have an account yet.

      Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

      With your input, this post could be even better 💗

      Register Login
      • 1 / 1
      • First post
        Last post

      Pycom on Twitter

      Pycom