The problem seems to be in the function node "managing all the AQI'S".
I want to manage all the numbers i get from before ( 1 to 5) to output always the highest one.
I try'd it with the Math.max() function I found but I don't know if it just don't work or if i messed up entirely
The variables does not look like they will get any values at all
The code in the function node does not look correct. You can add a number of node.warn() statements to check that the values are correct. You should start with that
EDIT: I would expect that you set the variables values using the incoming data. You have to filter on the key in the msg object like:
I just want one thing. as you can so i recieve in the debug "value control" to numbers. one is called "IAQ_pm2" and the other one is "IAQ_pm10". I just want that always the higher number gets returned. So in this case below, I want that the debug "extracontrol" shows the number "3", because its the higher one.
And I want this procedere with 5 parameters as you can see. But now I can only test it with these two because the other sensors are not connected right now.
So do you have an example how I should code the function node "managing all the AQI's" that I get always the highest number of all 5 inputs?
If you look at the debug node output you will see that each message only contains one of the values, the other one is not present so you can't take the maximum of the two of them, as only one is available at a time. If these values are coming in from different sources then you need to join the messages together to give you both in one message.
Note that you will need the values in msg.payload and each source must have a unique topic. It is almost always more convenient to put values in msg.payload anyway, most nodes expect, by default, the data to be there. If you don't understand what I have just written then I recommend watching this playlist: Node-RED Essentials. The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.
Also read the node red docs page Working with Messages. Unless you understand what is on that page you will find things very difficult.
As with many things in life there are so many alternatives. One is to use context to capture the values from the incoming messages. An example like this I think will work (you have to extend it to cover all your values). Try the code in your function node
You are the greatest man It works perfect.
After I get a good grade for this project I'll send you a present Don't know what I would have done without all your help here
Thank you very much for your kind words, it was a pleasure to help! I'm glad it works as you want. Node-RED has so many possibilities to be applied in various projects for various tasks, it's really powerful!!
I hope you succeed with your examination at your university!
hello @krambriw !
I'm working now for 2 weeks to connect another measuring device like you showed me. And i feel a little embarrassed to ask you again for your help after all of your work, but I'm not getting any further with it.
I changed the VID and PID and all the names in your script for the new device, but after many hours it still doesn't work. (I didn't connect anything with mqtt or node red, I first want to make the script work)
Now I have the thought that maybe the measuring device isn't compatible for this method.
Do you mind to look over the operation manual? I read it 10 times but I don't get any smarter
So what happens when you start the script? Does it find the device, does it connect correctly?
The document you linked to does only describe the product, there is nothing in about how the data is expected to look like
EDIT: I see one major problem, it could very well be why it does'nt work. You have this line:
As target you have "luxAnalyzer" but here is no such function, it is instead "sdsAnalyzer". So replace sdsAnalyzer with luxAnalyzer (it is in two places in the script) and try then again
on page 3 you can see at the bottom the bit rate and how many data bits are there.
But I still doesn't know which bit has the data I need, I'm working on this to get the information from the manufacturer.
I think I changed all the lines you mentioned in the script. When I start it I get the following.
Has this something to do with that I don't know which bit contains the right information or is there another problem I didn't see?
EDIT: I found out that the device disconnects really fast, maybe this is the problem that the script doesn't detect anything because it's already disconnect?