Comments (5)
possible:
as historical data creation is not functional part of the python daemon, I suggest to handle this on SQL side too.
Remove existing trigger mqtt_after_update
with the following mqtt_before_update
trigger:
DROP TRIGGER IF EXISTS `mqtt_after_update`;
DROP TRIGGER IF EXISTS `mqtt_before_update`;
DELIMITER //
CREATE TRIGGER `mqtt_before_update` BEFORE UPDATE ON `mqtt` FOR EACH ROW BEGIN
IF ((SELECT value FROM mqtt WHERE id=NEW.id)!=NEW.value) THEN
INSERT INTO mqtt_history SET ts=NEW.ts, topicid=NEW.id, value=NEW.value;
END IF;
END//
DELIMITER ;
This will insert data into history table only if the current value is different to the last published
from mqtt2sql.
An alternate way with detailed control for each topic is
- add an additonal field
history
ALTER TABLE `mqtt`
ADD COLUMN `history` TINYINT(4) NOT NULL DEFAULT '1' AFTER `active`;
- insert values (check in triggers) only if history is set, so change the existing original triggers like:
DROP TRIGGER IF EXISTS `mqtt_after_insert`;
DROP TRIGGER IF EXISTS `mqtt_after_update`;
DELIMITER //
CREATE TRIGGER `mqtt_after_insert` AFTER INSERT ON `mqtt` FOR EACH ROW BEGIN
IF NEW.history!=0 THEN
INSERT INTO mqtt_history SET ts=NEW.ts, topicid=NEW.id, value=NEW.value;
END IF;
END//
CREATE TRIGGER `mqtt_after_update` AFTER UPDATE ON `mqtt` FOR EACH ROW BEGIN
IF NEW.history!=0 THEN
INSERT INTO mqtt_history SET ts=NEW.ts, topicid=NEW.id, value=NEW.value;
END IF;
END//
DELIMITER ;
This solution allows you to fine control using the history
column of mqtt
table which topic should be in history and which not.
from mqtt2sql.
Cool thanks for the statements! I think they would also fit good for README?
I prefer the history for all, and no exclusions, so nr 1 😃 .
EDIT: Actually, I think it would make sense to add the "history" flag in general (i.e. to the default README statement), and have the trigger "changed only" optionally as "alternative trigger setup"?
from mqtt2sql.
I've created a PR to add the history flag to mqtt mysql table on README.
If you are interested, after that PR we could upgrade it to have both suggestions coexisting in DB and in trigger: enable_history and enable_history_changes_only
from mqtt2sql.
btw, what I want todo with the data that this script produces: create simple dashboard for e.g. temperature history and turn heating on/off.
I'm running openhab since quite some time but it's quite unstable and resource consuming while I only need a very small faction of features. ... as data anyway coming from mqtt this should be enough to realize it in the simplest fashion
from mqtt2sql.
Related Issues (11)
- Error on_connet HOT 1
- автозагрузка HOT 3
- anyone have any consumer of the SQL data? HOT 1
- Will not allow SQL type database? HOT 1
- error, probably after python upgrade on host HOT 2
- wildcard in topic HOT 1
- Records created using local time instead of UTC HOT 1
- CTRL+C HOT 7
- mqtt2sql.py: error: argument --sql-type: invalid choice: 'mysql' (choose from 'sqlite') HOT 7
- автозапуск HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mqtt2sql.