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

    Wifi RSSI and mqtt subscribe

    Scheduled Pinned Locked Moved MicroPython
    micropythonmqttwifirssirgb
    3 Posts 2 Posters 1.8k 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.
    • S Offline
      sjp770
      last edited by

      I'm trying to change the RGB led through a simple subscribe and callback but it doesn't seem to be processing the subscribed message.

      I also wanted to publish the current signal strength at boot - is there a way to do this, even if its from a scan before wifi connect?

      Any ideas? Here is my main.py so far:

      from mqtt import MQTTClient
      from machine import Pin
      import machine
      import time
      from network import WLAN
      import pycom
      pycom.heartbeat(False)
      
      def trig_reset(arg):
          machine.reset()
      
      def sub_cb(topic, msg):
         print(msg)
      
      wlan = WLAN(mode=WLAN.STA)
      wlan.connect("SSID_Name", auth=(WLAN.WPA2, "wifipass"), timeout=5000)
      
      while not wlan.isconnected():
          machine.idle()
      print("Connected to Wifi\n")
      wifiaddress = ((str(wlan.ifconfig()[:1]))[2:])[:-3]
      
      client = MQTTClient("LoPy", "192.168.1.15",user="username", password="pass", port=1883)
      
      client.connect()
      client.set_callback(sub_cb)
      client.subscribe(topic="lopy/rgb")
      client.publish(topic="lopy/ip", msg=wifiaddress)
      
      button = Pin('P10', mode=Pin.IN, pull=Pin.PULL_UP)
      button.callback(Pin.IRQ_RISING, trig_reset)
      
      1 Reply Last reply Reply Quote 0
      • T Offline
        this.wiederkehr
        last edited by

        You have to call either client.wait_msg() or client.check_msg() in order to receive messages. The former is blocking whereas the latter is non blocking and has therefore to be called in a loop. See the comments on the mentioned methods in the following file:
        https://github.com/pycom/pycom-libraries/blob/master/examples/mqtt/mqtt.py

        S 1 Reply Last reply Reply Quote 0
        • S Offline
          sjp770 @this.wiederkehr
          last edited by

          @this.wiederkehr Thanks, I will try that later tonight.

          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