 #include <SPI.h>
 #include <sleeplib.h>
 
+ISR(WDT_vect) { watchdogEvent(); }
+
 // Structure of our payload
 struct payload_t
 {
   uint16_t orderno;
-  uint16_t seq; 
+  uint16_t seq;
   float value;
 };
 
-payload_t payload;    
+payload_t payload;
 
 enum radiomode_t { radio_sleep, radio_listen } radiomode;
 

// Network uses that radio
RF24Network network(radio);




void setup(void) {
  pinMode(STATUSLED, OUTPUT);     
  pinMode(VMESS_OUT, OUTPUT);  
  pinMode(VMESS_IN, INPUT);
  analogReference(INTERNAL);
  SPI.begin();

  
  //#################
  // END run frequently
  //#################
  }
  if ( network.available() ) {
    network_busy = true;
    stayawakeloopcount=0;
    network.read(rxheader,&payload,sizeof(payload));
    action_loop();
  }
  digitalWrite(STATUSLED,STATUSLED_OFF);
  if (stayawakeloopcount > STAYAWAKEDEFAULT) {
    network_busy=false;
    stayawakeloopcount=0;
  }
  if ( network_busy ) {
    sleep4ms(250);
    stayawakeloopcount++;
  } else {
    if ( radiomode == radio_sleep ) radio.powerDown();
    sleep4ms(sleeptime*1000);
    if ( radiomode == radio_sleep ) radio.powerUp();
    sleep4ms(1000);
  }
}
