arduino pro mini reed switch/sleep mode issue

I've been searching to find if anyone is having trouble with a reed switch and sleep mode for arduino pro mini. Nothing really comes up.
If I run this sketch will just the sleep mode call disabled I can read the reed switch and it works perfectly.

If I attempt sleep mode I go to sleep and never wake up.
I'm using arduino pro mini board and reed switch directly to pin 3 and ground on the other end.

#include <RFM69.h>
#include <SPI.h>
#include <avr/interrupt.h>
#include <avr/power.h>
#include <avr/sleep.h>
#include <avr/io.h>

// Addresses for this node. CHANGE THESE FOR EACH NODE!

#define NETWORKID     0   // Must be the same for all nodes
#define MYNODEID      2   // My node ID
#define TONODEID      1   // Destination node ID

// RFM69 frequency, uncomment the frequency of your module:
#define FREQUENCY   RF69_433MHZ
//#define FREQUENCY     RF69_915MHZ

// AES encryption (or not):
#define ENCRYPT       true // Set to "true" to use encryption
#define ENCRYPTKEY    "TOPSECRETPASSWRD" // Use the same 16-byte key on all nodes

// Use ACKnowledge when sending messages (or not):
#define USEACK        true // Request ACKs or not

// Packet sent/received indicator LED (optional):
#define LED_PIN           6 // LED positive pin
#define GND           8 // LED ground pin
int pirInputPin = 3; 
volatile int sendSignal = 0;   

// Create a library object for our RFM69HCW module:
RFM69 radio;

void setup()
{
  Serial.begin(9600);
  Serial.println("STARTUP");
  // Set up the indicator LED (optional):
  pinMode(13, OUTPUT);

  // Initialize the RFM69HCW:
  radio.initialize(FREQUENCY, MYNODEID, NETWORKID);
  radio.setHighPower(); // Always use this for RFM69HCW

  // Turn on encryption if desired:
  if (ENCRYPT)
    radio.encrypt(ENCRYPTKEY);

  pinMode(pirInputPin, INPUT_PULLUP);  
  
}

void loop()
{

  Serial.println("Loop ");
  
  int proximity = digitalRead(pirInputPin); // Read the state of the switch
  if (proximity == LOW) // If the pin reads low, the switch is closed.
  {
    Serial.println("Switch closed");
    digitalWrite(LED_PIN, HIGH); // Turn the LED on
  }
  else
  {
    Serial.println("Switch OPEN");
    digitalWrite(LED_PIN, LOW); // Turn the LED off
   
    
    
  }
  
 
   sleepNow();
      
}

void sleepNow()
{
    Serial.println("Sleepy Time Now");
    Serial.flush();
    
    //pin 3 is now attached
    attachInterrupt(digitalPinToInterrupt(pirInputPin), pinInterrupt, CHANGE);
  
    // Choose our preferred sleep mode:
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);
 
    // Set sleep enable (SE) bit:
    sleep_enable();

    digitalWrite(13, LOW);     // turn off LED13 status on-board LED
    //digitalWrite(LEDPIN, LOW);  // turn off status LED8 (ON when pro mini-awake/OFF when pro mini-asleep)
    delay(100);
    
    power_adc_disable();
    power_spi_disable();
    power_timer0_disable();
    power_timer1_disable();
    power_timer2_disable();
    power_twi_disable();  
    
    // Put the device to sleep:
    sleep_mode();
 
    // Upon waking up, sketch continues from this point.
    sleep_disable();
    
    delay(100);
    
}

void pinInterrupt(void)
{
   
    detachInterrupt(pirInputPin);
    sendSignal = 1;
    
}

void sendData(){
 
      
      Serial.print("Sending to node ");
      Serial.println(TONODEID, DEC);
      
      char radiopacket[20] = "frontdoor";     
      if (USEACK)
      {
        if (radio.sendWithRetry(TONODEID, radiopacket, strlen(radiopacket)))
          Serial.println("ACK received!");
        else
          Serial.println("no ACK received");
      }else // don't use ACK 
      {
        radio.send(TONODEID, radiopacket, strlen(radiopacket));
      }
      
      delay(500);
      
  
}

void Blink(byte PIN, int DELAY_MS)
// Blink an LED for a given number of ms
{
  digitalWrite(PIN,HIGH);
  delay(DELAY_MS);
  digitalWrite(PIN,LOW);
}
  pinMode(pirInputPin, INPUT); 
  digitalWrite(pirInputPin, INPUT_PULLUP);

The second argument to digitalWrite() is NOT INPUT_PULLUP. Pay attention to where INPUT_PULLUP makes sense.

  Serial.flush();

The only time this makes sense is right before going to sleep. While everything between this statement and going to sleep is commented out, that code should have been deleted or put before this statement. You'll miss output if you ever uncomment that code.

I've fixed the code. Any ideas why the reed switch works fine not in sleep mode but fails triggering the interrupt?

Is the reed switch connected to the pirInputPin? Why the heck is it connected to a pin with such a misleading name?

I figured it out. Turns out I needed to run the LowPower.h library from sparkfun.

code below is working in case anyone else runs into this.

// RFM69HCW Example Sketch
// Send serial input characters from one RFM69 node to another
// Based on RFM69 library sample code by Felix Rusu
// http://LowPowerLab.com/contact
// Modified for RFM69HCW by Mike Grusin, 4/16

// This sketch will show you the basics of using an
// RFM69HCW radio module. SparkFun's part numbers are:
// 915MHz: https://www.sparkfun.com/products/12775
// 434MHz: https://www.sparkfun.com/products/12823

// See the hook-up guide for wiring instructions:
// https://learn.sparkfun.com/tutorials/rfm69hcw-hookup-guide

// Uses the RFM69 library by Felix Rusu, LowPowerLab.com
// Original library: https://www.github.com/lowpowerlab/rfm69
// SparkFun repository: https://github.com/sparkfun/RFM69HCW_Breakout

// Include the RFM69 and SPI libraries:

#include <RFM69.h>
#include <SPI.h>
#include <avr/interrupt.h>
#include <LowPower.h>

//#include <avr/power.h>
//#include <avr/sleep.h>
//#include <avr/io.h>

// Addresses for this node. CHANGE THESE FOR EACH NODE!

#define NETWORKID     0   // Must be the same for all nodes
#define MYNODEID      2   // My node ID
#define TONODEID      1   // Destination node ID

// RFM69 frequency, uncomment the frequency of your module:
#define FREQUENCY   RF69_433MHZ
//#define FREQUENCY     RF69_915MHZ

// AES encryption (or not):
#define ENCRYPT       true // Set to "true" to use encryption
#define ENCRYPTKEY    "TOPSECRETPASSWRD" // Use the same 16-byte key on all nodes

// Use ACKnowledge when sending messages (or not):
#define USEACK        true // Request ACKs or not

// Packet sent/received indicator LED (optional):
#define LED_PIN           6 // LED positive pin
#define GND           8 // LED ground pin
int pirInputPin = 3; 
//volatile int sendSignal = 0;   

// Create a library object for our RFM69HCW module:

RFM69 radio;

void setup()
{
  Serial.begin(9600);
  Serial.println("STARTUP");
  // Set up the indicator LED (optional):
  pinMode(13, OUTPUT);

  // Initialize the RFM69HCW:
  radio.initialize(FREQUENCY, MYNODEID, NETWORKID);
  radio.setHighPower(); // Always use this for RFM69HCW

  // Turn on encryption if desired:
  if (ENCRYPT)
    radio.encrypt(ENCRYPTKEY);

  pinMode(pirInputPin, INPUT_PULLUP);  
  
}

void loop()
{

  Serial.println("Loop ");
  
  int proximity = digitalRead(pirInputPin); // Read the state of the switch
  if (proximity == LOW) // If the pin reads low, the switch is closed.
  {
    Serial.println("Switch closed");
    sendData(1);
  }
  else
  {
    Serial.println("Switch OPEN");
    digitalWrite(LED_PIN, HIGH); // Turn the LED off
    sendData(0);
    delay(200);
  }
  digitalWrite(LED_PIN, LOW); // Turn the LED off
  delay(100);
   sleepNow();
      
}

void sleepNow()
{
    Serial.println("Sleepy Time Now");
    Serial.flush();
    
    //pin 3 is now attached
    attachInterrupt(digitalPinToInterrupt(pirInputPin), pinInterrupt, CHANGE);
 
    //digitalWrite(13, LOW);     // turn off LED13 status on-board LED
    delay(100);
    
    LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);    
    
    
}

void pinInterrupt(void)
{
   
    detachInterrupt(pirInputPin);
    //sendSignal = 1;
    
}

void sendData(int state){
 
      
      Serial.print("Sending to node ");
      Serial.println(TONODEID, DEC);
      
      char data[61];
      char radiopacket[11] = "frontdoor-";
      sprintf(data, "%s%i", radiopacket, state);
      Serial.println(data);
      delay(100);
      
      //char temp[1] = char(state);  
      //strcat(radiopacket, temp);   
         
      if (USEACK)
      {
        if (radio.sendWithRetry(TONODEID, data, strlen(data)))
          Serial.println("ACK received!");
        else
          Serial.println("no ACK received");
      }else // don't use ACK 
      {
        radio.send(TONODEID, radiopacket, strlen(radiopacket));
      }
      
      delay(500);
      
  
}

void Blink(byte PIN, int DELAY_MS)
// Blink an LED for a given number of ms
{
  digitalWrite(PIN,HIGH);
  delay(DELAY_MS);
  digitalWrite(PIN,LOW);
}

PaulS:
Is the reed switch connected to the pirInputPin? Why the heck is it connected to a pin with such a misleading name?

It's just taken from an example use of RFM69 I'll need to clean up when I'm done. Blame tutorials on the internet for using such horrible variable names. :frowning:

Blame tutorials on the internet for using such horrible variable names.

If YOU changed the kind of sensor, YOU should change the variable names. It takes only a few seconds to use Ctrl-F and Replace All. Makes you look smarter.

PaulS:
If YOU changed the kind of sensor, YOU should change the variable names. It takes only a few seconds to use Ctrl-F and Replace All. Makes you look smarter.

Thanks just debugging at the moment, will do so before complete.

Hi Guys
i have one Moteino as receiver and one Arduino pro mini as sender. the sender is powered up with a battery on it and the receiver has connected to my laptop to power up
i want to bring the sender in sleep mode, when the receiver is not on
in fact i need , my sender listen for example every minute, when my receiver is not on
and when the receiver is on, the receiver send something to sender, so that , the sender understand the receiver is on and start to send the data
but i dont know how
the both of them are able to receive and send data
i am searching for a solution for my problem
i really thank you to some one, who help me
in following are my receiver and sender code:

receiver code:

// Sample RFM69 receiver/gateway sketch, with ACK and optional encryption, and Automatic Transmission Control
// Passes through any wireless received messages to the serial port & responds to ACKs
// It also looks for an onboard FLASH chip, if present
// **********************************************************************************
// Copyright Felix Rusu 2016, http://www.LowPowerLab.com/contact
// **********************************************************************************
// License
// **********************************************************************************
// This program is free software; you can redistribute it
// and/or modify it under the terms of the GNU General
// Public License as published by the Free Software
// Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will
// be useful, but WITHOUT ANY WARRANTY; without even the
// implied warranty of MERCHANTABILITY or FITNESS FOR A
// PARTICULAR PURPOSE. See the GNU General Public
// License for more details.
//
// Licence can be viewed at
// http://www.gnu.org/licenses/gpl-3.0.txt
//
// Please maintain this license information along with authorship
// and copyright notices in any redistribution of this code
// **********************************************************************************
#include <RFM69.h> //get it here: GitHub - LowPowerLab/RFM69: RFM69 library for RFM69W, RFM69HW, RFM69CW, RFM69HCW (semtech SX1231, SX1231H)
#include <RFM69_ATC.h> //get it here: GitHub - LowPowerLab/RFM69: RFM69 library for RFM69W, RFM69HW, RFM69CW, RFM69HCW (semtech SX1231, SX1231H)
#include <SPIFlash.h> //get it here: GitHub - LowPowerLab/SPIFlash: Arduino library for read/write access to SPI flash memory chips
#include <SPI.h> //included with Arduino IDE install (www.arduino.cc)

