MQTTSubscribe and Array of String data

148 views
Skip to first unread message

storm...@gmail.com

unread,
Aug 12, 2021, 10:04:43 PM8/12/21
to weewx-user
Is it possible for MQTTSubscribe to process array of string data as shown below.

Aug 12 21:27:40 raspberrypi weewx[18618] DEBUG user.MQTTSubscribe: (Service) MessageCallbackProvider data-> incoming topic: Alerts/NWS/, QOS: 0, retain: 0, payload: b'{"alert_NWS0":"Current Watches, Warnings and Advisories for Allegheny (PAC003) Pennsylvania Issued by the National Weather Service","alert_NWS1":"Severe Thunderstorm Warning issued August 12 at 8:39PM EDT until August 12 at 9:30PM EDT by NWS","alert_NWS2":"Flash Flood Warning issued August 12 at 8:36PM EDT until August 12 at 11:45PM EDT by NWS","alert_NWS3":"Flash Flood Warning issued August 12 at 8:32PM EDT until August 12 at 10:30PM EDT by NWS","alert_NWS4":"Severe Thunderstorm Watch issued August 12 at 7:48PM EDT until August 12 at 10:00PM EDT by NWS"}'


bell...@gmail.com

unread,
Aug 13, 2021, 10:12:32 PM8/13/21
to weewx-user
The short answer is no. 
But that data looks a lot like json to me … Because you are dealing with text, you will want to set conversion_type = None. See, https://github.com/bellrichm/WeeWX-MQTTSubscribe/wiki/Configuring#conversion_type You will also do some WeeWx configuration related to accumulators. See, https://github.com/bellrichm/WeeWX-MQTTSubscribe/wiki/Configuring#conversion_type

If it is not json, I suppose you could read it as a ‘individual’ payload and have a service post process it.

The final option is to write a custom parser. This is still experimental and would probably be more work than a standalone service to post process. A bit of information is here, https://github.com/bellrichm/WeeWX-MQTTSubscribe/wiki/Handling-different-MQTT-message-formats

rich

storm...@gmail.com

unread,
Aug 13, 2021, 10:57:41 PM8/13/21
to weewx-user
Rich...Thanks for the effort you put into this and for the info.  Yes, the data is in json format and I do have the  conversion_type = None.  I need to read up on the accumulators and the message formats.

storm...@gmail.com

unread,
Aug 14, 2021, 5:36:51 PM8/14/21
to weewx-user
Yes, it is possible  to process array of string data as shown below.

Aug 12 21:27:40 raspberrypi weewx[18618] DEBUG user.MQTTSubscribe: (Service) MessageCallbackProvider data-> incoming topic: Alerts/NWS/, QOS: 0, retain: 0, payload: b'{"alert_NWS0":"Current Watches, Warnings and Advisories for Allegheny (PAC003) Pennsylvania Issued by the National Weather Service","alert_NWS1":"Severe Thunderstorm Warning issued August 12 at 8:39PM EDT until August 12 at 9:30PM EDT by NWS","alert_NWS2":"Flash Flood Warning issued August 12 at 8:36PM EDT until August 12 at 11:45PM EDT by NWS","alert_NWS3":"Flash Flood Warning issued August 12 at 8:32PM EDT until August 12 at 10:30PM EDT by NWS","alert_NWS4":"Severe Thunderstorm Watch issued August 12 at 7:48PM EDT until August 12 at 10:00PM EDT by NWS"}'

I made the assumption that a county will not have more than 9 alerts at one time. 

 [[topics]]
.
.
.
 [[[Alerts/NWS/]]]
            
            [[[[alert_NWS0]]]]
               name = alert_0
               conversion_type = None
               
            [[[[alert_NWS1]]]]
               name = alert_1
               conversion_type = None
               
            [[[[alert_NWS2]]]]
               name = alert_2
               conversion_type = None
               
            [[[[alert_NWS3]]]]
               name = alert_3
               conversion_type = None
               
            [[[[alert_NWS4]]]]
               name = alert_4
               conversion_type = None
               
            [[[[alert_NWS5]]]]
               name = alert_5
               conversion_type = None 
               
            [[[[alert_NWS6]]]]
               name = alert_6
               conversion_type = None
               
            [[[[alert_NWS7]]]]
               name = alert_7
               conversion_type = None
               
            [[[[alert_NWS8]]]]
               name = alert_8
               conversion_type = None
           
            [[[[alert_NWS9]]]]
               name = alert_9
               conversion_type = None
               
            [[[[alert_NWS10]]]] 
               name = alert_10
               conversion_type = None 

[Accumulator]

 [[alert_0]]
        accumulator = firstlast
        extractor = last
        
    [[alert_1]]
        accumulator = firstlast
        extractor = last
        
    [[alert_2]]
        accumulator = firstlast
        extractor = last
        
    [[alert_3]]
        accumulator = firstlast
        extractor = last
        
    [[alert_4]]
        accumulator = firstlast
        extractor = last
        
    [[alert_5]]
        accumulator = firstlast
        extractor = last 
        
    [[alert_6]]
        accumulator = firstlast
        extractor = last
        
    [[alert_7]]
        accumulator = firstlast
        extractor = last
        
    [[alert_8]]
        accumulator = firstlast
        extractor = last
        
    [[alert_9]]
        accumulator = firstlast
        extractor = last
        
    [[alert_10]]
        accumulator = firstlast
        extractor = last

Rich Bell

unread,
Aug 14, 2021, 7:46:35 PM8/14/21
to weewx...@googlegroups.com
Nice, thanks for letting me know 

On Aug 14, 2021, at 5:36 PM, storm...@gmail.com <storm...@gmail.com> wrote:

Yes, it is possible  to process array of string data as shown below.
--
You received this message because you are subscribed to the Google Groups "weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to weewx-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/20097a01-3315-4295-af9f-4929100c7d1an%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages