Storm et al.,
I have attempted to setup my node-red and weewx.conf according to your 
email. I'm still getting errors which I have attached.  My weewx.conf file:
##############################################################################
# Options for 'MQTTSubscribeService'
[MQTTSubscribeService]
        enable = true    # false
    # The MQTT server.
    
    host = 192.168.1.10    [this is the LoRa server, N-R is running on the 
weewx machine 192.168.1.119. Should N-R be on the LoRa server?]
       port = 1883
       keepalive = 60
        username = None #admin    #None
       password = None  #admin    #None
        binding = loop

       [[message_callback]]
        
        type = json    #REPLACE_ME

    # The application/18/device/2cf7f12122500013/rx  topics to subscribe to.
    [[topics]]
                unit_system = US
        [[[application/18/device/2cf7f12122500013/rx]]]

        #data  sent from RAK7244
        #ignore = true
                [[[[CO2_Value_PPM]]]]
        #weewx db field name
                name = co2
                ignore = false
                contains total = false
                conversion type = float
                #units = ppm
        #[[[SECOND/REPLACE_ME]]]

The function in N-R seems to be putting out the correct data 
"CO2_Value_PPM: 404" but something isn't connecting properly.
Even though N-R (on weewx machine) says it's sending the parsed data, it 
seems to getting the whole data set. Should I be running
N-R on the LoRa server where the data is coming from? 
Sorry for the naive questions but I'm really not a programmer (but 
learning!)
Much appreciated for the help from everyone!
Cheers,
Bob


On Sunday, November 28, 2021 at 7:09:31 PM UTC-5 bell...@gmail.com wrote:

