Example #1
0
//--------------------------------------------------------------------------------------------------
// Send payload data via RF
//-------------------------------------------------------------------------------------------------
void tools_rfwrite (byte myNodeID, const void* ptr, uint8_t len) {
   if(tools_ack()){
      for (byte i = 0; i <= RETRY_LIMIT; ++i) {  // tx and wait for ack up to RETRY_LIMIT times
        rf12_sleep(-1);              // Wake up RF module
         while (!rf12_canSend())
         rf12_recvDone();
         rf12_sendStart(RF12_HDR_ACK, ptr, len); 
         rf12_sendWait(2);           // Wait for RF to finish sending while in standby mode
         byte acked = waitForAck(myNodeID);  // Wait for ACK
         rf12_sleep(0);              // Put RF module to sleep
         if (acked) { return; }      // Return if ACK received
     
         Sleepy::loseSomeTime(RETRY_PERIOD * 1000);     // If no ack received wait and try again
      }
   }
   else {
      rf12_sleep(-1);              // Wake up RF module
      while (!rf12_canSend())
         rf12_recvDone();
      rf12_sendStart(0, ptr, len); 
      rf12_sendWait(2);           // Wait for RF to finish sending while in standby mode
      rf12_sleep(0);              // Put RF module to sleep
      return;
   }
}
Example #2
0
void loop() {
  for (int i = 0; i < NUM_COUNTERS; i++) { // loop through the counters
    // read the counter input pin:
    counterState[i] = digitalRead(counterPin[i]);

    // compare the counterState to its previous state
    if (counterState[i] != lastCounterState[i]) {
      if (counterState[i] == LOW) {
        digitalWrite(LED1, HIGH);
        // if the current state is HIGH then the button
        // wend from off to on:
#ifdef DEBUG_ENABLED
        Serial.print(i);
        Serial.println(" LOW");
#endif

				payload.active_counter = i;
				counterMillis[i] = millis();
				payload.counter_millis = counterMillis[i];
 
        if (counterMillis[i] - lastCounterMillis[i] > 90) {
				// send a packet
				while (!rf12_canSend()) 
					rf12_recvDone();

				// send as broadcast, payload will be encrypted
				rf12_sendStart(0, &payload, sizeof(payload));
				rf12_sendWait(1);
        }
        lastCounterMillis[i] = counterMillis[i];
#ifdef DEBUG_ENABLED
      } else {
        // transision from LOW to HIGH means the pulse is over
        // we're not interested in that
        Serial.print(i);
        Serial.println(" HIGH"); 
#endif
      }
      Serial.println();
    }
    // save the current state as the last state, 
    //for next time through the loop
    lastCounterState[i] = counterState[i];

    if (led1Timer.poll(90)) {
      digitalWrite(LED1, LOW);
    }
  }
  wdt_reset();
  
}
Example #3
0
bool RF12Module::Send(byte destination, byte* message, uint8_t sendLen,
		bool needAck) {
	if (rf12_canSend()) {
		byte header = needAck ? RF12_HDR_ACK : 0;
		if (destination)
			header |= RF12_HDR_DST | destination;
		rf12_sendStart(header, message, sendLen);
		rf12_sendWait(1);
		return true;
	} else {
		// What must we do...
		return false;
	}
}
Example #4
0
/// @deprecated Use the 3-arg version, followed by a call to rf12_sendWait.
void rf12_sendStart (uint8_t hdr, const void* ptr, uint8_t len, uint8_t sync) {
    rf12_sendStart(hdr, ptr, len);
    rf12_sendWait(sync);
}