### Temperature power sketch issues

Hi again,

I've uploaded the temperature_power sketch onto my EmonTX but I'm having issues.

I have one temp sensor hooked up, for which I have the address. I have a CT clamp on my incoming supply.

First issue- I'm getting nothing for power. This was all working fine with the CT123 sketch.

My understanding is that the temperature_power sketch requires a CT measurement, and then uses an assume voltage and phase shift to work out the real power. I tried putting the CT clamp on both CT1 and CT2 on the TX, to no avail. Any ideas? I don't really understand a lot of the code in the sketch which makes it hard to diagnose the issue.

Second issue- temperature is 100 times too large (or so I assume, as it is reading 2190 ish, and I think it should be about 21.9 degC!). The notes do say that this will happen, but I'm confused because in the sketch the temps are multiplied by 100- why? Is this to get it into integer form? To get these into sensible numbers do I have to do some processing on emoncms?

I suspect a lot of my issues would be solved if I was able to understand the libraries being used. I've not been able to find details of how these work- can someone point me in the right direction?

Many thanks,

Chris

I'm getting zero for the real power, and a very large number for the temperature (

### Re: Temperature power sketch issues

You were using the CT123 sketch. That assumes a voltage (240 V) and calculates the apparent power from that.

emontx_temperature_power.ino  requires a voltage input from an AC-AC adapter to measure the real power.

If you haven't got that voltage input, real power will be zero (or very small, as it may read a tiny voltage from stray pick-up).  If you don't want to add the voltage measurement, you could replace "ct1.calcVI(20,2000);" etc with the corresponding lines from your original sketch.

Take a look at Building Blocks to see how AC power is measured. Basically, you were measuring current and calculating the average (rms) value with calcIrms; then calculating apparent power by multiplying by an assumed voltage. With the new sketch, you are multiplying instantaneous readings of current and voltage and then averaging to give real power directly. Hopefully, that will be enough to start you along the path to understanding the libraries, but ask again if the fog doesn't clear.

The temperature issue is purely one of scaling. Emoncms only accepts integer values, so to get a reading more precise than one degree, it is multiplied up before transmission, then inside emoncms you need to divide by the same number to restore the value. 100 is convenient and sensible, it doesn't have to be that.

### Re: Temperature power sketch issues

Robert,

Thanks again for your help and patience the new guy.

In the end I decided to edit the CT123 sketch to include temperature, pending the arrival of the AC-AC adapter plug.

I've sorted the temp issue now I've understood how the inputs/feeds work, and scaled to get a sensible result.

However, the electrical power readings are doing something odd. This morning around 4am (as I can see on the emoncms graphs), the power shot up from about 100W to 3000W, where it has remained ever since. When I used the microwave this morning the power responded going to around 4.6kW (microwave is 1.6kW).

I have a digital power monitor (provided by electricity company) which is not accurate but at least shows what the ball park figure should be. It was showing around 200W this morning, while the emonTX was showing 3000W as mentioned. So I think there must be something wrong with a) the sketch code or b) the hardware.

Anyone come across this issue before?

My sketchcode is below.

Chris

#define FILTERSETTLETIME 5000                                           //  Time (ms) to allow the filters to settle before sending data

const int CT1 = 1;

#define freq RF12_868MHZ                                                // 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 = 10;                                                  // 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>

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

#include "EmonLib.h"
EnergyMonitor ct1;                                              // Create  instances for each CT channel

#include <OneWire.h>
#include <DallasTemperature.h>

#define ONE_WIRE_BUS 4                                                  // Data wire is plugged into port 2 on the Arduino
OneWire oneWire(ONE_WIRE_BUS);                                          // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
DallasTemperature sensors(&oneWire);                                    // Pass our oneWire reference to Dallas Temperature.

DeviceAddress address_T1 = { 0x28, 0x44, 0x31, 0xE5, 0x04, 0x00, 0x00, 0xA8 };

typedef struct {
int power1;                                         // Power
int T1;                                         // Temperature
int battery;                                          // Battery

//typedef struct { int power1, T1, battery;} PayloadTX;      // create structure - a neat way of packaging data for RF comms

const int LEDpin = 9;                                                   // On-board emonTx LED

boolean settled = false;

void setup()
{

if (CT1) ct1.currentTX(1, 111.1);                                     // Setup emonTX CT channel (ADC input, calibration)

sensors.begin();

rf12_initialize(nodeID, freq, networkGroup);                          // initialize RFM12B
rf12_sleep(RF12_SLEEP);

pinMode(LEDpin, OUTPUT);                                              // Setup indicator LED
digitalWrite(LEDpin, HIGH);

if (UNO) wdt_enable(WDTO_8S);                                         // Enable anti crash (restart) watchdog if UNO bootloader is selected. Watchdog does not work with duemilanove bootloader                                                             // Restarts emonTx if sketch hangs for more than 8s
}

void loop()
{

if (CT1) {
emontx.power1 = ct1.calcIrms(1480) * 240.0;                         //ct.calcIrms(number of wavelengths sample)*AC RMS voltage
Serial.print(emontx.power1);
}

sensors.requestTemperatures();                                        // Send the command to get temperatures
emontx.T1 = sensors.getTempC(address_T1) * 100;                       // Multiply by 100 to get an integer value

Serial.print(" "); Serial.print(emontx.battery);
Serial.println(); delay(100);

// because millis() returns to zero after 50 days !
if (!settled && millis() > FILTERSETTLETIME) settled = true;

if (settled)                                                            // send data only after filters have settled
{
send_rf_data();                                                       // *SEND RF DATA* - see emontx_lib
digitalWrite(LEDpin, HIGH); delay(2); digitalWrite(LEDpin, LOW);      // flash LED
emontx_sleep(5);                                                      // sleep or delay in seconds - see emontx_lib
}
}

### Re: Temperature power sketch issues

I can't see anything wrong with your sketch, but are you sure the emonTx is sending a reading of 4.6 kW, and what you've done in emoncms is right? It seems to me it's much more likely that you're doing the wrong sums in emoncms.

### Re: Temperature power sketch issues

I can't see anything wrong. I just copied the example from emoncms instructions. This had been working previously with the CT123 sketch. See below. Could it be anything to do with the interval?

Chris