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 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) -
You have to call either
client.wait_msg()orclient.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 -
@this.wiederkehr Thanks, I will try that later tonight.
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