How to use emonlib variables to be sent via SMS

Good day to all! I am a newbie in Arduino and I have a problem concerning how to convert the variables in the emonlib so that the it can be sent via SMS.

I thought of converting the variables (which, i think, are declared as double) to string or char type. I have searched the net for solutions, however, there where no fit answers.

To those who can help please do impart your opinions it will be highly appreciated. Attached below is the code of the program.

// EmonLibrary examples openenergymonitor.org, Licence GNU GPL V3
#include "EmonLib.h"               // Include Emon Library
EnergyMonitor emon1;             // Create an instance
#include <SerialGSM.h>
#include <SoftwareSerial.h>
SerialGSM cell(2,3);
void setup()
{  
 Serial.begin(9600);
 Serial.println("CLEARDATA");
 Serial.println("LABEL,Time,RealPower,ApparentPower,Voltage,Current,PowerFactor");
 emon1.voltage(2, 280, 2.5);  // Voltage: input pin, calibration, phase_shift
 emon1.current(1, 27.5);       // Current: input pin, calibration.
 cell.begin(9600);
 cell.Verbose(true);
 cell.Boot();
 cell.FwdSMS2Serial();
 cell.Rcpt("+972123456789");
 cell.Message("hello world");
 cell.SendSMS();
}
void loop()
{
 Serial.print("DATA,TIME,"); 
 Serial.print(emon1.realPower); Serial.print(",");
 Serial.print(emon1.apparentPower); Serial.print(",");
 Serial.print(emon1.Vrms); Serial.print(",");
 Serial.print(emon1.Irms); Serial.print(",");
 Serial.print(emon1.powerFactor); Serial.println(",");
 delay(1000);
 emon1.calcVI(20,2000);         // Calculate all. No.of half wavelengths (crossings), time-out
  if (cell.ReceiveSMS())
   Serial.println(cell.Message());
   cell.DeleteAllSMS();
}

Please do not cross-post. This wastes time and resources as people attempt to answer your question on multiple threads.

Your other thread deleted.

  • Moderator

Please edit your post, select the code, and put it between [code][/code] tags.

You can do that by hitting the “Code” icon above the posting area. It is the first icon, with the symbol: </>

Please use code tags.

Read this before posting a programming question

How to use this forum

Thank you for that, Sir Nick. It has been edited. How do you tag people?

 Serial.print(emon1.realPower); Serial.print(",");
 Serial.print(emon1.apparentPower); Serial.print(",");
 Serial.print(emon1.Vrms); Serial.print(",");
 Serial.print(emon1.Irms); Serial.print(",");
 Serial.print(emon1.powerFactor); Serial.println(",");

Which produces what output?

I thought of converting the variables (which, i think, are declared as double) to string or char type. I have searched the net for solutions, however, there where no fit answers.

You did not look very hard if you could not find how to convert a float or double to a string (dtostrf()) or an int to a string (itoa()).

If you think you are going to find an example that sends data from the EnergyMonitor instance as an SMS, you are dreaming.

Serial.print(emon1.realPower); Serial.print(",");
 Serial.print(emon1.apparentPower); Serial.print(",");
 Serial.print(emon1.Vrms); Serial.print(",");
 Serial.print(emon1.Irms); Serial.print(",");
 Serial.print(emon1.powerFactor); Serial.println(",");

this part is just for the serial monitor so that i can view the data being read.

I have tried using the dtostrf(). However, after i added the library, i tested compiling the original code without the dtostrf() command but there was an error. The error was not displayed in the message window area.

this part is just for the serial monitor so that i can view the data being read.

You did not post a link to the EnergyMonitor library, so the only way we have to know if realPower, apparentPower, etc. are floats or ints or something else is to see the output.

I have tried using the dtostrf(). However, after i added the library, i tested compiling the original code without the dtostrf() command but there was an error. The error was not displayed in the message window area.

Was it printed on a postcard and mailed to you? Sent via morse code by blinking the power light on the PC? Sent by letting the magic smoke out as smoke signals?

How do you know there was an error?