Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InfluxDB writer invalid time parsing #688

Closed
bbokun opened this issue Apr 4, 2019 · 6 comments · Fixed by #689
Closed

InfluxDB writer invalid time parsing #688

bbokun opened this issue Apr 4, 2019 · 6 comments · Fixed by #689
Labels

Comments

@bbokun
Copy link

bbokun commented Apr 4, 2019

BUG REPORT

Hello guys,
first of all - great work!

My sensors publish SenML json data via MQTT to the assigned channel. This works as expected. The data is also normalized and written into the InfluxDB via the influxdb-writer.
When I checked the data, it seems that the time is not correctly written into the database - the decimal places of the time is ignored when transforming the time into nano-seconds.

Here an example - the SenML looks as follows:
[{"bt":1554381569.992,"n":"COTemperatureRead","u":"Cel","v":34.3},{"bt":1554381569.992,"n":"COTemperatureSet","u":"Cel","v":40},{"bt":1554381569.992,"n":"DHWTemperatureRead","u":"Cel","v":36.5},{"bt":1554381569.992,"n":"DHWTemperatureSet","u":"Cel","v":45},{"bt":1554381569.992,"n":"DriverStatus","v":33},{"bt":1554381569.992,"n":"FanOn","v":0},{"bt":1554381569.992,"n":"FanSpeed","u":"%","v":0},{"bt":1554381569.992,"n":"FeederOn","v":0},{"bt":1554381569.992,"n":"COPumpOn","v":0},{"bt":1554381569.992,"n":"DHWPumpOn","v":0},{"bt":1554381569.992,"n":"PumpMode","v":3},{"bt":1554381569.992,"n":"FuelLevel","v":0},{"bt":1554381569.992,"n":"FuelLevelPerc","u":"%","v":0},{"bt":1554381569.992,"n":"FuelHours","u":"s","v":0}]

When looking into the database I get:

time channel link name protocol publisher unit updateTime value


1554381569000000000 389 COPumpOn mqtt 106 0 0
1554381569000000000 389 COTemperatureRead mqtt 106 Cel 0 34.3
1554381569000000000 389 COTemperatureSet mqtt 106 Cel 0 40
1554381569000000000 389 DHWPumpOn mqtt 106 0 0
1554381569000000000 389 DHWTemperatureRead mqtt 106 Cel 0 36.5
1554381569000000000 389 DHWTemperatureSet mqtt 106 Cel 0 45
1554381569000000000 389 DriverStatus mqtt 106 0 33
1554381569000000000 389 FanOn mqtt 106 0 0
1554381569000000000 389 FanSpeed mqtt 106 % 0 0
1554381569000000000 389 FeederOn mqtt 106 0 0
1554381569000000000 389 FuelHours mqtt 106 s 0 0
1554381569000000000 389 FuelLevel mqtt 106 0 0
1554381569000000000 389 FuelLevelPerc mqtt 106 % 0 0
1554381569000000000 389 PumpMode mqtt 106 0 3

As we see, instead of 1554381569992000000, I get 1554381569000000000, what means that the fractional part is ignored.

When I turn on the mongodb-writer, the information is stored as expected ( as 1554381569.992)

I forgot to say I use Mainflux 0.8.0

Regards,
Boris Bokun
strictit d.o.o.
Belgrade

@dborovcanin dborovcanin added the bug label Apr 4, 2019
@dborovcanin
Copy link
Collaborator

I can confirm the bug. Line https://github.com/mainflux/mainflux/blob/4f62f89b87d2c0b17819e9a6fd6f1282ca815464/writers/influxdb/messages.go#L115 simply cuts off the decimal value from the time.

@dborovcanin dborovcanin changed the title Possible InfluxDB problem InfluxDB writer invalid time parsing Apr 4, 2019
@drasko
Copy link
Contributor

drasko commented Apr 4, 2019

@bbokun would it be possible that you pull the fix from @dusanb94's branch, butild the docker and test it?

https://github.com/mainflux/mainflux/pull/689

@bbokun
Copy link
Author

bbokun commented Apr 4, 2019

@drasko @dusanb94
I will try it in the evening. Is that ok?

@drasko
Copy link
Contributor

drasko commented Apr 4, 2019

@bbokun sure, thanks!

@nmarcetic
Copy link
Collaborator

@bbokun We merged the fix by @dusanb94
If you can pull the latest docker images or master branch, depending on how you run Mainflux and try now that would be great! Thanks!

@bbokun
Copy link
Author

bbokun commented Apr 5, 2019

@nmarcetic @drasko @dusanb94
👍

Hi guys,
I pulled the new version and tried it out.
Now it looks good. Here the results:

