manal
Posts: 18
Joined: Mon Nov 05, 2018 5:05 am

Deactivate sensor

Fri Nov 09, 2018 1:43 pm

Hey all,

I have connected digital sensor and led using node-red in raspberry pi 3 , these devices work using nodes already exist in node-red without any need to write python code to get data from sensor or control led. I am trying to use python code to deactivate the sensor to stop send data or zero value, and code to activate it again. I used unexport for GPIO number 7 where my sensor is connected, but it doesn't work. Actually, I am new with raspberry pi 3 and I don't have strong knowledge. could you help me to know how can I do this ?

Brandon92
Posts: 870
Joined: Wed Jul 25, 2018 9:29 pm
Location: The Netherlands

Re: Deactivate sensor

Fri Nov 09, 2018 4:33 pm

You need to give not information than that:
  • what for sensor, so the type?
  • what for code did you try or made?
  • how did you connect it?
Otherwise we can not help you with your question. There exist a lot of sensors.

Heater
Posts: 16091
Joined: Tue Jul 17, 2012 3:02 pm

Re: Deactivate sensor

Fri Nov 09, 2018 6:09 pm

I have no idea what sensor you are talking about but in my opinion using two programs to access the same sensor makes no sense and could lead to all kinds of chaos. Why not just keep life simple and do it all from the same program? In the language of your choice.

Or, if you really need two programs in different languages separate responsibility between them in a logical way. Have one program deal with the sensor, reading and writing, enabling and disabling. Have the other program communicate with that sensor program sending it commands to read/write/enable/disable, and using the data in whatever way you need.
Memory in C++ is a leaky abstraction .

PhatFil
Posts: 1685
Joined: Thu Apr 13, 2017 3:55 pm
Location: Oxford UK

Re: Deactivate sensor

Fri Nov 09, 2018 6:43 pm

If your dealing with active sensors which use power you can use a relay or transistor to switch power on and off to them to turn them on/off
you could if within the pis capacity over gpio use a gpio as output and set it high to provide vcc power to some sensors..

However if you can program the pi to turn sensors on and off when desired, you can equally 'code' or design a flow within node red that disregards the sensor input under identical conditions which would save the expense and work involved in modifying the h/w set up.

As node red utilises MQTT when you have sensor data you want to 'use' publish it under a 'USE-ME' topic perhaps?

The power of node red can take a wee while to appreciate, tbh im still struggling with the paradigm shift from focusing on execution flow..

manal
Posts: 18
Joined: Mon Nov 05, 2018 5:05 am

Re: Deactivate sensor

Sat Nov 10, 2018 1:50 pm

I use DS18B20 sensor, and it connects and sends data through node-red, I created a full IoT environment, and it works very well. but, I want to test something with this sensor, because that I want to write python code to disable it and prevent it from sending data .

User avatar
DougieLawson
Posts: 39296
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Deactivate sensor

Sat Nov 10, 2018 2:06 pm

sudo rmmod w1_gpio w1_therm wire
will disable it.

sudo modprobe w1_gpio; sudo modprobe w1_therm; sudo modprobe wire
will re-enable it.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

manal
Posts: 18
Joined: Mon Nov 05, 2018 5:05 am

Re: Deactivate sensor

Sun Nov 18, 2018 2:34 am

Thanks for your helping. actually, I need a code to enforce the sensor to send zero instead of its real value. could you help me, please?

PhatFil
Posts: 1685
Joined: Thu Apr 13, 2017 3:55 pm
Location: Oxford UK

Re: Deactivate sensor

Sun Nov 18, 2018 5:46 pm

manal wrote:
Sun Nov 18, 2018 2:34 am
Thanks for your helping. actually, I need a code to enforce the sensor to send zero instead of its real value. could you help me, please?

write a function containing the conditional rules that dictate when you want a temperature or 0 returned. and either return 0 or the sensor reading,

manal
Posts: 18
Joined: Mon Nov 05, 2018 5:05 am

Re: Deactivate sensor

Mon Nov 19, 2018 1:41 am

Actually, I didn't read sensor values through code, there is a node in node-red called ds18b20 , it takes the reading directly. because of that I don't know how I can do it . I want to write python code to let this node return zero value when I run this python script. I will be grateful if anyone help me .

Brandon92
Posts: 870
Joined: Wed Jul 25, 2018 9:29 pm
Location: The Netherlands

Re: Deactivate sensor

Mon Nov 19, 2018 5:29 am

You could write a if statement that decide if you are getting the real value of the ds1820 or the 0 value. By the way, what happends when your sensor sense 0 degrees?

But to make the if statement possible, you need to know "before" hand with value you want.

manal
Posts: 18
Joined: Mon Nov 05, 2018 5:05 am

Re: Deactivate sensor

Mon Nov 19, 2018 5:38 am

nothing to happen, I just test something that relate to the sensor.
I don't want to change it through node-red, I want to change it using external code such as python script
can I change the value "t" in w1_slave and write new value which is zero, so the node-red node will read the new value. or this is not applicable and it doesn't work.

Brandon92
Posts: 870
Joined: Wed Jul 25, 2018 9:29 pm
Location: The Netherlands

Re: Deactivate sensor

Mon Nov 19, 2018 5:56 am

I don't think it is possible to change the value that is coming directly outside the sensor. Without changing the code. You need to decide if you want the keep the real value or the modified value.

If it is only for testing purposes, you could also remove the 'real sensor' part and change that in a constant value. So, you can test the other part of your code /system.

PhatFil
Posts: 1685
Joined: Thu Apr 13, 2017 3:55 pm
Location: Oxford UK

Re: Deactivate sensor

Mon Nov 19, 2018 3:13 pm

with node red you can use a function node , or a switch node or perhaps a change node.

can you describe the conditions under which you want a 0 reading?

Node red is very powerful , took me a while to stop writting epic flows and consider using small 'more atomic' flows which are stimulated by a mqtt publication and result in a mqtt publication..

in your case consider a situation where you publish something like "read temperature" and "Read 0 temperatature" under different conditions and have a further flow that reacts to the resulting publication of a temperature be it real or 0

Return to “General discussion”