emonTX Firmware Help

Hi,

Just need some help with some creating some firmware I'm new to this whole editing firmware so just looking for some guidance and suggestions for my firmware.

What I'm looking to do is get the current only (no power calculations just output in amps), temperature and send via wireless RF. The CT clamps will connected to the mains.

Below is what I have tried to put together will this work for what I want? 

Any help or suggestions to get this working or make it better will be much appreciated.

Thanks

#define emonTxV3

#include <RFu_JeeLib.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include "EmonLib.h"                      // Include Emon Library
EnergyMonitor ct1, ct2, ct3;             // Create three instances

OneWire oneWire(4);                                      // Setup one-wire on digital input pin 4
DallasTemperature sensors(&oneWire);          // Pass the oneWire reference to Dallas Temperature.

DeviceAddress address_T1 = { 0x28, 0x22, 0x70, 0xEE, 0x02, 0x00, 0x00, 0xB8 };

#define freq RF12_433MHZ                                       
const int nodeID = 10;                                                // emonTx RFM12B node ID
const int networkGroup = 210;
typedef struct { int Irms1, Irms2 ,Irm3 ,Temperature;  } PayloadTX;     // create structure - a neat way of packaging data for RF comms
  PayloadTX emontx;

void setup()
{  
  Serial.begin(9600);
  sensors.begin();

  ct1.currentTX(1, 115.6);             // CT channel 1, calibration.
  ct2.currentTX(2, 115.6);             // CT channel 2, calibration.
  ct2.currentTX(3, 115.6);             // CT channel 3, calibration.
}

void loop()

{
  double Irms1 = ct1.calcIrms(1480);   // Calculate RMS current 1
  double Irms2 = ct2.calcIrms(1480);   // Calculate RMS current 2
  double Irms3 = ct3.calcIrms(1480);   // Calculate RMS current 3 

  Serial.println(Irms1);        // Print to serial Irms
  Serial.println(Irms2);        // Print to serial Irms
  Serial.println(Irms3);        // Print to serial Irms

sensors.requestTemperatures();

  double temperature = sensors.getTempC(address_T1);  // Get the temperature of the sensor
  Serial.println(temperature);                        // Print temperature
}

void send_rf_data()
{
  rf12_sleep(RF12_WAKEUP);                                 
  rf12_sendNow(0, &emontx, sizeof emontx);                           //send temperature data via RFM12B using new rf12_sendNow wrapper
  rf12_sendWait(2);
  rf12_sleep(RF12_SLEEP);
}

 

Robert Wall's picture

Re: emonTX Firmware Help

That won't work. More precisely, although you are getting and calculating all the values (which at a first glance appears to be OK), you aren't copying the values into the payload struct (emontx). So you're probably getting all zeros at the other end of the radio link.

The next 'gotcha' is the payload is all integers, for power in watts that's fine but for currents, it gives you steps of 240 W in terms of power. As your maximum is 100 A, and a signed integer is -32768 - +32767, you can afford to multiply by 100 before you assign it to the integer, and divide by 100 at the other end. The same argument goes for your temperature.

Paul Reed's picture

Re: emonTX Firmware Help

Why not use the standard OEM emonTX sketch and do the calculations in emoncms??

If you know the voltage and the power, you can easily ascertain the Current.

 

Paul

Anthony_S's picture

Re: emonTX Firmware Help

I haven't really looked at emoncms Paul mainly just the emontx I wasn't aware of what you can do with it but thanks for letting me know that you can do it.

Anthony_S's picture

Re: emonTX Firmware Help

Thanks for replying Robert.  

Is it possible to do what I'm trying to do overall? sorry I'm kind of understanding what you mean.

 

 

 

Robert Wall's picture

Re: emonTX Firmware Help

You're very nearly there! I think. My problem is that once you've launched the data into the aether, I don't know what you want to do with it next. You need to come clean and fully explain what you're trying to achieve as the ultimate goal.

I'm assuming you want to stay fairly closely with OEM conventions, but you don't have to. The 'Payload' is only integers because of emonCMS. If you want to use an emonGLCD or something else, the payload format can be whatever you like - but it'll be your job to sort the data out at the other end. (See part 2 of the RFM12 article in Building Blocks if you want the low-down on this.)

Anthony_S's picture

Re: emonTX Firmware Help

Again thanks for the information I'm understanding more now.

I'm looking to get the current and temperature from the emonTX through the CT clamps and temp sensor then send the data to emonCMS. A bit like what the default V3 firmware does except have the current displayed instead of power. 

I have yet to check the output of my attempt at a working firmware through the arduino serial monitor before I pass it through the wirless to emonCMS that may be something to do first as well.

Of course if this all can be done with the default firmware like what Paul said and just do the calculations on the front end then that might be easier for someone who is new to the process i'm not sure as I haven't messed around with the emoCMS yet.

Robert Wall's picture

Re: emonTX Firmware Help

The input type to emonCMS must be a signed integer. After that, it makes no real difference to emonCMS what the numbers you send it relate to in physical units. All it knows is it gets a series of integer values that have been forwarded by your Base. It's in the processing that you allocate meanings to the numbers, but you must bear in mind that the processing available to you is oriented towards energy rather than current, simply because that is most meaningful to most people as it's what they pay for. I think it would pay you to look at what processing is available inside emonCMS before you commit to anything. Look at emonCMS Docs and input processing, dashboards and visualisations; that should give you some idea of what's available.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.