//*********************************************************************************************
//************ IMPORTANT SETTINGS - YOU MUST CHANGE/CONFIGURE TO FIT YOUR HARDWARE *************
//*********************************************************************************************
#define NODEID 1 //unique for each node on same network
#define NETWORKID 100 //the same on all nodes that talk to each other
//Match frequency to the hardware version of the radio on your Moteino (uncomment one):
//#define FREQUENCY RF69_433MHZ
#define FREQUENCY RF69_868MHZ
//#define FREQUENCY RF69_915MHZ
#define ENCRYPTKEY "sampleEncryptKey" //exactly the same 16 characters/bytes on all nodes!
//#define IS_RFM69HW_HCW //uncomment only for RFM69HW/HCW! Leave out if you have RFM69W/CW!
//*********************************************************************************************
//Auto Transmission Control - dials down transmit power to save battery
//Usually you do not need to always transmit at max output power
//By reducing TX power even a little you save a significant amount of battery power
//This setting enables this gateway to work with remote nodes that have ATC enabled to
//dial their power down to only the required level
//#define ENABLE_ATC //comment out this line to disable AUTO TRANSMISSION CONTROL
//*********************************************************************************************
#define SERIAL_BAUD 9600

#ifdef AVR_ATmega1284P
#define LED 15 // Moteino MEGAs have LEDs on D15
#define FLASH_SS 23 // and FLASH SS on D23
#else
#define LED 9 // Moteinos have LEDs on D9
#define FLASH_SS 8 // and FLASH SS on D8
#endif

#ifdef ENABLE_ATC
RFM69_ATC radio;
#else
RFM69 radio;
#endif

SPIFlash flash(FLASH_SS, 0xEF30); //EF30 for 4mbit Windbond chip (W25X40CL)
bool promiscuousMode = false; //set to 'true' to sniff all packets on the same network

void setup() {
Serial.begin(SERIAL_BAUD);
delay(10);
radio.initialize(FREQUENCY,NODEID,NETWORKID);
#ifdef IS_RFM69HW_HCW
radio.setHighPower(); //must include this only for RFM69HW/HCW!
#endif
radio.encrypt(ENCRYPTKEY);
radio.promiscuous(promiscuousMode);
//radio.setFrequency(919000000); //set frequency to some custom frequency
char buff[50];
sprintf(buff, "\nListening at %d Mhz...", FREQUENCY==RF69_433MHZ ? 433 : FREQUENCY==RF69_868MHZ ? 868 : 915);
//Serial.println(buff);
if (flash.initialize())
{
//Serial.print("SPI Flash Init OK. Unique MAC = [");
flash.readUniqueId();
for (byte i=0;i<8;i++)
{
// Serial.print(flash.UNIQUEID*, HEX);*

  • if (i!=8) ;//Serial.print(':');*

  • }*

  • // Serial.println(']');*

  • //alternative way to read it:*
    _ //byte* MAC = flash.readUniqueId();_

  • //for (byte i=0;i<8;i++)*

  • //{*
    _ // Serial.print(MAC*, HEX);_
    _
    // Serial.print(' ');_
    _
    //}_
    _
    }_
    _
    else*_
    * Serial.println("SPI Flash MEM not found (is chip soldered?)...");*

#ifdef ENABLE_ATC
* Serial.println("RFM69_ATC Enabled (Auto Transmission Control)");
_
#endif*_
}
byte ackCount=0;
uint32_t packetCount = 0;
void Blink(byte PIN, int DELAY_MS)
{
* pinMode(PIN, OUTPUT);*
* digitalWrite(PIN,HIGH);*
* delay(DELAY_MS);
_
digitalWrite(PIN,LOW);_
_
}_
void loop() {
_
//process any serial input*_
* if (Serial.available() > 0)*
* {*
* char input = Serial.read();*
* if (input == 'r') //d=dump all register values*
* radio.readAllRegs();*
* if (input == 'E') //E=enable encryption*
* radio.encrypt(ENCRYPTKEY);*
* if (input == 'e') //e=disable encryption*
* radio.encrypt(null);*
* if (input == 'p')*
* {*
* promiscuousMode = !promiscuousMode;*
* radio.promiscuous(promiscuousMode);*
* Serial.print("Promiscuous mode ");Serial.println(promiscuousMode ? "on" : "off");*
* }*

* if (input == 'd') //d=dump flash area*
* {*
* Serial.println("Flash content:");*
* int counter = 0;*
* while(counter<=256){*
* Serial.print(flash.readByte(counter++), HEX);*
* Serial.print('.');*
* }*
* while(flash.busy());*
* Serial.println();*
* }*
* if (input == 'D')*
* {*
* Serial.print("Deleting Flash chip ... ");*
* flash.chipErase();*
* while(flash.busy());*
* Serial.println("DONE");*
* }*
* if (input == 'i')*
* {*
* Serial.print("DeviceID: ");*
* word jedecid = flash.readDeviceId();*
* Serial.println(jedecid, HEX);*
* }*
* if (input == 't')*
* {*
* byte temperature = radio.readTemperature(-1); // -1 = user cal factor, adjust for correct ambient*
_ byte fTemp = 1.8 * temperature + 32; // 9/5=1.8_
* Serial.print( "Radio Temp is ");*
* Serial.print(temperature);*
* Serial.print("C, ");*
* Serial.print(fTemp); //converting to F loses some resolution, obvious when C is on edge between 2 values (ie 26C=78F, 27C=80F)*
* Serial.println('F');*
* }*
* }*
* if (radio.receiveDone())*
* {*
// Serial.print("#[");
// Serial.print(++packetCount);
// Serial.print(']');
// Serial.print('[');Serial.print(radio.SENDERID, DEC);Serial.print("] ");
* if (promiscuousMode)*
* {*
* Serial.print("to [");Serial.print(radio.TARGETID, DEC);Serial.print("] ");*
* }*
* for (byte i = 0; i < radio.DATALEN; i++)*
_ Serial.print((char)radio.DATA*); // ############# HIER WERDEN DIE DATEN GEPRINTET???!!!!#############
// Serial.println(" 500");_
// Serial.print(" [RX_RSSI:");Serial.print(radio.RSSI);Serial.print("]");*

* if (radio.ACKRequested())*
* {*
* byte theNodeID = radio.SENDERID;*
* radio.sendACK();*
* //Serial.print(" - ACK sent.");*
* // When a node requests an ACK, respond to the ACK*
* // and also send a packet requesting an ACK (every 3rd one only)*
* // This way both TX/RX NODE functions are tested on 1 end at the GATEWAY*
* if (ackCount++%3==0)*
* {*
* // Serial.print(" Pinging node ");*
* // Serial.print(theNodeID);*
* // Serial.print(" - ACK...");*
* delay(3); //need this when sending right after reception .. ?*
* if (radio.sendWithRetry(theNodeID, "ACK TEST", 8, 0)) // 0 = only 1 attempt, no retries*
* //Serial.print("ok!");*
* // else //Serial.print("nothing");*
* delay(0);}*
* }*

* Blink(LED,3);*
* }*
}

Following to last post
the sender code:

Sender :
#include <RFM69.h> //get it here: GitHub - LowPowerLab/RFM69: RFM69 library for RFM69W, RFM69HW, RFM69CW, RFM69HCW (semtech SX1231, SX1231H)
#include <RFM69_ATC.h> //get it here: GitHub - LowPowerLab/RFM69: RFM69 library for RFM69W, RFM69HW, RFM69CW, RFM69HCW (semtech SX1231, SX1231H)
#include <SPIFlash.h> //get it here: GitHub - LowPowerLab/SPIFlash: Arduino library for read/write access to SPI flash memory chips
#include <SPI.h> //included with Arduino IDE install (www.arduino.cc)
#include <string.h>
#include <TC_Mux.h>
#include <LowPower.h>

//*********************************************************************************************
//************ IMPORTANT SETTINGS - YOU MUST CHANGE/CONFIGURE TO FIT YOUR HARDWARE ************
//*********************************************************************************************
#define NODEID 2 //must be unique for each node on same network (range up to 254, 255 is used for broadcast)
#define NETWORKID 100 //the same on all nodes that talk to each other (range up to 255)
#define GATEWAYID 1
//Match frequency to the hardware version of the radio on your Moteino (uncomment one):
//#define FREQUENCY RF69_433MHZ
#define FREQUENCY RF69_868MHZ
//#define FREQUENCY RF69_915MHZ
#define ENCRYPTKEY "sampleEncryptKey" //exactly the same 16 characters/bytes on all nodes!
//#define IS_RFM69HW_HCW //uncomment only for RFM69HW/HCW! Leave out if you have RFM69W/CW!
//*********************************************************************************************
//Auto Transmission Control - dials down transmit power to save battery
//Usually you do not need to always transmit at max output power
//By reducing TX power even a little you save a significant amount of battery power
//This setting enables this gateway to work with remote nodes that have ATC enabled to
//dial their power down to only the required level (ATC_RSSI)
#define ENABLE_ATC //comment out this line to disable AUTO TRANSMISSION CONTROL
#define ATC_RSSI -80
//*********************************************************************************************

#ifdef AVR_ATmega1284P
#define LED 15 // Moteino MEGAs have LEDs on D15
#define FLASH_SS 23 // and FLASH SS on D23
#else
#define LED 9 // Moteinos have LEDs on D9
#define FLASH_SS 8 // and FLASH SS on D8
#endif

#define SERIAL_BAUD 9600

int TRANSMITPERIOD = 200; //transmit a packet to gateway so often (in ms)
char payload[] = "123 ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char buff[20];
byte sendSize=0;
boolean requestACK = false;
SPIFlash flash(FLASH_SS, 0xEF30); //EF30 for 4mbit Windbond chip (W25X40CL)

#ifdef ENABLE_ATC
RFM69_ATC radio;
#else
RFM69 radio;
#endif

TC_Mux Muxer;

