This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | |||
technical:mqtt [2022/06/19 21:35] admin |
technical:mqtt [2022/06/19 21:48] (current) admin |
||
---|---|---|---|
Line 122: | Line 122: | ||
</ | </ | ||
- | ==== Response -> mqtt.lua ==== | ||
==== Response -> API Gateway ==== | ==== Response -> API Gateway ==== | ||
+ | * The API Gateway subscribe to the topic which the mesh node or access point publishes to. | ||
+ | * Here is a snippet from the **/ | ||
+ | <code javascript> | ||
+ | default: | ||
+ | request.put({ | ||
+ | url: mesh_controller + '/ | ||
+ | form: data | ||
+ | }, | ||
+ | function (err, res, body) { | ||
+ | if (err) { | ||
+ | console.error(' | ||
+ | } | ||
+ | |||
+ | console.log(body); | ||
+ | } | ||
+ | ); | ||
+ | break; | ||
+ | </ | ||
==== Response -> CakePHP Controller ==== | ==== Response -> CakePHP Controller ==== | ||
+ | * Finally we can look at the CakePHP code that process the response so our system know and can indicate the mesh node or access point did receive the instruction. | ||
+ | * Lets look at the **/ | ||
+ | <code php> | ||
+ | //--This comes from the NodeJS API Gateway Application in response to ' | ||
+ | //--This comes from the NodeJS API Gateway Application in FIRST response to ' | ||
+ | public function nodeCommand(){ | ||
+ | |||
+ | if($this-> | ||
+ | $data = $this-> | ||
+ | if((!empty($data[' | ||
+ | // update command status to fetched | ||
+ | $model = ' | ||
+ | if($data[' | ||
+ | $model = ' | ||
+ | } | ||
+ | | ||
+ | $entity | ||
+ | if($entity){ | ||
+ | $entity-> | ||
+ | $this-> | ||
+ | } | ||
+ | |||
+ | $this-> | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | )); | ||
+ | } else { | ||
+ | $this-> | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | )); | ||
+ | } | ||
+ | |||
+ | } else { | ||
+ | $this-> | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | )); | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||