Sensor

As far as I can see, if you send ledState/status=0, the RGB LED goes off and the imp will idle until you subsequently send ledState/status=1. If you are continuing to read light values - presumably you are seeing this in the log - then sensor is not zero when it is called.

I would power-cycle your imp manually to make sure it has the latest version of your software if you have not done this.

Couple of observations:

  1. The imp.configure line is no longer necessary - remove it.
  2. The setTime() function doesn’t need the ‘if…’ statement. If you want the LEDs to turn off, you just send a non-zero time value which can be used by imp.wakeup. Are you ever going to send a zero value?

my main problem is the light sensor, this is why my program does not do what i want. and i dont’t know what i have to modify at my readSensor function to make the program work.

what I have to modify at my readSensor() function, I want to make my light sensor to read values and to send them to my RGB Led. At the moment that function reads only a value and then it’s not reading another value.

I need some help for this problem, I’ve recently start programing and I don’t know how to resolve it.

You can use wakeup to have something happen again in the future.
https://electricimp.com/docs/api/imp/wakeup/

As your code is now the light is only read once when told to do so from the agent.

OK, @eleonora0403, I think I understand now what you are trying to do. I would add the following at the start of the device code:

timer <- 0;

I would change setSensor() to:

function setSensor(ledState) { status=ledState; if (status) //status=1 { readSensor(); } else // status=0 { redPin.write(0); greenPin.write(0); bluePin.write(0); imp.cancelwakeup(timer); } }

and change readSensor() to:

function readSensor() { light=lightreading.read(); local value = 1- (light / 65535.0); redPin.write(value); greenPin.write(value); bluePin.write(value); server.log(format("Lightness is:" +light)); timer = imp.wakeup(5.0, readSensor); }

This will make readSensor() run every five seconds after it is first called, or until the agent sends an “sensor” message with 0 as the data:

device.send("sensor", 0);

thanks a lot I appreciate your help :smiley: