I have a problem with Arduino Nano AT328 with RFM69 and DHT22 AM2302 sensor.
Using following sketch
#include <RFM69.h>
#include <SPI.h>
#define NODEID 22 //unique for each node on same network
#define NETWORKID 100 //the same on all nodes that talk to each other
#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 //uncomment only for RFM69HW! Leave out if you have RFM69W!
#define ACK_TIME 30 // max # of ms to wait for an ack
#define LED 6 // On which PIN the LED isconnected
#define SERIAL_BAUD 115200 //must be 9600 for GPS, use whatever if no GPS
//deviceID's
// 2 = Temperature/Humidity
typedef struct {
int nodeID; //node ID (1xx, 2xx, 3xx); 1xx = BEDRoom, 2xx = LivingRoom, 3xx = Kitchen ...
int deviceID; //sensor ID (2, 3, 4, 5)
float var1_usl; //uptime in ms - not in all cases
float var2_float; //sensor data?
float var3_float; //battery condition?
} Payload;
Payload theData;
bool promiscuousMode = false;
typedef struct {
int nodeID;
int command;
//unsigned long var1_usl;
//float var2_float;
//float var3_float;
//int var4_int;
} klima_Send;
klima_Send theDataIR;
char buff[20];
byte sendSize=0;
//boolean requestACK = false;
RFM69 radio;
//end RFM69 ------------------------------------------
//device DHT22 Temperature/Humidity
#include <DHT.h>
#define DHTPIN 3 // what pin we're connected to
#define DHTTYPE DHT22 // DHT 22
DHT dht(DHTPIN, DHTTYPE);
//time:
const unsigned long dev2_period = 30000; //send data every X seconds
unsigned long dev2_period_time; //seconds since last period
void setup()
{
Serial.begin(SERIAL_BAUD); //Begin serial communcation
//RFM69-------------------------------------------
radio.initialize(FREQUENCY,NODEID,NETWORKID);
#ifdef IS_RFM69HW
radio.setHighPower(); //uncomment only for RFM69HW!
#endif
radio.encrypt(ENCRYPTKEY);
radio.promiscuous(promiscuousMode);
char buff[50];
sprintf(buff, "\nTransmitting at %d Mhz...", FREQUENCY==RF69_433MHZ ? 433 : FREQUENCY==RF69_868MHZ ? 868 : 915);
Serial.println(buff);
theData.nodeID = 22; //this node id should be the same for all devices in this node
pinMode(LED, OUTPUT);
//device DHT
dht.begin();
//time:
// dev2 is temperature_F/humidity
dev2_period_time = millis(); //seconds since last period
}
void loop()
{
if (radio.receiveDone())
{
theDataIR = *(klima_Send*)radio.DATA; //assume radio.DATA actually contains our struct and not something else
Serial.print(theDataIR.nodeID);
Serial.print(":");
Serial.print(theDataIR.command);
Serial.print(":");
Serial.println(radio.RSSI);
int state;
if(theDataIR.command == 1)
state = HIGH;
else if(theDataIR.command == 0)
state = LOW;
digitalWrite(LED, state);
//}
if (radio.ACKRequested())
{
radio.sendACK();
Serial.print(" - ACK sent");
Serial.println();
}
} //end if radio.receive
radio.receiveDone();
delay(2000);
//DHT22 --------------------------------
// DEVICE # TEMP/HUMIDITY // SENSOR #1
// Wait a few seconds between measurements.
//delay(2000);
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// Compute heat index in Fahrenheit (the default)
float hif = dht.computeHeatIndex(f, h);
// Compute heat index in Celsius (isFahreheit = false)
float hic = dht.computeHeatIndex(t, h, false);
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" *C ");
Serial.print(f);
Serial.print(" *F\t");
Serial.print("Heat index: ");
Serial.print(hic);
Serial.print(" *C ");
Serial.print(hif);
Serial.println(" *F");
delay(1000);
// NOW SEND THE DAM TEMP/HUMIDTY DATA!!!!!!!
theData.nodeID = 1;
theData.var2_float = f;// changed from .var2_float if .var3 if sending to photon.
theData.var3_float = h;// changed from .var3_float if .var3 if sending to photon.
radio.sendWithRetry(GATEWAYID,(const void*)(&theData), sizeof(theData));
digitalWrite(13,HIGH);
delay(300);
digitalWrite(13,LOW);
}
- On Serial I do have correct Readings
However when send via RFM69 to gateway I am getting following
[22] �p�B�? [RSSI:-71][ACK-sent]
The problem is that. I do get correct readings on serial but when sent out to Gateway getting wierd characters above.