我正在工作的Mqtt IOT项目,以执行传感器数据监测。项目架构:

我被困在EC2和GoDaddy订阅part.also之间,我使用phpMQTT库在共享托管中托管了phpMQTT。但是这使得获取数据的速度非常慢,而且我可以管理数据插入part.but,这是我需要做的。
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";
}。
发布于 2020-09-11 16:40:15
我找到了答案。我使用了nodejs、paho、websockets,并使用远程数据库将数据插入mysql。
https://stackoverflow.com/questions/63726759
复制相似问题