> OK, assuming (and you know what happens when one assumes) that your 
> payload is:
> {
>    "CO2_Value_PPM": 430
> }
>
> And yout topic is:
> application/18/device/2cf7f12122500013/rx
>
> Then this should work:
>     [[topics]]
>         [[[application/18/device/2cf7f12122500013/rx]]]
>     [[[[CO2_Value_PPM]]]]
>         name = co2
>
> If it doesn't, post the debug log.
> rich
>
>
> On Sunday, 28 November 2021 at 15:50:53 UTC-5 bgra...@umw.edu wrote:
>
>> Thanks for the replies. Here is where I am.
>>
>> bg@n4mrv:~$ mosquitto_sub -t application/18/device/2cf7f12122500013/rx -h 
>> 192.168.1.10 | jq .
>> {
>>   "applicationID": "18",
>>   "applicationName": "CO2app",
>>   "deviceName": "CO2device",
>>   "devEUI": "2cf7f12122500013",
>>   "txInfo": {
>>     "frequency": 905300000,
>>     "dr": 0
>>   },
>>   "adr": true,
>>   "fCnt": 226,
>>   "fPort": 2,
>>   "data": "AQQQsI8GAF5I",
>>   "object": {
>>     "err": 0,
>>     "messages": [
>>       {
>>         "CO2_Value_PPM": 430,
>>         "measurementId": 4100,
>>         "type": "report_telemetry"
>>       }
>>     ],
>>     "payload": "010410B08F06005E48",
>>     "valid": true
>>   }
>> }
>>
>>
>> I was using node-red but thought it was conflicting with something else 
>> on Mosquitto-subscribe-weewx so I turned it off. I wasn't sure how to 
>> connect weewx to the output of n-r.
>>
>> When setting the CO2 sensor up with emoncms (another server) a kind and 
>> knowledgeable soul gave me the following code for a function in n-r:
>> ```
>> // Test to see if CO2 measurement is present in uplink // Assumption is 
>> msg.payload.object.messages[] array is always present // if not then we 
>> need to test in different way // why do we do this to ensure we don't send 
>> rubbish to emoncms if ("CO2_Value_PPM" in msg.payload.object.messages[0]){ 
>> msg = 
>> {payload:{"CO2_Value_PPM":msg.payload.object.messages[0].CO2_Value_PPM}}; 
>> return msg; }
>> ```
>> This cut down the extra data and produced something like:  "CO2_Value_PPM: 
>> 430" other data was omitted.
>> You may have an idea about connecting n-r.
>> Cheers,
>> Bob
>>
>> On Sunday, November 28, 2021 at 2:21:01 PM UTC-5 bell...@gmail.com wrote:
>>
>>> From the log extract, this what I see as the payload
>>>
>>> {
>>>     "applicationID": "18",
>>>     "applicationName": "CO2app",
>>>     "deviceName": "CO2device",
>>>     "devEUI": "2cf7f12122500013",
>>>     "txInfo": {
>>>         "frequency": 903900000,
>>>         "dr": 0
>>>     },
>>>     "adr": true,
>>>     "fCnt": 220,
>>>     "fPort": 2,
>>>     "data": "AQQQaJsGAAqz",
>>>     "object": {
>>>         "err": 0,
>>>         "messages": [
>>>             {
>>>                 "CO2_Value_PPM": 433,
>>>                 "measurementId": 4100,
>>>                 "type": "report_telemetry"
>>>             }
>>>         ],
>>>         "payload": "010410689B06000AB3",
>>>         "valid": true
>>>     }
>>> }
>>>
>>> On Sunday, 28 November 2021 at 14:07:59 UTC-5 vince wrote:
>>>
>>>> Agree.  Pre-process it to a format that works with weewx.
>>>>
>>>> Again, can you give us a vanilla "mosquitto_sub -t whatever -h 
>>>> the_host" output so we can see what you have a little more clearly ?   
>>>> Piping it to " |  jq . " sometimes helps show the nesting and 
>>>> structure a little better for the eyes.
>>>>
>>>> On Sunday, November 28, 2021 at 10:51:17 AM UTC-8 storm...@gmail.com 
>>>> wrote:
>>>>
>>>>> Since you are using Node Red, a possible solution is to use a Change 
>>>>> Node and delete the payload that you don't want to include in weewx.
>>>>>
>>>>> On Sunday, November 28, 2021 at 1:41:56 PM UTC-5 bell...@gmail.com 
>>>>> wrote:
>>>>>
>>>>>> I looked more closely at the payload format and I don't think that 
>>>>>> format is currently supported. specifically the 'nested array'..
>>>>>>
>>>>>> "object":{"err":0,"messages":[{"CO2_Value_PPM":433,"measurementId":4100,"type":"report_telemetry"}]
>>>>>> Busy time of the year, so not sure when I'll have time to delve into 
>>>>>> a solution.
>>>>>> rich
>>>>>> On Sunday, 28 November 2021 at 12:22:22 UTC-5 bell...@gmail.com 
>>>>>> wrote:
>>>>>>
>>>>>>>
>>>>>>> Bob,
>>>>>>> Since you have a lot of fields that you want to ignore, try setting 
>>>>>>> the ignore flag to true at the 'topic' level. Also I don’t think you 
>>>>>>> want 
>>>>>>> to set contains_total.  So you would end up with something like this, 
>>>>>>>     [[topics]]
>>>>>>>         [[[application/18/device/2cf7f12122500013/rx]]]
>>>>>>>             ignore = true
>>>>>>>     [[[[CO2_Value_PPM]]]]
>>>>>>>         name = co2
>>>>>>>                         ignore = false
>>>>>>>
>>>>>>> Since the data is published so infrequently, once you get the basic 
>>>>>>> configuration working, you might want to look into the expires_after 
>>>>>>> option. This will cache the value between publications. For additional 
>>>>>>> information see, 
>>>>>>> https://github.com/bellrichm/WeeWX-MQTTSubscribe/wiki/Configuring-additional-options#expires_after
>>>>>>>
>>>>>>> rich
>>>>>>>
>>>>>>> On Sunday, 28 November 2021 at 11:21:43 UTC-5 bgra...@umw.edu wrote:
>>>>>>>
>>>>>>>> Thanks for coming back so soon with help Storm and Vince.
>>>>>>>> I am attaching three things in a .txt file rather than pasting in 
>>>>>>>> as the format seems messy and I'm not sure how to make it easier to 
>>>>>>>> read.
>>>>>>>>
>>>>>>>> 1.  My modified section of weewx.conf . Among other things, there 
>>>>>>>> seems to be a problem with float.
>>>>>>>>
>>>>>>>> 2.  The data sent from the LoRa server when I subscribe 
>>>>>>>> to applications/18/devices/2cf7f12122500013/rx  (using MQTT-explorer). 
>>>>>>>> Lots 
>>>>>>>> of unneeded things  but it contains the CO2_Value_PPM data.
>>>>>>>>
>>>>>>>> 3.  A listing of weewx.log in debug mode showing the problems (I 
>>>>>>>> hope). The data seems to be getting there but is not being parsed out 
>>>>>>>> for 
>>>>>>>> what I need.
>>>>>>>>
>>>>>>>> Hopefully this will give you an idea of what's going on.  Thanks 
>>>>>>>> again for your help.
>>>>>>>> Bob
>>>>>>>>
>>>>>>>> On Saturday, November 27, 2021 at 5:36:51 PM UTC-5 vince wrote:
>>>>>>>>
>>>>>>>>> My example:
>>>>>>>>>
>>>>>>>>> [MQTTSubscribeService]
>>>>>>>>>     enable = True
>>>>>>>>>     host = 192.168.1.171
>>>>>>>>>     port = 1883
>>>>>>>>>     keepalive = 60
>>>>>>>>>     username = None
>>>>>>>>>     password = None
>>>>>>>>>     binding = loop
>>>>>>>>>     [[message_callback]]
>>>>>>>>>         type = json
>>>>>>>>>     [[topics]]
>>>>>>>>>         unit_system = US
>>>>>>>>>         #
>>>>>>>>>         #--- these are emitted every 5 minutes ---
>>>>>>>>>         # mosquitto_sub -t BaseballRoomConditions -h nuc2
>>>>>>>>>         #     {"dateTime": 1621715702, "extraTemp1": 63.16, 
>>>>>>>>> "extraTemp2": 63.5, "pi": 100.28}
>>>>>>>>>         #
>>>>>>>>>         [[[BaseballRoomConditions]]]    <=== the topic to 
>>>>>>>>> subscribe to
>>>>>>>>>             [[[[dateTime]]]]            <=== the element in that 
>>>>>>>>> topic
>>>>>>>>>                 ignore = True           <=== optionally ignore 
>>>>>>>>> this item within the topic
>>>>>>>>>             [[[[extraTemp1]]]]
>>>>>>>>>                 name = extraTemp1       <=== db element to map the 
>>>>>>>>> item to
>>>>>>>>>                 units = degree_F        <=== its units
>>>>>>>>>             [[[[extraTemp2]]]]
>>>>>>>>>                 name = extraTemp2
>>>>>>>>>                 units = degree_F
>>>>>>>>>             [[[[pi]]]]
>>>>>>>>>                 ignore = True
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On Saturday, November 27, 2021 at 2:26:46 PM UTC-8 
>>>>>>>>> storm...@gmail.com wrote:
>>>>>>>>>
>>>>>>>>>>  I believe you need to add the topic you subscribing to in 
>>>>>>>>>> [[[first/topic]]]. 
>>>>>>>>>>
>>>>>>>>>> Example:
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> ##########################################################################################
>>>>>>>>>>   #              Acurite-5n1 Sensors
>>>>>>>>>>   #              SDR # 1 
>>>>>>>>>>   #              433 MHz
>>>>>>>>>>   
>>>>>>>>>> ##########################################################################################
>>>>>>>>>>   
>>>>>>>>>>      
>>>>>>>>>>
>>>>>>>>>>         
>>>>>>>>>>         [[[Acurite-Tower/8785/]]]
>>>>>>>>>>            
>>>>>>>>>>            [[[[temperature_F]]]]
>>>>>>>>>>             name = extraTemp7
>>>>>>>>>>             ignore = False
>>>>>>>>>>             contains_total = False
>>>>>>>>>>             conversion_type = float
>>>>>>>>>>             units = degree_F
>>>>>>>>>>
>>>>>>>>>> On Saturday, November 27, 2021 at 5:15:24 PM UTC-5 
>>>>>>>>>> bgra...@umw.edu wrote:
>>>>>>>>>>
>>>>>>>>>>> Hello,
>>>>>>>>>>> I'm running a RAK7244 LoRaWAN server/gateway on a local network 
>>>>>>>>>>> to which my weewx server is connected. Weeex is the latest stable 
>>>>>>>>>>> on Ubuntu 
>>>>>>>>>>> with extended db.
>>>>>>>>>>>
>>>>>>>>>>> A CO2 sensor is sending data to the LoRa server. I have node-red 
>>>>>>>>>>> on my weewx server with a flow  connecting to the RAK7244. I want 
>>>>>>>>>>> to have 
>>>>>>>>>>> the CO2 data put into the co2 slot that is available on the weewx 
>>>>>>>>>>> db.
>>>>>>>>>>>
>>>>>>>>>>> I have installed the weewx extension Mosquitto-subscribe and 
>>>>>>>>>>> attempted to configure weewx.conf as:
>>>>>>>>>>> #################################################
>>>>>>>>>>> # Options for 'MQTTSubscribeService'
>>>>>>>>>>> [MQTTSubscribeService]
>>>>>>>>>>>     # This section is for the MQTTSubscribe service.
>>>>>>>>>>>         # Turn the service on and off.
>>>>>>>>>>>     # Default is: true
>>>>>>>>>>>     # Only used by the service.
>>>>>>>>>>>     enable = true    # false
>>>>>>>>>>>     
>>>>>>>>>>>     # The MQTT server.
>>>>>>>>>>>     # Default is localhost.
>>>>>>>>>>>     host = localhost  #192.168.1.10    #localhost
>>>>>>>>>>>     
>>>>>>>>>>>     # The port to connect to.
>>>>>>>>>>>     # Default is 1883.
>>>>>>>>>>>     port = 1883
>>>>>>>>>>>     
>>>>>>>>>>>     # Maximum period in seconds allowed between communications 
>>>>>>>>>>> with the broker.
>>>>>>>>>>>     # Default is 60.
>>>>>>>>>>>     keepalive = 60
>>>>>>>>>>>     
>>>>>>>>>>>     # username for broker authentication.
>>>>>>>>>>>     # Default is None.
>>>>>>>>>>>     username = None
>>>>>>>>>>>     
>>>>>>>>>>>     # password for broker authentication.
>>>>>>>>>>>     # Default is None.
>>>>>>>>>>>     password = None 
>>>>>>>>>>>     
>>>>>>>>>>>     # The binding, loop or archive.
>>>>>>>>>>>     # Default is: loop
>>>>>>>>>>>     # Only used by the service.
>>>>>>>>>>>     binding = loop
>>>>>>>>>>>     
>>>>>>>>>>>     # The message handler to use
>>>>>>>>>>>     [[message_callback]]
>>>>>>>>>>>         # The format of the MQTT payload.
>>>>>>>>>>>         # Currently support: individual, json, keyword
>>>>>>>>>>>         # Must be specified.
>>>>>>>>>>>         type = json    #REPLACE_ME
>>>>>>>>>>>     
>>>>>>>>>>>     # The application/18/device/2cf7f12122500013/rx  topics to 
>>>>>>>>>>> subscribe to.
>>>>>>>>>>>     [[topics]]
>>>>>>>>>>>         # Units for MQTT payloads without unit value.
>>>>>>>>>>>         # Valid values: US, METRIC, METRICWX
>>>>>>>>>>>         # Default is: US
>>>>>>>>>>>         unit_system = US
>>>>>>>>>>>         
>>>>>>>>>>>         [[[first/topic]]]
>>>>>>>>>>>
>>>>>>>>>>> #value sent from RAK7244
>>>>>>>>>>>
>>>>>>>>>>> [[[[CO2_Value_PPM]]]]
>>>>>>>>>>>         #weewx db name
>>>>>>>>>>> name = co2
>>>>>>>>>>> ignore = false
>>>>>>>>>>>                 contains total = True
>>>>>>>>>>> conversion type = float
>>>>>>>>>>>                 
>>>>>>>>>>>         #[[[SECOND/REPLACE_ME]]]
>>>>>>>>>>> ################################################
>>>>>>>>>>>
>>>>>>>>>>> The message (data) every 60 minutes coming from the node-red 
>>>>>>>>>>> function is:
>>>>>>>>>>>
>>>>>>>>>>> {"CO2_Value_PPM":401} 
>>>>>>>>>>>
>>>>>>>>>>> I may have too many things going here but, as I'm not a 
>>>>>>>>>>> programmer, I'm stuck trying to figure out the problem. The 
>>>>>>>>>>> node-red flow 
>>>>>>>>>>> is connected on both ends (RAK7244-->weewx) but I don't see any 
>>>>>>>>>>> data 
>>>>>>>>>>> reaching the db.
>>>>>>>>>>>
>>>>>>>>>>> Thanks in advance if anyone can help on this.
>>>>>>>>>>> Cheers'
>>>>>>>>>>> Bob
>>>>>>>>>>>
>>>>>>>>>>>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/weewx-user/f9912a50-d160-4b12-acc5-6341b619d241n%40googlegroups.com.
Nov 29 11:10:57 n4mrv weewx[117486] DEBUG user.MQTTSubscribe: (Service) 
MessageCallbackProvider data-> incoming topic: 
application/18/device/2cf7f12122500013/rx, QOS: 0, retain: 0, payload: 
b'{"applicationID":"18","applicationName":"CO2app","deviceName":"CO2device","devEUI":"2cf7f12122500013","txInfo":{"frequency":904900000,"dr":0},"adr":true,"fCnt":247,"fPort":2,"data":"AQQQICoGAPuQ","object":{"err":0,"messages":[{"CO2_Value_PPM":404,"measurementId":4100,"type":"report_telemetry"}],"payload":"010410202A0600FB90","valid":true}}'
Nov 29 11:10:57 n4mrv weewx[117486] ERROR user.MQTTSubscribe: (Service) 
MessageCallbackProvider on_message_json failed with <class 
'user.MQTTSubscribe.ConversionError'> and reason Failed converting field 
applicationName with value CO2app using 'lambda x: to_float(x)' with reason 
could not convert string to float: 'CO2app'..
Nov 29 11:10:57 n4mrv weewx[117486] ERROR user.MQTTSubscribe: (Service) **** 
MessageCallbackProvider Ignoring 
topic=application/18/device/2cf7f12122500013/rx and 
payload=b'{"applicationID":"18","applicationName":"CO2app","deviceName":"CO2device","devEUI":"2cf7f12122500013","txInfo":{"frequency":904900000,"dr":0},"adr":true,"fCnt":247,"fPort":2,"data":"AQQQICoGAPuQ","object":{"err":0,"messages":[{"CO2_Value_PPM":404,"measurementId":4100,"type":"report_telemetry"}],"payload":"010410202A0600FB90","valid":true}}'
Nov 29 11:10:57 n4mrv weewx[117486] ERROR user.MQTTSubscribe: (Service) **** 
MessageCallbackProvider Traceback (most recent call last):#012  File 
"/home/weewx/bin/user/MQTTSubscribe.py", line 1263, in _convert_value#012    
return conversion_func['compiled'](value)#012  File "<string>", line 1, in 
<lambda>#012  File "/home/weewx/bin/weeutil/weeutil.py", line 1276, in 
to_float#012    return float(x) if x is not None else None#012ValueError: could 
not convert string to float: 'CO2app'#012#012During handling of the above 
exception, another exception occurred:#012#012Traceback (most recent call 
last):#012  File "/home/weewx/bin/user/MQTTSubscribe.py", line 1427, in 
_on_message_json#012    (fieldname, value) = self._update_data(fields, 
fields_conversion_func, lookup_key, data_flattened[key], unit_system)#012  File 
"/home/weewx/bin/user/MQTTSubscribe.py", line 1230, in _update_data#012    
value = self._convert_value(fields, default_field_conversion_func, orig_name, 
orig_value)#012  File "/home/weewx/bin/user/MQTTSubscribe.py", line 1268, in 
_convert_value#012    raise ConversionError("Failed converting field %s with 
value %s using '%s' with reason %s." \#012user.MQTTSubscribe.ConversionError: 
Failed converting field applicationName with value CO2app using 'lambda x: 
to_float(x)' with reason could not convert string to float: 'CO2app'.

Reply via email to