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

Wrong structure output somoetimes. #315

Open
Just-another-pleb opened this issue May 13, 2024 · 0 comments
Open

Wrong structure output somoetimes. #315

Just-another-pleb opened this issue May 13, 2024 · 0 comments

Comments

@Just-another-pleb
Copy link

Just-another-pleb commented May 13, 2024

(After posting edit)

Sorry, I am now suspicious this is me reporting an error that doesn't exist.
Please indulge me ignorance.
I shall add code which I suspect is really the problem.

I've asked on the forum but got dismissed.
As I am still seeing things, I would like to check there is/not a problem.

(Second edit)
Ok, suspicion that the msg.payload.rain may not be set (line 22 and 27)
If it isn't raining, that isn't set.
And so it glitches at sunrise (the first invocation for today.
And then I later - when testing - get a message. It is sunny and no rain.
There wasn't an incoming message undefined.
If it is sunny, then msg.payload.rain wouldn't be set, so......
Sorry. I hope this isn't a waste of your time.

Openweathermap

What are the steps to reproduce?

Sometimes when invoked it seems to be sending wrongly structured messages.
(Above my head. My flow is giving me messages saying things are not as expected/usual.)
See screen shots.

This is a good cycle.

Screenshot from 2024-05-14 08-13-57

Follow green line. I test it and I get good messages.
Note the green line/arrow.

Sometimes I do HOURLY reading to get the total rain fallen since a time.
Be it midnight or sunrise.
(I think that doesn't come into it as I have added the function node just before the node to make sure it is always getting the same trigger.)

What happens?

Today when I looked at the page (from a remote machine) I see this:

Screenshot from 2024-05-14 08-12-06

Note: Incoming message undefined

What do you expect to happen?

Well, a correctly formatted message as per shown with the GREEN screen shot above.

This only happens Now and then.
Most messages received are ok. Some: Not so.

Please tell us about your environment:

System Details:

NR 3.0.2
RasPi 3b+
Buster

pi@BedPi:~ $ node --version
v16.20.2

Using Fire fox on remote machine to view page.

Added code
Look at line: 27 (if block)
That may be the problem.

//  2024 04 09
//
//  Input:  `msg.payload.rain` for normal ops.
//  Ouptut: `msg.rain_now`

//===================================================================================

let rainamount = context.get('rainamount') || []    // get context variable, default empty array

//      If `reset` message received.
if (msg.reset == "reset") {
    node.status({ text: "RESET" });
    flow.set("total_rain", 0);
    flow.set("todays_rain", 0);
    context.set('rainamount', []);
    rainamount = [];
    return;
}

let todays_rain = flow.get("total_rain") || 0;
node.warn("Today's rain is " + todays_rain);
node.warn("Incoming message " + msg.payload.rain);

//==================================================
//  2024 04 09
//      This is if there is no rain and the message structure is not defined.
if (msg.payload.rain == undefined) {
    node.warn("no rain detected in message");
    msg.payload.rain = 0;
    node.warn("Set payload.rain to 0");
    node.warn(msg.payload.rain);
}
//==================================================

//  2024 04 09
//      This is where the latest value is parsed.
let rain_now = msg.payload.rain * 10;
node.warn("at this point rain_now is = " + rain_now / 10);

//==================================================
//  2024 04 09      Get `count` value.
let count = msg.count || 0;

node.warn("count value set to " + count);

if (count == 0)
{
    node.warn("I shouldn't be here");
    return;
}
//  Reduce `count` size.
count = count / 4;
node.warn("modified count value set to " + count);

//==================================================

//==================================================
//  2024 04 09
//
//  Store rain values in context to maybe help with tracing things.
rainamount.push(rain_now)    // Add a new array element 
context.set('rainamount', rainamount)   // save to node context
//==================================================

node.warn("Adding rain totals together (count included)");

todays_rain = (todays_rain + rain_now);
flow.set("total_rain", todays_rain);

node.warn("Value 1 = " + todays_rain);

todays_rain = Math.round(todays_rain / count) / 10;

node.warn("Value 2 = " + todays_rain);

node.status({ text: "counter = " + msg.count + " Total rain today = " + todays_rain + " Rain = " + rain_now});

flow.set("count", count);

//  *********   msg.rain_now used to send data
msg.rain_now = todays_rain;
msg.topic = null;

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

No branches or pull requests

1 participant