Two SenML packets:

[{"bt":1554424254.927,"n":"COTemperatureRead","u":"Cel","v":24.6},{"bt":1554424254.927,"n":"COTemperatureSet","u":"Cel","v":40},{"bt":1554424254.927,"n":"DHWTemperatureRead","u":"Cel","v":33.4},{"bt":1554424254.927,"n":"DHWTemperatureSet","u":"Cel","v":45},{"bt":1554424254.927,"n":"DriverStatus","v":33},{"bt":1554424254.927,"n":"FanOn","v":0},{"bt":1554424254.927,"n":"FanSpeed","u":"%","v":0},{"bt":1554424254.927,"n":"FeederOn","v":0},{"bt":1554424254.927,"n":"COPumpOn","v":0},{"bt":1554424254.927,"n":"DHWPumpOn","v":0},{"bt":1554424254.927,"n":"PumpMode","v":3},{"bt":1554424254.927,"n":"FuelLevel","v":0},{"bt":1554424254.927,"n":"FuelLevelPerc","u":"%","v":0},{"bt":1554424254.927,"n":"FuelHours","u":"s","v":0}]

[{"bt":1554424255.177,"n":"COTemperatureRead","u":"Cel","v":24.6},{"bt":1554424255.177,"n":"COTemperatureSet","u":"Cel","v":40},{"bt":1554424255.177,"n":"DHWTemperatureRead","u":"Cel","v":33.4},{"bt":1554424255.177,"n":"DHWTemperatureSet","u":"Cel","v":45},{"bt":1554424255.177,"n":"DriverStatus","v":33},{"bt":1554424255.177,"n":"FanOn","v":0},{"bt":1554424255.177,"n":"FanSpeed","u":"%","v":0},{"bt":1554424255.177,"n":"FeederOn","v":0},{"bt":1554424255.177,"n":"COPumpOn","v":0},{"bt":1554424255.177,"n":"DHWPumpOn","v":0},{"bt":1554424255.177,"n":"PumpMode","v":3},{"bt":1554424255.177,"n":"FuelLevel","v":0},{"bt":1554424255.177,"n":"FuelLevelPerc","u":"%","v":0},{"bt":1554424255.177,"n":"FuelHours","u":"s","v":0}]

The result in the database:

name: messages
time channel link name protocol publisher unit updateTime value


1554424254927000045 389 COPumpOn mqtt 106 0 0
1554424254927000045 389 COTemperatureRead mqtt 106 Cel 0 24.6
1554424254927000045 389 COTemperatureSet mqtt 106 Cel 0 40
1554424254927000045 389 DHWPumpOn mqtt 106 0 0
1554424254927000045 389 DHWTemperatureRead mqtt 106 Cel 0 33.4
1554424254927000045 389 DHWTemperatureSet mqtt 106 Cel 0 45
1554424254927000045 389 DriverStatus mqtt 106 0 33
1554424254927000045 389 FanOn mqtt 106 0 0
1554424254927000045 389 FanSpeed mqtt 106 % 0 0
1554424254927000045 389 FeederOn mqtt 106 0 0
1554424254927000045 389 FuelHours mqtt 106 s 0 0
1554424254927000045 389 FuelLevel mqtt 106 0 0
1554424254927000045 389 FuelLevelPerc mqtt 106 % 0 0
1554424254927000045 389 PumpMode mqtt 106 0 3

1554424255177000045 389 COPumpOn mqtt 106 0 0
1554424255177000045 389 COTemperatureRead mqtt 106 Cel 0 24.6
1554424255177000045 389 COTemperatureSet mqtt 106 Cel 0 40
1554424255177000045 389 DHWPumpOn mqtt 106 0 0
1554424255177000045 389 DHWTemperatureRead mqtt 106 Cel 0 33.4
1554424255177000045 389 DHWTemperatureSet mqtt 106 Cel 0 45
1554424255177000045 389 DriverStatus mqtt 106 0 33
1554424255177000045 389 FanOn mqtt 106 0 0
1554424255177000045 389 FanSpeed mqtt 106 % 0 0
1554424255177000045 389 FeederOn mqtt 106 0 0
1554424255177000045 389 FuelHours mqtt 106 s 0 0
1554424255177000045 389 FuelLevel mqtt 106 0 0
1554424255177000045 389 FuelLevelPerc mqtt 106 % 0 0
1554424255177000045 389 PumpMode mqtt 106 0 3

The milliseconds are now visible, and it is ok.

The only thing is that the multiplication with 1e09 gave the expected floating values rounding issues.
For me this is not a problem.

Thanks a lot !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants