Wifi RSSI and mqtt subscribe

  • 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
    def trig_reset(arg):
    def sub_cb(topic, msg):
    wlan = WLAN(mode=WLAN.STA)
    wlan.connect("SSID_Name", auth=(WLAN.WPA2, "wifipass"), timeout=5000)
    while not wlan.isconnected():
    print("Connected to Wifi\n")
    wifiaddress = ((str(wlan.ifconfig()[:1]))[2:])[:-3]
    client = MQTTClient("LoPy", "",user="username", password="pass", port=1883)
    client.publish(topic="lopy/ip", msg=wifiaddress)
    button = Pin('P10', mode=Pin.IN, pull=Pin.PULL_UP)
    button.callback(Pin.IRQ_RISING, trig_reset)

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

  • 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:

Pycom on Twitter