void LightLampApplication:: boot(void) { os().debug("ON"); TOGGLE_LED(LED_BLUE); os().allow_doze(false); os().allow_sleep(false); os().radio().hardware_radio().set_channel(17); telos = new TelosbModule(os_); telos->init(); telos->add_button_handler(this); os().dispatcher().add_receiver(this); //Create the command payload - off messclose[0] = 0x7f; //mksense messclose[1] = 0x69; //mksense messclose[2] = 105; //mksense //Create the command payload - on messopen[0] = 0x7f; //mksense messopen[1] = 0x69; //mksense messopen[2] = 105; //mksense //Create the command payload - switch messwitch[0] = 0x7f; //mksense messwitch[1] = 0x69; //mksense messwitch[2] = 105; //mksense for (int i = 3; i < 13; i++) { messopen[i] = 1; //on messclose[i] = 0; //off messwitch[i] = 99; //swithc } //create the echo payload echomsg[0] = 0x7f; //mksense echomsg[1] = 0x69; //mksense echomsg[2] = 100; //mksense echomsg[3] = 42; //echo payload //get the initial light value light = telos->light(); //start periodic tasks os().add_task_in(Time(1, 0), this, NULL); }
void WISEBEDApplication::read_sensors() { #if defined (ISENSE_PACEMATE) #endif #if defined (ISENSE_MSP430) os().debug("wiseml;6;%x;%i",os().id(), telos_->humidity()); uint16 temp = telos_->temperature(); uint16 temprest = temp % 10; os().debug("wiseml;1;%x;%i,%i",os().id(), temp / 10, temprest); os().debug("wiseml;2;%x;%i",os().id(), telos_->light()); os().debug("wiseml;3;%x;%i",os().id(), telos_->infrared()); spyglass_->paintNodeWithTemp(os().id(), temp); spyglass_->paintNodeWithLight(os().id(), telos_->light()); spyglass_->paintNodeWithIrda(os().id(), telos_->infrared()); #endif #if defined (ISENSE_JENNIC_JN513xR1) if (em_active_ == true) { temp_ = em_->temp_sensor()->temperature(); lux_ = em_->light_sensor()->luminance(); os().debug("wiseml;1;%x;%i",os().id(), temp_); os().debug("wiseml;2;%x;%d",os().id(), lux_); spyglass_->paintNodeWithTemp(os().id(), temp_); spyglass_->paintNodeWithLight(os().id(), lux_); } else { } #endif }
void WISEBEDApplication::init_sensors() { #if defined (ISENSE_PACEMATE) #endif #if defined (ISENSE_MSP430) telos_->init(); #endif #if defined (ISENSE_JENNIC_JN513xR1) if (em_->temp_sensor() != NULL) { em_->temp_sensor()->enable(); } else os().fatal("Could not allocate temp sensor"); em_->enable(true); temp_ = em_->temp_sensor()->temperature(); if (temp_ == -127 ) // node with PIR and ACC { em_active_ = false; } if(em_active_ == true) { if (em_->light_sensor() != NULL) { em_->light_sensor()->enable(); } else os().fatal("Could not allocate light sensor"); } else { acc_ = new LisAccelerometer(os()); if ((acc_ != NULL) && (pir_!= NULL)) { acc_->set_mode(MODE_THRESHOLD); acc_->set_threshold(100); acc_->set_handler(this); acc_->enable(); pir_->set_sensor_handler(this); pir_->set_pir_sensor_int_interval( 2000 ); pir_->enable(); } } #endif }
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); }