Help needed - MQTT to REST

Options

Hi all,
I'm new to Solace and I'm still learning the ropes. I'm stuck and I need help.

What I want to achieve:

  • I want to control Shelly IoT devices from my own HTTP server, using SOLACE+MQTT.
    To do that, I need to:

  • Translate MQTT to REST. When solace receives a MQTT message, it should send a REST call to another server.

  • Translate REST to MQTT. When solace receives a REST call (POST with basic auth), it should send a MQTT message to subscribers.

What I managed to achieve until now:

  • Spin up a solace cloud instance (free plan) and connect MQTT devices.
  • Test a REST call at https://mr2j0vvhki6a39.messaging.solace.cloud:20427/T/rest/pubsub and it seem to work, but it does not work if I change /T/rest/pubsub to anything else.
    What I'm stuck on:

  • how to actually translate my rest call at /T/rest/pubsub to a MQTT message sent to shellies/shelly1-8CAAB505BF8E/relay/0/command ?

  • how to translate my MQTT message at shellies/shelly1-8CAAB505BF8E/relay/0 to a REST call to my http server?

Any hints?

Tagged:

Comments

  • TomF
    TomF Member, Employee Posts: 406 Solace Employee
    Options

    Hi @Mirco Stevanato. What you're trying to do is perfectly valid and we should get you up an running pretty quickly. Let's first deal with how your incoming REST call is being dealt with. By default you will be in "REST Messaging Mode" as opposed to microgateway mode - see https://docs.solace.com/Overviews/Microgateway-Concepts/Microgateways-Overview.htm#Msging_vs_MicroGateway for more details. This is probably what you need so let's stick with that at the moment.

    Next, how is the incoming REST message mapped to a topic? Well, that "/T" (short for /TOPIC, which also works) in your URI indicates that this message should go to a topic - in this case, topic rest/pubsub. You can change this to any topic that works - for instance, your IoT device could include its own ID in that topic string. If you want to persist the incoming message, create a queue, then use /QUEUE/queue-name OR (insert Solace magic) have your queue subscribe to the topic.

    Now the good bit - if you're sending the REST messages to a topic, all you need to do is have your MQTT subscriber subscribe to the same topic. So you'd want your incoming REST message to be sent to https://mr2j0vvhki6a39.messaging.solace.cloud:20427/TOPIC/shellies/shelly1-8CAAB505BF8E/relay/0/command.

    In the other direction, there is some work needed to set up your REST outgoing call. You'll need to set up a Rest Delivery Point (RDP). Inside this will be the configuration for how to call the REST service and at what URL - this is the Rest Consumer. The key point is that you'll need a queue and a queue binding - the queue binding reads messages from the queue. So, create a queue to receive your incoming MQTT messages and make sure the queue subscribes to the MQTT topic.

  • Mirco Stevanato
    Mirco Stevanato Member Posts: 2
    Options

    Thanks! I'm still confused about queues, but I'm going to try what you suggested.

    I managed to send a command from REST to MQTT, using: http://mr2j0vvhki6a39.messaging.solace.cloud:20426/TOPIC/shellies/shelly1-8CAAB505BF8E/relay/0/command and it's working.

    is there a way to use a REST call to read a topic?

    I tried to GET http://mr2j0vvhki6a39.messaging.solace.cloud:20426/TOPIC/shellies/shelly1-8CAAB505BF8E/relay/0 but all I receive is an error:
    <?xml version="1.0" encoding="utf-16"?> <solace-error-response> <code>405</code> <reason><![CDATA[Method Not Allowed]]></reason> <detail><![CDATA[ Method not allowed ]]></detail> <internal-use>1:1624</internal-use> </solace-error-response>

  • Neha
    Neha Member, Employee Posts: 5 Solace Employee
    Options

    Hi Mirco,
    In Solace REST call cannot be used to read messages from a Topic Or Queue.