Question about JSON format for MQTT ipaddress / geojson

Hi there,

I’m doing some preliminary testing changing attribute values via mosquitto_pub

This works for numbers but I can’t get the ipaddress or geojson to change

e.g.

mosquitto_pub -h ${HOST} -p ${PORT} -u ${USER} -P ${PASSWORD} -i ${CLIENTID} -t master/${CLIENTID}/writeattributevalue/powerfail_reactivation/${THINGID} -m 1
mosquitto_pub -h ${HOST} -p ${PORT} -u ${USER} -P ${PASSWORD} -i ${CLIENTID} -t master/${CLIENTID}/writeattributevalue/battery/${THINGID} -m 81
mosquitto_pub -h ${HOST} -p ${PORT} -u ${USER} -P ${PASSWORD} -i ${CLIENTID} -t master/${CLIENTID}/writeattributevalue/signal_strength/${THINGID} -m 90
mosquitto_pub -h ${HOST} -p ${PORT} -u ${USER} -P ${PASSWORD} -i ${CLIENTID} -t master/${CLIENTID}/writeattributevalue/ipaddress/${THINGID} -m "{\"ip\":\"86.8.146.132\"}"
mosquitto_pub -h ${HOST} -p ${PORT} -u ${USER} -P ${PASSWORD} -i ${CLIENTID} -t master/${CLIENTID}/writeattributevalue/location/${THINGID} -m "{\“type”:“Point\”,\“coordinates\”: [-3.0208900000004633,53.47920427156586] }"

I’ve tried a simple string for IP address and various different JSON formats but I can’t seem to crack it. Could anybody advise please?

Thanks!

Alex

Could anybody signpost me on this? I think the data-format(s) should be very straightforward but I can’t find any documentation on them anywhere? Thanks!

Hi!

The payload should be a JSON (object) of the attribute value.

For example, as you are showing with the numbers; you can simply send the raw value.
With sime complex objects, it should be a JSON object,

For context; the MQTT API, and its publish topic is documented here.

.
In case of IP addresses, I believe you can simply use a string.
For locations, I believe it would be a string of coordinates, right? Like in the UI?
(not entirely sure about this)

.
I haven’t used a CLI tool to send MQTT messages, so might be a limitation / confusion with the CLI.
So you might need to tinker a bit :sweat_smile:

Maybe another forum user like @panos knows haha

HI Martin!

Yes thanks for the link. It would be super helpful to have an example of a good JSON payload (or other) for both IP Address and GEO JSON as I’ve tried a number of permutations with no success

I’ve tried sending a string payload for IP address e.g. “192.168.1.1” and the attribute just goes “blank”

So I’m at a bit of a loss!

Thanks,

Alex

OK I have a GEO JSON payload sorted

