WebThingsIO / gateway

WebThings Gateway - a self-hosted web application for monitoring and controlling a building over the web
http://webthings.io/gateway
Mozilla Public License 2.0
2.62k stars 339 forks source link

Logging: NaN y axis #2031

Open personalnadir opened 5 years ago

personalnadir commented 5 years ago

I'm trying to log the temperature from a Fibaro multisensor. However when I open the log the y axis is labelled NaN.

Opening the Javascript console I'm seeing the following output:

[Error] Error: Problem parsing d="M 115 NaN L 126 NaN"
    makePath (0b82e0a20aeaf4b390a8-app.js:26810)
    drawYTicks (0b82e0a20aeaf4b390a8-app.js:27254)
    redraw (0b82e0a20aeaf4b390a8-app.js:27065)
    (anonymous function) (0b82e0a20aeaf4b390a8-app.js:42525)
[Error] Error: Problem parsing d="M 116 NaN L 1165 NaN L 1168 NaN L 1168 NaN"
    makePath (0b82e0a20aeaf4b390a8-app.js:26810)
    redraw (0b82e0a20aeaf4b390a8-app.js:27164)
    (anonymous function) (0b82e0a20aeaf4b390a8-app.js:42525)
[Error] Error: Problem parsing d="M 116 180 L 116 NaN L 1165 NaN L 1168 NaN L 1168 NaN L 1168 180"
    makePath (0b82e0a20aeaf4b390a8-app.js:26810)
    redraw (0b82e0a20aeaf4b390a8-app.js:27174)
    (anonymous function) (0b82e0a20aeaf4b390a8-app.js:42525)
[Error] TypeError: value.toFixed is not a function. (In 'value.toFixed(places)', 'value.toFixed' is undefined)
    valueToLabel (0b82e0a20aeaf4b390a8-app.js:27208)
    drawTooltip (0b82e0a20aeaf4b390a8-app.js:27671)
    onPointerMove (0b82e0a20aeaf4b390a8-app.js:27634)
    onPointerMove

I've noticed that the data from the sensor seems to be logged in the metricsOther table.

As it stands the data is:

ID DATE VALUE
1 1563827966849 "28.4"
1 1563829764024 "27.1"

The metric IDs are:

id descr maxAge
1 {"type":"property","thing":"zwave-ed612fed-4","property":"temperature"} 604800000

The device seems to update its values correctly.

Screenshot 2019-07-22 at 22 22 14

I pulled this data from the things database:

{
  "name": "Fibaro Hallway",
  "type": "binarySensor",
  "@context": "https://iot.mozilla.org/schemas",
  "@type": [
    "DoorSensor",
    "BinarySensor",
    "TemperatureSensor"
  ],
  "description": "",
  "href": "/things/zwave-ed612fed-4",
  "properties": {
    "on": {
      "@type": "BooleanProperty",
      "readOnly": true,
      "links": [
        {
          "rel": "property",
          "href": "/things/zwave-ed612fed-4/properties/on"
        }
      ]
    },
    "open": {
      "title": "Open",
      "@type": "OpenProperty",
      "description": "Contact Switch",
      "readOnly": true,
      "links": [
        {
          "rel": "property",
          "href": "/things/zwave-ed612fed-4/properties/open"
        }
      ]
    },
    "temperature": {
      "title": "Temperature",
      "type": "number",
      "@type": "TemperatureProperty",
      "unit": "degree celsius",
      "links": [
        {
          "rel": "property",
          "href": "/things/zwave-ed612fed-4/properties/temperature"
        }
      ]
    },
    "luminance": {
      "title": "Luminance",
      "type": "number",
      "unit": "lux",
      "links": [
        {
          "rel": "property",
          "href": "/things/zwave-ed612fed-4/properties/luminance"
        }
      ]
    },
    "batteryLevel": {
      "title": "Battery",
      "type": "number",
      "@type": "LevelProperty",
      "unit": "percent",
      "minimum": 0,
      "maximum": 100,
      "readOnly": true,
      "links": [
        {
          "rel": "property",
          "href": "/things/zwave-ed612fed-4/properties/batteryLevel"
        }
      ]
    }
  },
  "actions": {},
  "events": {},
  "links": [
    {
      "rel": "properties",
      "href": "/things/zwave-ed612fed-4/properties"
    },
    {
      "rel": "actions",
      "href": "/things/zwave-ed612fed-4/actions"
    },
    {
      "rel": "events",
      "href": "/things/zwave-ed612fed-4/events"
    },
    {
      "rel": "alternate",
      "mediaType": "text/html",
      "href": "/things/zwave-ed612fed-4"
    }
  ],
  "layoutIndex": 0,
  "selectedCapability": "TemperatureSensor",
  "iconHref": null
}
rmeissn commented 4 years ago

