Kann man nicht ausschließen, aber wie kann ein aktiver Serial Monitor dazu führen, dass es keinen Absturz gibt?
Hier ist der Sketch:
#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>
#include <dht.h>
#include "MyTypes.h"
#include <Narcoleptic.h>
#define DHTPIN 3 // what pin we're connected to
#define DHTTYPE DHT22 // DHT 22 (AM2302)
DHT dht(DHTPIN, DHTTYPE);
// nRF24L01(+) radio attached
RF24 radio(9,10);
// Network uses that radio
RF24Network network(radio);
// Address of our node
const uint16_t this_node = 1;
// Address of the other node (by default send it to the base)
const uint16_t other_node = 0;
// How often to send 'hello world to the other unit
unsigned long interval = 5000; //ms
// When did we last send?
unsigned long last_sent;
// How many have we sent already
unsigned long packets_sent;
payload_t myData;
// Number of packets we've failed to send since we last sent one
// successfully
uint16_t lost_packets = 0;
void setup(void)
{
Serial.begin(57600);
Serial.println("RF24Network/examples/helloworld_tx/");
SPI.begin();
radio.begin();
network.begin(/*channel*/ 90, /*node address*/ this_node);
dht.begin();
RF24NetworkHeader header(network.parent(), 'k');
Serial.print("APP Sending type: k to node:");
Serial.println(header.to_node);
if ( ! network.write(header, NULL, 0) )
Serial.println("failed.");
}
void loop(void)
{
delay(100);
// Pump the network regularly
network.update();
// If so, grab it and print it out
RF24NetworkHeader header;
network.peek(header);
if ( this_node > 0 )
{
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT");
}
else{
myData.value = h;
myData.unity[0] = '%';
myData.lost_packets = lost_packets;
sendData(&myData);
delay(200);
myData.value = t;
myData.unity[0] = 'C';
myData.lost_packets = lost_packets;
sendData(&myData);
}
//radio.powerDown();
//radio.powerDown();
}
}
boolean sendData(payload_t* data) {
unsigned long now = millis();
if ( now - last_sent >= interval )
{
Serial.println("Sending...");
last_sent = now;
boolean ok = false;
RF24NetworkHeader header(other_node, 'S');
ok = network.write(header, &myData, sizeof(myData));
if (!ok) {
++lost_packets;
Serial.println("failed.");
}
return ok;
}
}