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.

質問済み 7年前1108ビュー
3回答
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
回答済み 7年前
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

回答済み 7年前
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
回答済み 7年前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