Author Topic: Wrong last value of network connected node [solved]  (Read 196 times)

Lukapple

  • Full Member
  • ***
  • Posts: 185
Wrong last value of network connected node [solved]
« on: April 05, 2021, 02:21:22 AM »
I've a network connected node, that pool data from my weather station using API, using this approach:

Code: [Select]
api.getStationsData(function(err, devices) {
            //temperature data
            var fakeSerialMsg = '['+nodeRightNow._id+']'+' C:'+devices[0].modules[0].dashboard_data.Temperature;
            processSerialData(fakeSerialMsg);
            //rain data
            fakeSerialMsg = '['+nodeRightNow._id+']'+' R:'+devices[0].modules[1].dashboard_data.Rain;
            processSerialData(fakeSerialMsg);

Everything worked fine, until I added the additional call of processSerialData to get to get the rain data.
And now it shows the wrong temperature info in the "Last value" field. Any idea why?



Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6531
  • Country: us
    • LowPowerLab
Re: Wrong last value of network connected node
« Reply #1 on: April 05, 2021, 10:55:56 AM »
What was the value if not "4.4"?

Lukapple

  • Full Member
  • ***
  • Posts: 185
Re: Wrong last value of network connected node
« Reply #2 on: April 05, 2021, 11:07:57 AM »
It was minus X.

It looks like it's somehow stuck at 4.4, but the values on the graph are correct.
Another example:


And the "refresh time" is also stuck. It looks like something went wrong yesterday when I added the Rain data.
Maybe I should try to delete the old measures?

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6531
  • Country: us
    • LowPowerLab
Re: Wrong last value of network connected node
« Reply #3 on: April 05, 2021, 11:23:33 AM »
My guess is you're probably overriding something.
Ensure you don't have any duplicate metric definitions.
Otherwise I can't tell just by looking at photos, it will take some debugging of whatever code you added or modified.

Lukapple

  • Full Member
  • ***
  • Posts: 185
Re: Wrong last value of network connected node
« Reply #4 on: April 05, 2021, 12:05:29 PM »
Here is some more info what exactly I do.

I added this event which triggers every 10 minutes
Code: [Select]
weatherStationPoll: {
  label:'Netatmo : temperature/rain Poll',
  icon:'fa-heartbeat',
  descr:'Poll temperature/rain from Netatmo outdoor module',
  nextSchedule: function(nodeAtScheduleTime) { return 10*60*1000; }, //runs every 10 min
  scheduledExecute: function(nodeAtScheduleTime) {
    db.findOne({ _id : nodeAtScheduleTime._id }, function (err, nodeRightNow) {
      if (nodeRightNow)
      {
        var netatmo = require('netatmo');
        var auth = {
          "client_id": "removed",
          "client_secret": "removed",
          "username": "removed",
          "password": "removed",
        };
        var api = new netatmo(auth);
        // Get Stations Data
        // See docs: https://dev.netatmo.com/dev/resources/technical/reference/weatherstation/getstationsdata
         api.getStationsData(function(err, devices) {
           var fakeSerialMsg = '['+nodeRightNow._id+']'+' C:'+devices[0].modules[0].dashboard_data.Temperature;
           processSerialData(fakeSerialMsg);
           //rain data
           fakeSerialMsg = '['+nodeRightNow._id+']'+' R:'+devices[0].modules[1].dashboard_data.Rain;
           processSerialData(fakeSerialMsg);
         });         
      }
    });
  },
},

and this additional metrics for Rain data:
Code: [Select]
exports.metrics = {
  R : { name:'Rain', regexp:/\R:([\d\.]+)\b/i, pin:1, graph:1},
}

I've checked the console logs and if you check the first line, there is correct temperature "C:3.4", but in the second line with the rain data, there is also temperature data, but with old value "4.4"

Code: [Select]
[04-04-21_23:21:39.710] [INFO]   [201] DB-Updated: processSerialData('[201] C:3.4',undefined):entry={"_id":201,"updated":1617571299679,"type":"WeatherMote","label":"Temperatura/dež dvorišče","descr":"Netatmo zunanji senzor","metrics":{"C":{"label":"C","value":3.4,"unit":"°","updated":1617571299679,"pin":1610044205214,"graph":1}},"events":{"weatherStationPoll":{"enabled":1,"executeDateTime":"2021-04-04T21:31:28.113Z"},"messageAirTempToDMD":{"enabled":1},"messageToOOK1":{"enabled":1}}}
[04-04-21_23:21:39.769] [INFO]   [201] DB-Updated: processSerialData('[201] R:0',undefined)  :entry={"_id":201,"updated":1617571299691,"type":"WeatherMote","label":"Temperatura/dež dvorišče","descr":"Netatmo zunanji senzor","metrics":{"C":{"label":"C","value":4.4,"unit":"°","updated":1617568735368,"pin":1610044205214,"graph":1},"Rain":{"label":"Rain","value":0,"updated":1617571299691,"pin":1,"graph":1}},"events":{"weatherStationPoll":{"enabled":1,"executeDateTime":"2021-04-04T21:31:28.113Z"},"messageAirTempToDMD":{"enabled":1},"messageToOOK1":{"enabled":1}}}

And here is the example contents from API Response, "modules" array:

Code: [Select]
[
  {
    _id: 'removed',
    type: 'NAModule1',
    module_name: 'Dvorišče',
    last_setup: 1573229405,
    data_type: [ 'Temperature', 'Humidity' ],
    battery_percent: 64,
    reachable: true,
    firmware: 50,
    last_message: 1617637983,
    last_seen: 1617637971,
    rf_status: 62,
    battery_vp: 5348,
    dashboard_data: {
      time_utc: 1617637971,
      Temperature: 12.8,
      Humidity: 48,
      min_temp: -0.5,
      max_temp: 15.1,
      date_max_temp: 1617628896,
      date_min_temp: 1617598391,
      temp_trend: 'down'
    }
  },
  {
    _id: 'removed',
    type: 'NAModule3',
    module_name: 'Smart Rain Gauge',
    last_setup: 1617370670,
    data_type: [ 'Rain' ],
    battery_percent: 100,
    reachable: true,
    firmware: 12,
    last_message: 1617637984,
    last_seen: 1617637984,
    rf_status: 83,
    battery_vp: 6278,
    dashboard_data: {
      time_utc: 1617637984,
      Rain: 0.101,
      sum_rain_1: 0.202,
      sum_rain_24: 0.2
    }
  }
]

Am I doing something wrong in that weatherStationPoll event?

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6531
  • Country: us
    • LowPowerLab
Re: Wrong last value of network connected node
« Reply #5 on: April 05, 2021, 12:26:47 PM »
Looks ok at first glance.
BTW You could call processSerialData a single time instead of twice - ie concatenate the metrics in a single message.

Lukapple

  • Full Member
  • ***
  • Posts: 185
Re: Wrong last value of network connected node
« Reply #6 on: April 05, 2021, 12:32:23 PM »
Thanks for the hint. Not I'm not sure what's the correct format for merging those data together. Should the data be comma separated?

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6531
  • Country: us
    • LowPowerLab
Re: Wrong last value of network connected node
« Reply #7 on: April 05, 2021, 01:42:47 PM »
It has to be space separated:

TOKEN:VALUE TOKEN2:VALUE2 TOKEN3

Lukapple

  • Full Member
  • ***
  • Posts: 185
Re: Wrong last value of network connected node
« Reply #8 on: April 05, 2021, 03:03:58 PM »
That worked perfectly. Temperature is now properly displayed. Thanks Felix! :)