Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
0
Help us understand the problem. What is going on with this article?
@hashito

MQTTのMessageを残らずMySQL(MariaDB)に保存するコマンド

More than 1 year has passed since last update.

個人的なメモ

db構造

sudo mysql -e "SHOW FULL COLUMNS FROM mqtt.msg"
+-------+---------------+-------------------+------+-----+---------+-------+---------------------------------+---------+
| Field | Type          | Collation         | Null | Key | Default | Extra | Privileges                      | Comment |
+-------+---------------+-------------------+------+-----+---------+-------+---------------------------------+---------+
| m     | varchar(1124) | latin1_swedish_ci | YES  |     | NULL    |       | select,insert,update,references |         |
| tm    | int(11)       | NULL              | YES  |     | NULL    |       | select,insert,update,references |         |
+-------+---------------+-------------------+------+-----+---------+-------+---------------------------------+---------+

コマンド

mosquitto_sub -t "#" -v | xargs -I@ sudo mysql -e "insert into mqtt.msg (m,tm)values('@',$(date +%s))"

上記だと、時間が固定になってしまいます。
SQLの方で持ってくるように変更

mosquitto_sub -t "#" -v | xargs -I@ sudo mysql -e "insert into mqtt.msg (m,tm)values('@',UNIX_TIMESTAMP(NOW()))"

課題

・セキュリティ的に問題有り
・トピックとMessageが分割できていない

commentいただけると嬉しいです!

0
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
hashito
わたしです。 主に個人的なメモです。

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
0
Help us understand the problem. What is going on with this article?