开发者

SQL database and MQTT (Mosquitto or RSMB)

开发者 https://www.devze.com 2023-03-17 23:08 出处:网络
I am curren开发者_开发百科tly using RSMB as an MQTT connection to mobile devices. What\'s the best way to go about storing the published messages into an SQL database when they come through?

I am curren开发者_开发百科tly using RSMB as an MQTT connection to mobile devices. What's the best way to go about storing the published messages into an SQL database when they come through?

Right now I'm having to POST to a PHP page that accesses the database before publishing to the topic.

Thanks


You could create an MQTT client that subscribes to the topics you're interested in and inserts them into your database. This could run on the machine running the broker or the database.

Both Mosquitto and RSMB provide C client libraries that you could use, along with the appropriate library for your database.


I wrote a blog article which deals exactly with that topic:

http://www.hivemq.com/mqtt-sql-database/

You can find the example code for a wilcard subscriber which inserts message to a MySQL database here: https://github.com/dc-square/paho-wildcard-subscriber


Have a look at:

https://github.com/bluewindthings/mqtt-to-sql-daemon

this daemon, along with maybe a prior re-organization of topics structure with https://github.com/bluewindthings/mqtt-republisher-daemon may be the answer

0

精彩评论

暂无评论...
验证码 换一张
取 消