void setup() {

Serial.begin(SERIAL_BAUD);
radio.initialize(FREQUENCY,NODEID,NETWORKID);
#ifdef IS_RFM69HW_HCW
radio.setHighPower(); //must include this only for RFM69HW/HCW!
#endif
radio.encrypt(ENCRYPTKEY);
//radio.setFrequency(919000000); //set frequency to some custom frequency

//Auto Transmission Control - dials down transmit power to save battery (-100 is the noise floor, -90 is still pretty good)
//For indoor nodes that are pretty static and at pretty stable temperatures (like a MotionMote) -90dBm is quite safe
//For more variable nodes that can expect to move or experience larger temp drifts a lower margin like -70 to -80 would probably be better
//Always test your ATC mote in the edge cases in your own environment to ensure ATC will perform as you expect
#ifdef ENABLE_ATC
radio.enableAutoPower(ATC_RSSI);
#endif

char buff[50];
sprintf(buff, "\nTransmitting at %d Mhz...", FREQUENCY==RF69_433MHZ ? 433 : FREQUENCY==RF69_868MHZ ? 868 : 915);
Serial.println(buff);

if (flash.initialize())
{
Serial.print("SPI Flash Init OK ... UniqueID (MAC): ");
flash.readUniqueId();
for (byte i=0;i<8;i++)
{
Serial.print(flash.UNIQUEID*, HEX);*
Serial.print(' ');
}
Serial.println();
}
else
Serial.println("SPI Flash MEM not found (is chip soldered?)...");
#ifdef ENABLE_ATC
Serial.println("RFM69_ATC Enabled (Auto Transmission Control)\n");
#endif
}
void Blink(byte PIN, int DELAY_MS)
{
pinMode(PIN, OUTPUT);
digitalWrite(PIN,HIGH);
delay(DELAY_MS);
digitalWrite(PIN,LOW);
}
long lastPeriod = 0;
void loop() {
//process any serial input
// if (Serial.available() > 0)
// {
// char input = Serial.read();
// if (input >= 48 && input <= 57) //[0,9]
// {
// TRANSMITPERIOD = 100 * (input-48);
// if (TRANSMITPERIOD == 0) TRANSMITPERIOD = 1000;
// Serial.print("\nChanging delay to ");
// Serial.print(TRANSMITPERIOD);
// Serial.println("ms\n");
// }
//
// if (input == 'r') //d=dump register values
// radio.readAllRegs();
// //if (input == 'E') //E=enable encryption
// // radio.encrypt(KEY);
// //if (input == 'e') //e=disable encryption
// // radio.encrypt(null);
//
// if (input == 'd') //d=dump flash area
// {
// Serial.println("Flash content:");
// uint16_t counter = 0;
//
// Serial.print("0-256: ");
// while(counter<=256){
// Serial.print(flash.readByte(counter++), HEX);
// Serial.print('.');
// }
// while(flash.busy());
// Serial.println();
// }
// if (input == 'e')
// {
// Serial.print("Erasing Flash chip ... ");
// flash.chipErase();
// while(flash.busy());
// Serial.println("DONE");
// }
// if (input == 'i')
// {
// Serial.print("DeviceID: ");
// word jedecid = flash.readDeviceId();
// Serial.println(jedecid, HEX);
// }
// }
//check for any received packets
if (radio.receiveDone())
{
Serial.print('[');Serial.print(radio.SENDERID, DEC);Serial.print("] ");
for (byte i = 0; i < radio.DATALEN; i++)
Serial.print((char)radio.DATA*);*
Serial.print(" [RX_RSSI:");Serial.print(radio.RSSI);Serial.print("]");
if (radio.ACKRequested())
{
radio.sendACK();
Serial.print(" - ACK sent");
}
Blink(LED,3);
Serial.println();
}
int currPeriod = millis()/TRANSMITPERIOD;
if (currPeriod != lastPeriod)
{
lastPeriod=currPeriod;
//send FLASH id
// ######## er sendet als erstes die ID des Flash Speichers an das Gateway
// if(sendSize==0)
// {
// sprintf(buff, "FLASH_MEM_ID:0x%X", flash.readDeviceId());
// byte buffLen=strlen(buff);
// if (radio.sendWithRetry(GATEWAYID, buff, buffLen))
// Serial.print(" ok!");
// else Serial.print(" nothing...");
// //sendSize = (sendSize + 1) % 31;
// }
//######## danach sendet er die payload[]. sendsize ist hier der Counter pro void loop() Runde
// else
{
// Serial.print("Sending[");
* // Serial.print(sendSize);*
* // Serial.print("]: ");*
// for(byte i = 0; i < sendSize; i++)
_ // Serial.print((char)payload*);
// if (radio.sendWithRetry(GATEWAYID, payload, sendSize))
// Serial.print(" ok!");
// else Serial.print(" nothing...");
}
sendSize = (sendSize + 1) % 31; // % 31 bedeutet dass sendsize = Rest der Division von sendsize+1/31 ist. Also 1,2,3,..bis 30 und bei 31 ist 31/31=1 und der Rest=0 somit beginnt sendsize wieder bei 0
char messwerte[200] = {0};
Muxer.mux(messwerte,200);
Serial.print(messwerte);_

// sprintf(pot_char,"%d",potwert);
// int laenge = strlen (pot_char);
_// Serial.println(laenge);
// Serial.println("#######################");
radio.sendWithRetry(GATEWAYID,messwerte,200);//Hier werden die Daten über die serielle Schnittstelle gesendet
Blink(LED,3);
}
}*_