Firstly thanks in advance to whoever can help me, im pretty new to arduino software and this is my first time trying to connect sensor data to Emoncms.
Im trying to send sensor readings from my CT sensor to the Emoncms web application in order to visualise my energy usage, ive got the correct readings appearing on my serial monitor but for some reason the live feed isnt appearing in the Emoncms application. Im pretty sure this has something to do with my code trying to connect with the application see below any ideas?
#include "EmonLib.h" // Include Emon Library
#include <SPI.h>
#include <Ethernet.h>
// assign a MAC address for the ethernet controller.
// fill in your address here:
byte mac[] = {
0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
// fill in an available IP address on your network here,
// for auto configuration:
IPAddress ip(192, 168, 0, 11); //ip address of ethernet sheild
IPAddress subnet(255, 255, 255, 0);
IPAddress DNS(8, 8, 8, 8);
IPAddress gw(192, 168, 0, 1);
//IPAddress gw(192, 168, 0, 254);
// initialize the library instance:
EthernetClient client;
char server[] = "http://emoncms.org/"; //emoncms URL
//IPAddress server(213, 138, 101, 177);
boolean lastConnected = false; // state of the connection last time through the main loop
String apikey = "9e4db68e8c292d38ed45663f48e0ed2e"; //api key
int node = 0; //if 0, not used
const unsigned long postingInterval = 3*1000; // delay between updates, in milliseconds
EnergyMonitor emon1; // Create an instance
void setup()
{
Serial.begin(9600);
// give the ethernet module time to boot up:
delay(1000);
// Display a welcome message
Serial.println("HTTP emoncms client v0.1 starting...");
emon1.voltage(2, 234.26, 1.7); // Voltage: input pin, calibration, phase_shift
emon1.current(1, 111.1); // Current: input pin, calibration.
}
void loop()
{
emon1.calcVI(20,2000); // Calculate all. No.of half wavelengths (crossings), time-out
emon1.serialprint(); // Print out all variables (realpower, apparent power, Vrms, Irms, power factor)
float realPower = emon1.realPower; //extract Real Power into variable
float apparentPower = emon1.apparentPower; //extract Apparent Power into variable
float powerFActor = emon1.powerFactor; //extractPower Factor into Variable
float supplyVoltage = emon1.Vrms; //extract Vrms into Variable
float Irms = emon1.Irms; //extract Irms into Variable
Serial.print("Real Power, ");
Serial.print("Apparent Power, ");
Serial.print("Power Factor, ");
Serial.print("Supply Voltage, ");
Serial.print("Irms = (");
}
// this method makes a HTTP connection to the server:
void sendData(float realPower, float apparentPower, float PowerFActor, float supplyVoltage, float Irms) {
// if there's a successful connection:
if (client.connect(server, 80)) {
Serial.println("Connecting...");
// send the HTTP PUT request:
//client.print("GET /emoncms/input/post.json?apikey=9e4db68e8c292d38ed45663f48e0ed2e&json={power");
client.print("GET /emoncms.org/input/post.json?json={power:200}&apikey=9e4db68e8c292d38ed45663f48e0ed2e");
client.print(":");
client.print(",realPower:");
client.print(realPower);
client.print(",apparentPower:");
client.print(apparentPower);
client.print(",PowerFActor:");
client.print(PowerFActor);
client.print(",supplyVoltage:");
client.print(supplyVoltage);
client.print(",Irms:");
client.print(Irms);
client.println("} HTTP/1.1");
client.println("Host: ip(192, 168, 0, 11)");
client.println("User-Agent: Arduino-ethernet");
client.println("Connection: close");
client.println();
}
else {
// if you couldn't make a connection:
Serial.println("Connection failed");
Serial.println("Disconnecting...");
client.stop();
}
}