tkurki / signalk-to-influxdb2

Apache License 2.0
6 stars 4 forks source link

Error creating point from notifications #47

Closed nadrog closed 11 months ago

nadrog commented 11 months ago

Sending certain notifications throws error: "Error creating point notifications.environment.inside.temperature:[object Object] => number source:undefined". This is after I extended the debug to include the source as well.

This happens when sending notifications created by Zones plugin, but I was not able to identify the reason.

This case does NOT throw an error:

notifications.environment.inside.humidity:
{
  "state": "normal",
  "message": "vlag",
  "method": [
    "visual",
    "sound"
  ],
  "timestamp": "2023-12-28T10:36:21.348Z"
}

and creates the following record in InfluxDB2: {"state":"normal","message":"vlag","method":["visual","sound"],"timestamp":"2023-12-28T10:36:21.348Z"}

All others, like this one, do throw the error above but I fail to see any meaningful distinction.

notifications.environment.inside.temperature:
{
  "state": "normal",
  "message": "temp",
  "method": [
    "visual",
    "sound"
  ],
  "timestamp": "2023-12-28T10:14:34.666Z"
}

If this matters, this is running on Nixos 23.11 signalk 2.4.1 is installed with "npm config set prefix /home/user/.npm-apackages" as global install is not supported on Nixos npm is 9.8.1 node is v18.18.2

tkurki commented 11 months ago

InfluxDB 2 has an internal data type per measurement (= Signal K path) that is locked in place when you write the first value.

The plugin uses Signal K schema to try to retrieve the Influx data type to use for each measurement / path. If the schema provides a unit for the path the value is assumed to be a number, otherwise the data type of the JavaScript value is used to derive the Influx data type to use.

The difference is explained by this

> sk.getUnits('vessels.self.notifications.environment.inside.humidity')
undefined
> sk.getUnits('vessels.self.notifications.environment.inside.temperature')
'K'

which seems to me to be a bug in getUnits implementation.

But I think a better fix would be to assume all values under notifications are objects and force that data type.

nadrog commented 11 months ago

Actually, according to SignalK specification, my example only works because I wrongly used inside.humidity instead of SignalK's inside.relativeHumidity. Although, there's some inconsistency here as the spec defines outside.humidity instead of outside.relativeHumidity. Also, in SignalK server, the unit for notifications.environment.inside.humidity is ratio...

Anyway, in the SignalK spec, there are two matches for vessels.self.notifications.environment.inside.temperature:

Based on this, for the complete solution, I would say that

Until this is done, can you implement a workaround and use sk.getUnits only if path does not match /vessels/<RegExp>/notifications/<RegExp>?

tkurki commented 11 months ago

v1.6.2 should be available shortly.

nadrog commented 11 months ago

Just tested it and it works ok. Thanks!

On Fri, Dec 29, 2023 at 4:55 PM Teppo Kurki @.***> wrote:

v1.6.2 should be available shortly.

— Reply to this email directly, view it on GitHub https://github.com/tkurki/signalk-to-influxdb2/issues/47#issuecomment-1872185615, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABXQ47ZZW4LRJQT7GZFBN3TYL3RV5AVCNFSM6AAAAABBFLOZHWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNZSGE4DKNRRGU . You are receiving this because you authored the thread.Message ID: @.***>