0

Publishing null to feed in group with /get does not work?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Publishing null to feed in group with /get does not work?

by KarelKotrba on Thu Mar 07, 2019 12:08 pm

Hello,

I am running into a problem which I am not able to solve despite a lot of experiments:

If there is a feed defined in a group (i.e. "username/feed/mygroup.out1"), the device is subscribed to this feed and I send NULL to feed "username/feed/mygroup.out1/get" I am not able to read the last value back as suggested by documentation.

On opposite, if the feed is "username/feed/out1" and is in "Default" group, publishing NULL to "username/feed/out1/get" brings back the last value perfectly with no problem.

Any suggestions wellcome,
Thanks
Karel

KarelKotrba
 
Posts: 2
Joined: Tue Jan 29, 2019 5:20 am

Re: Publishing null to feed in group with /get does not work

by indroth on Fri Mar 22, 2019 1:47 am

I have the same problem.

Here is some test code that passes for the ungrouped feed (indroth/f/test), but fails for the grouped feed (indroth/f/phoenix.power):

Code: Select all | TOGGLE FULL SIZE
import paho.mqtt.client as mqtt
import unittest
from parameterized import parameterized
import time

class FeedTest(unittest.TestCase):
       
    @parameterized.expand(["indroth/f/test", "indroth/f/phoenix.power"])
    def testFeed(self, topic):
        lastMessage = {}
        published = False

        # The callback for when the client receives a CONNACK response from the server.
        def on_connect(client, userdata, flags, rc):
            print("Connected with result code "+str(rc))
            client.subscribe(topic)

        # The callback for when a PUBLISH message is received from the server.
        def on_message(client, userdata, msg):
            print(msg.topic+" "+str(msg.payload))
            lastMessage[msg.topic] = msg.payload

        def on_subscribe(client, userdata, mid, qos):
            print("subscribed")
            client.publish(topic + "/get", "")

        def on_publish(client, userdata, mid):
            print("published")
            published = True

        client = mqtt.Client()
        client.on_connect = on_connect
        client.on_message = on_message
        client.on_subscribe = on_subscribe
        client.on_publish = on_publish
        client.tls_set()
        client.username_pw_set("indroth", "xxx")
        client.loop_start()
        client.connect("io.adafruit.com", 8883, 60)
       
        for _ in range(5):
            if published:
                break
            time.sleep(1)

        for _ in range(5):
            if topic:
                break
            time.sleep(1)
           
        self.assertIn(topic, lastMessage)   
   
        client.loop_stop()


This is the output:

Code: Select all | TOGGLE FULL SIZE
$ python3 -m unittest -v adafruit_get_test.py
testFeed_0_indroth_f_test (adafruit_get_test.FeedTest) ... Connected with result code 0
subscribed
published
indroth/f/test b'ON'
ok
testFeed_1_indroth_f_phoenix_power (adafruit_get_test.FeedTest) ... Connected with result code 0
subscribed
published
FAIL

======================================================================
FAIL: testFeed_1_indroth_f_phoenix_power (adafruit_get_test.FeedTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/shounak/.local/lib/python3.6/site-packages/parameterized/parameterized.py", line 518, in standalone_func
    return func(*(a + p.args), **p.kwargs)
  File "/srv/store/work/adafruit_get_test.py", line 51, in testFeed
    self.assertIn(topic, lastMessage)
AssertionError: 'indroth/f/phoenix.power' not found in {}

----------------------------------------------------------------------
Ran 2 tests in 11.414s

FAILED (failures=1)

indroth
 
Posts: 1
Joined: Wed Jan 09, 2019 8:03 pm

Please be positive and constructive with your questions and comments.


cron