Not all devices are able to use the MQTT protocol. Solution to fix this? Well .. it is super simple .. use a proxy. In the code I attached there is a file called proxy.php . To use you must put it (along with the other files, remember that the certificates/private key are wrong, you must generate your own certificates on the AWS console!!!!) on a webserver that is capable of serving PHP files.
Then, in your project, you just call the URL to it along with 2 GET parameters (topic and msg). Example:
http://mydomain.com/path/proxy.php?topic=xxx&msg=yyy
. The script will output "0" for failure to connect or publish and "1" for success on publishing your "yyy" message to your "xxx" topic.
That's basically all.
Also here is an example on how to do a call to it using an NodeMCU (but you can use ANY Internet capable shield/device). For it look on code section of the tutorial on "MQTT Proxy Example".
Comments