Hello,
I am trying to get the Energy Monitor Shield from Seeed to work (http://wiki.seeedstudio.com/wiki/Energy_Monitor_Shield_V0.9b) but struggling to use the provided sketch. As far as I know I need to transform the code to make it work with MySensors 2.0. I am rubbish with code (only know a little python) and have no clue where to start or decipher the error messages.
The original code looks like this:
/*
This example code is in the public domain.
*/
#include <SPI.h>
#include <MySensor.h> // Include MySensors.org Library V1.5
#include "EmonLib.h" // Include Emon Library
#include <LCD5110_Graph_SPI.h> // Include NOKIA5110 Library
#define CHILD_ID_POWER 0
EnergyMonitor emon;
LCD5110 myGLCD(5,6,3);
extern unsigned char SmallFont[];
MyTransportNRF24 transport(7, 8); //for EMv1
MySensor gw(transport);
unsigned long lastSend;
unsigned long SEND_FREQUENCY = 20000; // Minimum time between send (in milliseconds). We don't wnat to spam the gateway.
float Irms;
float lastIrms = -99;
char tbuf[8];
char sbuf[12];
MyMessage IrmsMsg(CHILD_ID_POWER, V_KWH);
void setup()
{
myGLCD.InitLCD();
myGLCD.setFont(SmallFont);
myGLCD.update();
// The third argument enables repeater mode.
gw.begin(NULL, AUTO, true),
gw.sendSketchInfo("Energy Monitor v1", "1.0");
// emon.current(0, 111.1); // Current: input pin, calibration.
emon.current(0, 66.5);
// Register all sensors to gw (they will be created as child devices)
gw.present(CHILD_ID_POWER, S_POWER);
}
void loop()
{
gw.process();
unsigned long now = millis();
double Irms = emon.calcIrms(1480); // Calculate Irms only
float realIrms = emon.Irms*220; //extract Real Power into variable
if (realIrms != lastIrms) {
gw.send(IrmsMsg.set(realIrms, 1)); //send to gateway
lastIrms=realIrms;
}
dtostrf(realIrms,5,2,tbuf);
sprintf(sbuf, " %s kWt", tbuf);
myGLCD.print(sbuf, 20, 0);
myGLCD.print("Powr:", 0, 0);
dtostrf(Irms,5,2,tbuf);
sprintf(sbuf, " %s Amp", tbuf);
myGLCD.print(sbuf, 20, 10);
myGLCD.print("Irms:", 0, 10);
myGLCD.update();
Serial.print("Power: ");
Serial.println(realIrms);
gw.sleep(SEND_FREQUENCY);
}```
Then I transformed it to:
/*
This example code is in the public domain.
*/
#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>
#include <SPI.h>
#include <MySensors.h> // Include MySensors.org Library V1.5
#include "EmonLib.h" // Include Emon Library
#include <LCD5110_Graph_SPI.h> // Include NOKIA5110 Library
#define CHILD_ID_POWER 0
#define MY_RADIO_NRF24
EnergyMonitor emon;
LCD5110 myGLCD(5,6,3);
extern unsigned char SmallFont[];
MyTransportNRF24 transport(7, 8); //for EMv1
unsigned long lastSend;
unsigned long SEND_FREQUENCY = 20000; // Minimum time between send (in milliseconds). We don't wnat to spam the gateway.
float Irms;
float lastIrms = -99;
char tbuf[8];
char sbuf[12];
MyMessage IrmsMsg(CHILD_ID_POWER, V_KWH);
void setup()
{
myGLCD.InitLCD();
myGLCD.setFont(SmallFont);
myGLCD.update();
// The third argument enables repeater mode.
begin(NULL, AUTO, true),
sendSketchInfo("Energy Monitor v1", "1.0");
// emon.current(0, 111.1); // Current: input pin, calibration.
emon.current(0, 66.5);
// Register all sensors to gw (they will be created as child devices)
present(CHILD_ID_POWER, S_POWER);
}
void loop()
{
unsigned long now = millis();
double Irms = emon.calcIrms(1480); // Calculate Irms only
float realIrms = emon.Irms*220; //extract Real Power into variable
if (realIrms != lastIrms) {
send(IrmsMsg.set(realIrms, 1)); //send to gateway
lastIrms=realIrms;
}
dtostrf(realIrms,5,2,tbuf);
sprintf(sbuf, " %s kWt", tbuf);
myGLCD.print(sbuf, 20, 0);
myGLCD.print("Powr:", 0, 0);
dtostrf(Irms,5,2,tbuf);
sprintf(sbuf, " %s Amp", tbuf);
myGLCD.print(sbuf, 20, 10);
myGLCD.print("Irms:", 0, 10);
myGLCD.update();
Serial.print("Power: ");
Serial.println(realIrms);
sleep(SEND_FREQUENCY);
} ```
But still get the same error which is:
MySensors.h:287:4: error: #error No forward link or gateway feature activated. This means nowhere to send messages! Pretty pointless.
#error No forward link or gateway feature activated. This means nowhere to send messages! Pretty pointless.
^
exit status 1
Error compiling for board Arduino/Genuino Mega or Mega 2560.
I think the sketch was written some time ago, using MySensors 1.5, not sure how to change it to the updated version.
Appreciate any help
Regards
Christian