{ \"type\": \"Point\", \"coordinates\":[-3.0208900000004633,53.47920427156586]}

There’s still something very odd about IP address. From the errors in the logs it looks like if I send a string it errors as it wants to parse JSON But if I send JSON then it errors as it wants to parse a string

2024-07-25 23:21:11.074  INFO    [Thread-29 (ActiveMQ-clie..ads)] te.model.util.ValueUtil.MODEL_AND_VALUES : Failed to parse JSON string: 192.168.1.1
com.fasterxml.jackson.core.JsonParseException: Unexpected character ('.' (code 46)): Expected space separating root-level values
 at [Source: REDACTED (`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled); line: 1, column: 9]
        at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:2481)
        at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:752)
        at com.fasterxml.jackson.core.base.ParserMinimalBase._reportUnexpectedChar(ParserMinimalBase.java:676)
        at com.fasterxml.jackson.core.base.ParserMinimalBase._reportMissingRootWS(ParserMinimalBase.java:724)
        at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._verifyRootSpace(ReaderBasedJsonParser.java:1834)
        at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._parseFloat(ReaderBasedJsonParser.java:1494)
        at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._parseUnsignedNumber(ReaderBasedJsonParser.java:1422)
        at com.fasterxml.jackson.core.json.ReaderBasedJsonParser.nextToken(ReaderBasedJsonParser.java:809)
        at com.fasterxml.jackson.databind.ObjectMapper._initForReading(ObjectMapper.java:4986)
        at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4892)
        at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3846)
        at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3814)
        at org.openremote.model.util.ValueUtil.parse(ValueUtil.java:205)
        at org.openremote.manager.mqtt.DefaultMQTTHandler.onPublish(DefaultMQTTHandler.java:427)
        at org.openremote.manager.mqtt.MQTTHandler.lambda$addPublishConsumer$0(MQTTHandler.java:132)
        at org.apache.activemq.artemis.core.client.impl.ClientConsumerImpl.callOnMessage(ClientConsumerImpl.java:982)
        at org.apache.activemq.artemis.core.client.impl.ClientConsumerImpl$Runner.run(ClientConsumerImpl.java:1134)
        at org.apache.activemq.artemis.utils.actors.OrderedExecutor.doTask(OrderedExecutor.java:57)
        at org.apache.activemq.artemis.utils.actors.OrderedExecutor.doTask(OrderedExecutor.java:32)
        at org.apache.activemq.artemis.utils.actors.ProcessorBase.executePendingTasks(ProcessorBase.java:68)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
        at org.apache.activemq.artemis.utils.ActiveMQThreadFactory$1.run(ActiveMQThreadFactory.java:118)
2024-07-25 23:14:48.976  WARNING [Pool-AttributeEventProce..1-16] ote.manager.asset.AssetProcessingService : Error processing from DefaultMQTTHandler: AttributeEvent{timestamp=2024-07-25T21:14:48.968Z, ref=AttributeRef{id='43xLqosLx5plzmceavH0ym', name='ipaddress'}, valueType=java.util.LinkedHashMap}  - INVALID_VALUE (Event processing failed unable to coerce value into the correct value type: realm=null, attribute=AttributeRef{id='43xLqosLx5plzmceavH0ym', name='ipaddress'}, event value type=class java.util.LinkedHashMap, attribute value type=class java.lang.String)
        2024-07-25 23:14:49.966  INFO    [Pool-AttributeEventProce..1-16] te.model.util.ValueUtil.MODEL_AND_VALUES : Failed to coerce value to requested type: input=class java.util.LinkedHashMap, output=class java.lang.String
java.lang.IllegalArgumentException: Cannot deserialize value of type `java.lang.String` from Object value (token `JsonToken.START_OBJECT`)
 at [Source: UNKNOWN; byte offset: #UNKNOWN]
        at com.fasterxml.jackson.databind.ObjectMapper._convert(ObjectMapper.java:4618)
        at com.fasterxml.jackson.databind.ObjectMapper.convertValue(ObjectMapper.java:4549)
        at org.openremote.model.util.ValueUtil.getValue(ValueUtil.java:358)
        at org.openremote.model.util.ValueUtil.getValueCoerced(ValueUtil.java:385)
        at org.openremote.manager.asset.AssetProcessingService.lambda$processAttributeEvent$15(AssetProcessingService.java:395)
        at java.base/java.util.Optional.map(Optional.java:260)
        at org.openremote.manager.asset.AssetProcessingService.lambda$processAttributeEvent$18(AssetProcessingService.java:393)
        at org.openremote.container.persistence.PersistenceService.lambda$doTransaction$4(PersistenceService.java:416)
        at org.openremote.container.persistence.PersistenceService.doReturningTransaction(PersistenceService.java:426)
        at org.openremote.container.persistence.PersistenceService.doTransaction(PersistenceService.java:415)
        at org.openremote.manager.asset.AssetProcessingService.processAttributeEvent(AssetProcessingService.java:380)
        at org.openremote.manager.asset.AssetProcessingService.lambda$configure$11(AssetProcessingService.java:326)
        at org.apache.camel.support.processor.DelegateSyncProcessor.process(DelegateSyncProcessor.java:65)
        at org.apache.camel.processor.errorhandler.RedeliveryErrorHandler$RedeliveryTask.doRun(RedeliveryErrorHandler.java:824)
        at org.apache.camel.processor.errorhandler.RedeliveryErrorHandler$RedeliveryTask.run(RedeliveryErrorHandler.java:732)
        at org.apache.camel.impl.engine.DefaultReactiveExecutor$Worker.executeReactiveWork(DefaultReactiveExecutor.java:196)
        at org.apache.camel.impl.engine.DefaultReactiveExecutor$Worker.schedule(DefaultReactiveExecutor.java:164)
        at org.apache.camel.impl.engine.DefaultReactiveExecutor.scheduleMain(DefaultReactiveExecutor.java:59)
        at org.apache.camel.processor.Pipeline.process(Pipeline.java:163)
        at org.apache.camel.impl.engine.CamelInternalProcessor.process(CamelInternalProcessor.java:383)
        at org.apache.camel.component.seda.SedaConsumer.sendToConsumers(SedaConsumer.java:267)
        at org.apache.camel.component.seda.SedaConsumer.doRun(SedaConsumer.java:186)
        at org.apache.camel.component.seda.SedaConsumer.run(SedaConsumer.java:129)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
        at java.base/java.lang.Thread.run(Thread.java:840)
Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of type `java.lang.String` from Object value (token `JsonToken.START_OBJECT`)
 at [Source: UNKNOWN; byte offset: #UNKNOWN]
        at com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:59)
        at com.fasterxml.jackson.databind.DeserializationContext.reportInputMismatch(DeserializationContext.java:1767)
        at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1541)
        at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1446)
        at com.fasterxml.jackson.databind.DeserializationContext.extractScalarFromObject(DeserializationContext.java:958)
        at com.fasterxml.jackson.databind.deser.std.StdDeserializer._parseString(StdDeserializer.java:1424)
        at com.fasterxml.jackson.databind.deser.std.StringDeserializer.deserialize(StringDeserializer.java:48)
        at com.fasterxml.jackson.databind.deser.std.StringDeserializer.deserialize(StringDeserializer.java:11)
        at com.fasterxml.jackson.databind.ObjectMapper._convert(ObjectMapper.java:4613)
        ... 25 more
2024-07-25 23:14:49.967  WARNING [Pool-AttributeEventProce..1-16] ote.manager.asset.AssetProcessingService : Error processing from DefaultMQTTHandler: AttributeEvent{timestamp=2024-07-25T21:14:49.965Z, ref=AttributeRef{id='43xLqosLx5plzmceavH0ym', name='ipaddress'}, valueType=java.util.LinkedHashMap}  - INVALID_VALUE (Event processing failed unable to coerce value into the correct value type: realm=null, attribute=AttributeRef{id='43xLqosLx5plzmceavH0ym', name='ipaddress'}, event value type=class java.util.LinkedHashMap, attribute value type=class java.lang.String)

AHA. I have to explicitly publish a string with quotes

"\"192.168.1.1\""

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.