I would like some advices and help concerning a IoT stack. This is the stack I have imagined:
- Arduino, the IoT device
- Broker, doesn't matter for now, I will use a free public broker for testing.
- A Server storing the data.
Since I already have a Web Host from Siteground, either apache2 or nginx. I wanted to know if it is possible to connect the it as a Subscriber to the broker to received the data and store it into its database.
For now I have discovered the php/mqtt library, and mock a publisher and a subscriber with this guide.
<?php // Subscriber require('vendor/autoload.php'); use \PhpMqtt\Client\MqttClient; use \PhpMqtt\Client\ConnectionSettings; $server = 'broker.emqx.io'; $port = 1883; $clientId = rand(5, 15); $username = 'emqx_user'; $password = null; $clean_session = false; $connectionSettings = new ConnectionSettings(); $connectionSettings ->setUsername($username) ->setPassword(null) ->setKeepAliveInterval(60) ->setLastWillTopic('emqx/test/last-will') ->setLastWillMessage('client disconnect') ->setLastWillQualityOfService(0); $mqtt = new MqttClient($server, $port, $clientId); pcntl_signal(SIGINT, function (int $signal, $info) use ($mqtt) { $mqtt->interrupt(); }); $mqtt->connect($connectionSettings, $clean_session); printf("client connected\n"); $mqtt->subscribe('emfqx/test', function ($topic, $message) { printf("Received message on topic [%s]: %s\n", $topic, $message); }, 0); $mqtt->loop(true); $mqtt->disconnect(); How can I make my server run this script? Can it be run like a REST API? If it's feasible, can I also host a web application on the same server to display the data from the database?
Furthermore, I would also like to know if using the same server as the broker is possible? With Mosquitto, for example?
Actually I did not found any ressource explaining how to deploy this, more precisely I am looking for the connection between the broker and the 'cloud platform', preferably in php.