Hi there,
Finally getting somewhere with this project after resolving some hardware issues. I can actually monitor temperature. Result.
Now getting to the communications bit. My emonTx (v2.2) has a sketch copied from some example code. The relevant bit is
void send_rf_data()
{
rf12_sleep(RF12_WAKEUP);
// if ready to send + exit loop if it gets stuck as it seems too
int i = 0; while (!rf12_canSend() && i<10) {rf12_recvDone(); i++;}
rf12_sendStart(0, &emontx, sizeof emontx);
// set the sync mode to 2 if the fuses are still the Arduino default
// mode 3 (full powerdown) can only be used with 258 CK startup fuses
rf12_sendWait(2);
rf12_sleep(RF12_SLEEP);
}
the temperature is read correctly from 1 sensor. emontx.T1 is therefor the only value that means anything currently. should be no problem for the purposes of testing.
if i run rf12demo on my nanodeRF everything works fine
Current configuration:
A i1 g210 @ 433 MHz q1
OK 10 0 0 0 0 252 8 100 206 100 206 100 206
OK 10 0 0 0 0 252 8 100 206 100 206 100 206
OK 10 0 0 0 0 252 8 100 206 100 206 100 206
OK 10 0 0 0 0 71 10 100 206 100 206 100 206
OK 10 0 0 0 0 27 11 100 206 100 206 100 206
OK 10 0 0 0 0 127 11 100 206 100 206 100 206
OK 10 0 0 0 0 71 11 100 206 100 206 100 206
OK 10 0 0 0 0 2 11 100 206 100 206 100 206
OK 10 0 0 0 0 202 10 100 206 100 206 100 206
the 6th and 7th byte seem to represent the temperature on T1. as i hold the sensor it rises and then slowly falls when i let it go. excellent.
now i am trying to make my own nanodeRF sketch, this is where things fall apart.
#define RF_freq RF12_433MHZ // Frequency of RF12B module can be RF12_433MHZ, RF12_868MHZ or RF12_915MHZ. You should use the one matching the module you have.
const int nodeID = 1; // emonTx RFM12B node ID
const int networkGroup = 210; // emonTx RFM12B wireless network group - needs to be same as emonBase and emonGLCD
const int UNO = 1; // Set to 0 if your not using the UNO bootloader (i.e using Duemilanove) - All Atmega's shipped from OpenEnergyMonitor come with Arduino Uno bootloader
#include <avr/wdt.h>
#include <JeeLib.h> // make sure V12 (latest) is used if using RFM69CW
ISR(WDT_vect) { Sleepy::watchdogEvent(); } // Attached JeeLib sleep function to Atmega328 watchdog -enables MCU to be put into sleep mode inbetween readings to reduce power consumption
typedef struct {
int realPower; // RealPower
int apparentPower; // ApparentPower
int T1; // temperature sensor 1
int T2; // temperature sensor 2
int T3; // temperature sensor 3
int T4; // temperature sensor 4
} Payload;
Payload emontx;
const int LEDpin = 9;
void emontx_sleep(int seconds) {
for (int i=0; i<seconds; i++) {
delay(1000);
if (UNO) wdt_reset();
}
}
void setup() {
Serial.begin(9600);
Serial.println("test");
rf12_initialize(nodeID, RF_freq, networkGroup); // initialize RF
rf12_sleep(RF12_SLEEP);
pinMode(LEDpin, OUTPUT);
digitalWrite(LEDpin, HIGH);
if (UNO) wdt_enable(WDTO_8S);
}
void loop()
{
Serial.print(".");
if (rf12_recvDone())
{
if (rf12_crc != 0)
{
Serial.print("crc oops");
}
else if ((rf12_hdr & RF12_HDR_CTL) != 0)
{
Serial.print("rf12_hdr?");
}
else
{
Serial.println();
Serial.print(rf12_data[0]);
Serial.print(rf12_data[1]);
Serial.print(rf12_data[2]);
Serial.print(rf12_data[3]);
Serial.print(rf12_data[4]);
Serial.print(rf12_data[5]);
Serial.print(rf12_data[6]);
Serial.println();
//Serial.println();
//emontx = *(Payload*) rf12_data;
//Serial.print(emontx.T1);
}
}
emontx_sleep(10); // sleep or delay in seconds - see emontx_lib
digitalWrite(LEDpin, HIGH); delay(2); digitalWrite(LEDpin, LOW); // flash LED
}
so… the output of this is sometimes like this:
test
..
0000399100
..crc oops..crc oops..crc oops..crc oops..crc oops..crc oops...crc oops..crc oops..crc oops..crc oops.
however sometimes it doesn’t even get the first one. The super weird thing is it keeps spitting out the crc oops message even when my emonTx is unpowered.
as far as i can tell i have initialised it with the same settings that were used in rf12demo eg. nodeID 1, netGroup 210, frequency 433mhz
hmmm i must be doing something quite wrong here…?