Hi,
I am successfully collecting data from an emonTX V3 but want to add several emonTH to record temperature and humidity in different rooms. This will finally link to some RF TRV for heating.
The question I have is how to I received data from several emonTH and emonTX at the same time. I am using a JeeLink to received data with the following sketch:
//Simple RFM12B wireless demo - Receiver - no ack //Glyn Hudson openenergymonitor.org GNU GPL V3 12/4/12 //Credit to JCW from Jeelabs.org for RFM12 #include <JeeLib.h> #define myNodeID 30 //node ID of Rx (range 0-30) #define network 210 //network group (can be in the range 1-250). #define RF_freq RF12_433MHZ //Freq of RF12B can be RF12_433MHZ, RF12_868MHZ or RF12_915MHZ. Match freq to module typedef struct { int power1, power2, power3, power4, Vrms, temp; } PayloadTX; // create structure - a neat way of packaging data for RF comms PayloadTX emontx; const int emonTx_NodeID=10; //emonTx node ID void setup() { rf12_initialize(myNodeID,RF_freq,network); //Initialize RFM12 with settings defined above Serial.begin(9600); #ifdef DEBUG Serial.println("RF12B demo Receiver - Simple demo"); Serial.print("Node: "); Serial.print(myNodeID); Serial.print(" Freq: "); if (RF_freq == RF12_433MHZ) Serial.print("433Mhz"); if (RF_freq == RF12_868MHZ) Serial.print("868Mhz"); if (RF_freq == RF12_915MHZ) Serial.print("915Mhz"); Serial.print(" Network: "); Serial.println(network); #endif // DEBUG } void loop() { if (rf12_recvDone()){ if (rf12_crc == 0 && (rf12_hdr & RF12_HDR_CTL) == 0) { int node_id = (rf12_hdr & 0x1F); //extract nodeID from payload if (node_id == emonTx_NodeID) { //check data is coming from node with the corrct ID emontx=*(PayloadTX*) rf12_data; // Extract the data from the payload Serial.print(emontx.power1); // Solar power produced Serial.print(","); Serial.print(emontx.power2); // Power consumed Serial.print(","); Serial.println(emontx.temp); // Temperature } } } }
How would I extend this to read from multiple emonTH?
Thanks in advance,
Geoff
Re: emonTH and emonTX V3
Updated formatting
Re: emonTH and emonTX V3
The bit you are interested in is:
if (node_id == emonTx_NodeID) { //check data is coming from node with the corrct ID
emontx=*(PayloadTX*) rf12_data; // Extract the data from the payload
Serial.print(emontx.power1); // Solar power produced
Serial.print(",");
Serial.print(emontx.power2); // Power consumed
Serial.print(",");
Serial.println(emontx.temp); // Temperature
}
That decodes information received from node "emonTx_NodeID". You need similar code for each node you wish to receive from. You'll need to add the appropriate data structure to decode the data, of course, and you must give each node within radio range its own, unique, node ID.
For the emonTHs, you'll need something like this:
typedef struct { // RFM12B RF payload datastructure
int temp;
int temp_external;
int humidity;
int battery;
} PayloadTH;
PayloadTH emonth1, emonth2, emonth3;
and then
if (node_id == emonTH1_NodeID) { //check data is coming from node with the correct ID
emontx=*(PayloadTH*) rf12_data; // Extract the data from the payload
Serial.println(emonth1.temp_external);
// [etc]
}
for each emonTH.
Re: emonTH and emonTX V3
Thanks Robert. I'll let you know how I get on.
Re: emonTH and emonTX V3
Richard - all up and running. I needed to upload the sketch to the emonTH - I had expected this to come preloaded with software as per the emonTX V3.