IBM Watson Sensor Support

ALright thanks for all the help I really appreciate it <3

Actually is there anyway to reset to variable to 0 at the beginning of each "session"

Session?

You mean when node-red restarts?

Global variables don't normally retain value. Have you tried restarting?

How do i restart the whole program

I already lost some of my saves lol by not being careful


Also what is going on with kicks here

No idea. But if you add debug nodes like I suggested twice before, you could figure it out yourself.

1 Like

any idea on reseting the values to 0 though?

Like I said, restarting node-red will clear values.

You can also use an inject node linked to a change node to set global.count to zero.

Can I also suggest you do some reading and check out the cookbook. Try the examples. Learn to walk before you try to run.

And don't forget to add debug nodes after every node so you can understand what happens as the msg travels through the flow.

Do you have any idea why my variables for kicks and sprints might be getting confused because currently they are printing as the same number as you can see in the screenshot. what should i do?

As @Steve-Mcl has suggested quite a lot of times, you can use a Debug node throughout your flow to figure out what is happening to the messages. You have not acknowledged that advice yet ask us for what could be happening in your flows.

We cannot tell anything from a screenshot with no information about what those Function nodes currently contain.

If you wanted to share some actual details, then make sure you read this post first on how to properly share code in the forum - How to share code or flow json

Here is my latest code. As you can see the kicks and sprints seem to be getting confused in the output for some reason. This project is for a summer program that I am doing in high school at UC Davis, that is why I have very basic knowledge and require substantial assistance. All your help is appreciated :slight_smile:

Def Kicks

var kick = global.get( "count")||0;
// sprint++;
global.set('count', kick);
msg.payload.kick = kick; 
return msg;

Analyze Kicks

var gyro = msg.payload.d.Y
var kick = msg.payload.kick;
if (gyro < -600) {
   kick++;
   global.set('count', kick);
}
msg.payload.kick = kick;
return msg;

Def Sprint

var sprint = global.get( "count")||0;
// sprint++;
global.set('count', sprint);
msg.payload.sprint = sprint; 
return msg;

Analyze Sprint

var accel = msg.payload.d.Z 
var sprint = msg.payload.sprint;
if (accel > 1500) {
   sprint++;
   global.set('count', sprint);
}
msg.payload.sprint = sprint;
return msg;

Screenshot%20(10)

How come two different variables have the same value?

What do the messages coming from the IBM IoT node look like? From the screenshot, I see you have a Debug node attached to it, but it appears to be configured to only show msg.payload.d.Level - so we cannot see what the full message looks like.

You asked why the kicks and sprints values were 'getting confused'.

You are storing both in the same global context value called count - that is why they are the same.

So if I change one of them will they be different?

You are storing the two different values in the same context variable. So yes, you need to change something.

Thanks! Do you know any way to introduce time (eg. implementing a delay after a kick has been detected?)

Have you looked at the Delay node?

Hi again, I'm sorry to say but it seems you have tried nothing and you're all out of ideas!

If you aren't careful, you will lose support from us unpaid folk.

Have you looked at the available nodes? There is one called delay. Give it a try, drop on onto the editor & read the built in info.

Also, search the flows library

Give it a try.

IF and only IF you get stuck, 1st Search the forum THEN 2nd ask a question stating what you have tried and what went wrong.

Good luck.

1 Like

checking it out rn thanks