emonTH - Transmitting two different sets of data - Is it possible?

I am attempting to complete a sketch that transmits my water usage based on an interrupt routine (ie - it will only transmit when water is flowing) but also to transmit temperature and pressure data every one minute regardless.

So I started with two different payloads like this:

// What information are we going to be transmitting back to our gateway?

typedef struct {                             // RF payload datastructure
  float GAL;
  float GPM;
  float GLM;                                       
} Payload;
Payload pool_water;

// What information are we going to be transmitting back to our gateway?

typedef struct {                             // RF payload datastructure
  int box_temp;
  int filter_psi;                                             
} SensorPayload;
SensorPayload pool_sensors;

Then I have a routine set up to transmit water usage but only if there are changes:

// We only transmit if there are changes to send....


  if (pool_water.GPM!=GPMlast || pool_water.GAL!=GALlast || pool_water.GLM!=GLMlast)  //Check and see if we used any pool_water.....
  {
    power_spi_enable();

    if (debug)
       {
       Serial.println("We are going to transmit now.......");
       }

    rf12_sleep(RF12_WAKEUP);
    delay(100);
    rf12_sendNow(0, &pool_water, sizeof pool_water);
    rf12_sendWait(2);

    // Make last reading match curent reading until they change
    GALlast = pool_water.GAL;
    GPMlast = pool_water.GPM;
    GLMlast = pool_water.GLM;

    power_spi_disable();
   }

And then I have a routine setup that transmits every 60 seconds:

void take_sensor_readings()
{
  Serial.println("Getting Sensor Readings...");
  take_ds18b20_reading();
  delay(500);
  get_filter_pressure();
  delay(500);
  power_spi_enable();
  rf12_sleep(RF12_WAKEUP);
  rf12_sendNow(0, &pool_sensors, sizeof pool_sensors);
  rf12_sendWait(2);
  rf12_sleep(RF12_SLEEP);
  power_spi_disable();
  if (debug){
    Serial.print("TEMP: "); Serial.print(pool_sensors.box_temp);
    Serial.print(", Filter PSI: "); Serial.print(pool_sensors.filter_psi); 
    Serial.print(", Sensor Voltage: "); Serial.println(sensorVoltage);
  }
}

Both of those work great, the only problem is that they are over writing each other when the data is transmitted. As long as I have no water flowing, I get my temp and pressure readings without a problem. As soon as water starts flowing, then those readings are getting overwritten with my meter readings, gallons-per-minute, etc.

I was wondering if there is anyway at all to vary the time data is transmitted as well as what data is transmitted.

Thanks

What you are effectively trying to do here is use the emonTH as 2 separate nodes which should be possible if you identify them individually.
You will need to change node id prior to sending the respective payload, then you can have 2 individually defined nodes in emonhub.conf and they will not over write each other at emoncms, for all intents and purposes they will be as if they came from 2 different emonTH’s once the payloads are airbourne, not even the receiver will know there is only one device.

How often does the sketch check if water has been used?

If the frequency of the checks is never faster than the temp and pressure transmissions you could consider using a single node id with a variable size payload if you want to keep the payload/transmission time as short as possible.

By changing your temp and pressure to floats or your gallons to ints so that you are using all the same datatypes you can use “datatype=” h or f depending on your choice above and then use an “if changed statement” to select and send either a short 2 value payload or a long 5 value payload, using the “datacode=” with a single data type allows you to vary the packet length at will.

You can escape the need to use floats in many instances by scaling, eg the OEM way to send temp in deg’s C as a 2b int rather than a 4b float is to scale by 100, giving a range of -326.77C to 326.78 which far exceeds the scope of the sensors.

The " 2 nodes" option may not be the most efficient use of battery life as what you save by not sending repeat(unchanged) values, may be lost to the second packets pre-amble, config bytes, crc and the additional power up time for changing the config and payload. From your original payload (float temp and int pressure) a 2 byte increased size to 2 floats would allow you to just append the water use if changed so the packet overhead is shared not duplicated.

Hi Paul -

Thank you for this info, it gives me a direction in which to go.

The water is done on an interrupt so as soon as water starts flowing the node sees this and transmits until the water stops flowing. Since it is on an interrupt, it happens immediately. The temp and pressure I only need to see once a minute. I am powering this via a wall wart so I do not need or care about any type of power savings. In the end, I could use two different physical nodes to do this job but would really like to figure out if I could do it with one instead.

It sounds like the “if changed” statement was the way to go and I tried that (and do that with the water), but unless I transmitted all of the fields at once, how do I keep the data in the correct fields? I assume this has something to do with a variable size payload. How does the emonpi know that the data I am sending in the short payload if for temp and pressure (for example) and not GPM or GLM?

Thanks for the help!!

// We only transmit if there are changes to send....


  if (pool_water.GPM!=GPMlast || pool_water.GAL!=GALlast || pool_water.GLM!=GLMlast)

The “shared” or “variable size” payload will only work if one or other part is always present. for example if your code was sending temp & pressure every 60s and you just wanted to add the water data if it had changed. This would be done by having one fullsize payload with temp and pressure as the first and second values and if no change was detected in the water usage then the “sizeof payload” value in the send code would be reduced to exclude the water values.

But since this isn’t about saving battery then I see how you may wish to send the water usage more frequently than the temp & pressure so perhaps you should use the virtual 2 node approach or just send one payload more frequently for simplicity.

But be wary of giving the interrupt full rein of the send interval as during times of heavy use it will be very busy sending on every change/pulse. it is normal to count the interrupts and send as a count in controlled manner.

I have some interrupt based sketches that will on each interrupt increment a running total and if 5s has passed since the last send then send the running total, there is also a loop that checks for change in the total after 5s since last send.
This way the sketch only sends a count if there has been change in the last 5 secs and the maximum time before a pulse is reported is also 5s.

Thanks Paul -

I do limit how often it transmits, but its pretty quick.

I’ll continue to play around with it since I don’t have my external enclosure yet, but in the end maybe the easiest way will be to grab another emonth!