I observe something similar. I built my own WebThing (a temperature Sensor) and wanted to log the temperature over time. The WebThing was able to connect and in things view I can view the correct values (e.g. 22°C). The logging graph works for a small amount of time. But at some point the graph fails to render. See the picture below.

Bildschirmfoto von 2020-01-21 14-39-13

My javascript console logs for this page of the gateway are:

...
[webrtc_vad.js status]  <empty string> stm_web.min.js:1:4693
Unexpected value NaN when parsing the attribute y. 2 log.js:246:8
[webrtc_vad.js status]  Exception thrown, see JavaScript console stm_web.min.js:1:4693
TypeError: value.toFixed is not a function
log.js:609:24
[webrtc_vad.js error] [post-exception status] Exception thrown, see JavaScript console stm_web.min.js:1:4615
TypeError: value.toFixed is not a function
log.js:609:24
[webrtc_vad.js error] [post-exception status] Exception thrown, see JavaScript console stm_web.min.js:1:4615
TypeError: value.toFixed is not a function
log.js:609:24
[webrtc_vad.js error] [post-exception status] Exception thrown, see JavaScript console stm_web.min.js:1:4615
TypeError: value.toFixed is not a function
log.js:609:24
...

This is repeated like a hundred times.

The same sensor (WebThing) delivers humidity values, for which the graph works as expected (now 1 day of data).

mrstegeman commented 4 years ago

@rmeissn is it possible that you’re sending the value as a string, rather than a number?

rmeissn commented 4 years ago

@mrstegeman I'm doing:

class DHT22 extends Thing {
  constructor(sensorPin) {
    super(
       uuidv4(),
      'DHT22',
      ['MultiLevelSensor'],
      'A web connected temperature und humidity sensor'
    );

    this.temperature = new Value(0.0);
    this.humidity = new Value(0.0);

    this.addProperty(new Property(this, 'Humidity', this.humidity, {
        '@type': 'LevelProperty',
        title: 'Humidity',
        type: 'number',
        description: 'The current humidity in %',
        minimum: 0,
        maximum: 100,
        unit: 'percent',
        readOnly: true
      })
    );

    this.addProperty(new Property(this, 'Temperature', this.temperature, {
        '@type': 'LevelProperty',
        title: 'Temperature',
        type: 'number',
        description: 'The current temperature in °C',
        minimum: -40,
        maximum: 80,
        unit: 'degree celsius',
        readOnly: true
      })
    );

    this.readAndUpdate = function () {
      const that = this;
      sensorlib.read(22, sensorPin, function (err, Stemperature, Shumidity) {
        if(!err) {
          const temp = Stemperature.toFixed(1);
          const humid = Shumidity.toFixed(1);

          console.log('Setting new levels for pin ' + sensorPin + ':', "T:" + temp + "C, H:" + humid + "%");
          that.temperature.notifyOfExternalUpdate(temp);
          that.humidity.notifyOfExternalUpdate(humid);
          that.emit('update')
        }
      });
    };
    this.readAndUpdate = this.readAndUpdate.bind(this);

    this.readAndUpdate();
    setInterval(this.readAndUpdate, 300000);
  }
}

The code is mostly adapted from the examples in https://github.com/mozilla-iot/webthing-node/tree/master/example You'll see that it's exactly the same for humidity and temperature. Humidity is working fine in the gateway, temperature is not.

mrstegeman commented 4 years ago

toFixed() returns a string, not a number.

rmeissn commented 4 years ago

Uups, I'm sorry. You're totally right. Now it works as expected for me and the graphs are correctly drawn.