MQTT Publish and Respond with PHP?

0

I want to send an API call via HTTP request to send a message via MQTT and returned the results when the task is done.

I have a Node JS MQTT AWS IOT Client that receives a response to "client/UUID_3124324" and does a task that might take 1-5 seconds on average and sends the response to "response/UUID_3124324" . I have a rule that records the response to DynamoDB. So the problem is that I need to get the response back to the user but this is not asynchronous call. My thought is that I can call the HTTP Request and somehow listen to the DynamoDB stream for changes. This is getting complicated for me because I am using PHP as the backend and there is no native AWS IOT SDK to quickly subscribe to "response/UUID_3124324" and do something about it.

Any guidance would be appreciated. AWS MQTT seems something I want to use but I think I am missing something or there are other solutions that are easier to implement.

Thanks.

asked 7 years ago1090 views
3 Answers
0

Hi Ikkysleepy,

If one of the actors in your system is constrained to PHP only, I recommend checking out the device shadow service of AWS IoT. Your other actors can publish messages to a shadow topic which gets persisted by AWS IoT. It may not be ideal, though your PHP actor can poll the shadow value over HTTP to check for changes.

http://docs.aws.amazon.com/iot/latest/developerguide/iot-thing-shadows.html

Ryan

AWS
Ryan_B
answered 7 years ago
0

Thanks for the response. This solution might work if the Shadow can contain custom fields and values and not just the current state. Do you know if this is possible? It looks like you can do long polling using php:

https://github.com/panique/php-long-polling

answered 7 years ago
0

You can store any arbitrary key:value pairs in the shadow document, just not at the root level where the "state" key is defined. You can store new values in either the "state.desired" or "state.reported" object space.

{
  "state": {
    "desired": {
      "myKey": "myValue"
    }
  }
}
AWS
Ryan_B
answered 7 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions