Aws EC2 Mosquitto broker Subscribe using Shared Hosting

Viewed 104

i am working on Mqtt IOT project to perform sensor data monitoring. Project architecture:

Project architecture

I was stuck between EC2 and GoDaddy subscription part.also i hosted PHP script in shared hosting using phpMQTT library. but this give fetch data very slowly and i can manage data inserting part.but this is what i need to do.

require('../phpMQTT.php');


$server = 'MY EC2 IP';     // change if necessary
$port = 1883;                     // change if necessary
$username = '';                   // set your username
$password = '';                   // set your password
$client_id = 'test client'; // make sure this is unique for connecting to sever - you could use uniqid()

$mqtt = new Bluerhinos\phpMQTT($server, $port, $client_id);
if(!$mqtt->connect(true, NULL, $username, $password)) {
    exit(1);
}

$mqtt->debug = true;

$topics['bluerhinos/phpMQTT/examples/publishtest'] = array('qos' => 0, 'function' => 'procMsg');
$mqtt->subscribe($topics, 0);

while($mqtt->proc()) {

}

$mqtt->close();

function procMsg($topic, $msg){
        echo 'Msg Recieved: ' . date('r') . "\n";
        echo "Topic: {$Topicx}\n\n";
        echo "\t$msg\n\n";
}
  1. Is there any method to configure to mosquitto for sending data to external server MySQL database?
  2. Is there Javascript based method?
  3. Could you please suggest working methods to subscribe Mqtt topic from shared hosting at least 1 second delay?
1 Answers

i found the answer. i used nodejs paho websockets and insert data to mysql using remote database.

Related