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 年前檢視次數 1111 次
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 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南