void
LightLampApplication::
execute(void* userdata) {

    //grab new light value
    int16 newlight = telos->light();


    //check thresholds
    if (newlight < 200) {
        //need to switch off
        if (light >= 200) {
            // previously was on
            os().debug("Switch On The LAMP");
            os().radio().send(0xffff, 13, messopen, 0, 0);
            telos->led_on(1);
        }
    } else {
        //need to switch on
        if (light < 200) {
            //previously was off
            os().debug("Switch Off The LAMP");
            os().radio().send(0xffff, 13, messclose, 0, 0);
            telos->led_off(1);
        }
    }

    //set the light value as the current
    light = newlight;
    os().debug("light:%d", light);

    //broadcast a beacon
    os().radio().send(0xffff, 4, echomsg, 0, 0);
    os().debug("echo");

    //repeat every 1 minute
    os().add_task_in(Time(1, 0), this, NULL);
}