Arduino Nano AT328 RFM69 + DHT22 AM2302

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.

You send the data in binary format so why do you expect to see it in ASCII on the other side?

Eh, only if I knew what is the problem. Is there any way of converting it before sending?

java.io.IOException: The system cannot find the file specified
at java.io.WinNTFileSystem.createFileExclusively(Native Method)
at java.io.File.createTempFile(File.java:2024)
at processing.app.BaseNoGui.saveFile(BaseNoGui.java:908)
at processing.app.SketchFile.save(SketchFile.java:287)
at processing.app.Sketch.save(Sketch.java:138)
at processing.app.SketchController.save(SketchController.java:344)
at processing.app.Editor.handleSave2(Editor.java:2020)
at processing.app.Editor.handleSave(Editor.java:2000)
at processing.app.Editor.handleExport(Editor.java:2140)
at processing.app.EditorToolbar.mousePressed(EditorToolbar.java:378)
at java.awt.Component.processMouseEvent(Component.java:6530)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
at java.awt.Component.processEvent(Component.java:6298)
at java.awt.Container.processEvent(Container.java:2236)
at java.awt.Component.dispatchEventImpl(Component.java:4889)
at java.awt.Container.dispatchEventImpl(Container.java:2294)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4522)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)
at java.awt.Container.dispatchEventImpl(Container.java:2280)
at java.awt.Window.dispatchEventImpl(Window.java:2746)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.awt.EventQueue$4.run(EventQueue.java:729)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
The system cannot find the file specified

Eh, only if I knew what is the problem. Is there any way of converting it before sending?

You could try the dtostrf function.