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, any ideas?
[code]
#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 = "MYAPIKEY"; //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=MYAPIKEY&json={power");
client.print("GET /emoncms.org/input/post.json?json={power:200}&apikey=MYAPIKEY");
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();
}
}
[/code]
Re: Sending Arduino Sensor data to Emoncms
You should probably edit your post to hide your APIKey.
one issue is the you have the IP ADDRESS of the server set but in your Client.print string you have emoncms.org.
you can simply test this in a webrowser
try http://<ipaddress of server>/<client.print string>
if you get the response Ok you know it's correct.
Also have a look at the Api help page on the input tab on emoncms.org
Re: Sending Arduino Sensor data to Emoncms
Would changing the line:
client.print("GET /emoncms.org/input/post.json?json={power:200}&apikey=MYAPIKEY");
to:
client.print("GET /input/post.json?json={power:200}&apikey=MYAPIKEY");
do it?
Re: Sending Arduino Sensor data to Emoncms
Thanks for both your responses; Trystan i made the change you recommended but the values from the sensor are still not appearing in emoncms. any other ideas?
Re: Sending Arduino Sensor data to Emoncms
{
client.print(F("GET /input/post.json?node=1&csv="));
client.print(F("User-Agent: Arduino-ethernet"));
client.println(F("Connection: close"));
client.println();
}
So for you, I would try something like:
if(client.connect("emoncms.org",80))
{
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.print("}&apikey="
client.println(F("Connection: close")); // Although not technically necessary, I found this helpful
client.println();
Re: Sending Arduino Sensor data to Emoncms
I am new in Arduino Programming and I am trying to upload sensor data onto emoncms website using GSM shield , EmonTx V2 shield and Arduino duemilanove. I just want to upload real power readings
ive got the correct readings appearing on my serial monitor but for some reason the live feed isnt appearing in the Emoncms application. I think their is something wrong in my code while connecting to website , please if anybody could help
#include "EmonLib.h" // Include Emon Library
#include <SPI.h>
#include <GSM.h>
#define GPRS_APN "data.lycamobile.co.uk" // replace your GPRS APN
#define GPRS_LOGIN "lmuk" // replace with your GPRS login
#define GPRS_PASSWORD "plus" // replace with your GPRS password
#define PINNUMBER ""
GSMClient client;
GPRS gprs;
GSM gsmAccess;
char server[] = "http://emoncms.org/"; //emoncms URL
boolean lastConnected = false; // state of the connection last time through the main loop
String apikey = "b340460c41753172b26XXXXXXXX9fb0297"; //api key
int node = 0; //if 0, not used
const unsigned long postingInterval = 3*1000; // delay between updates, in milliseconds
EnergyMonitor ct1;
const int LEDpin = 9;// 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...");
ct1.voltage(0, 300.26, 1.7); // Voltage: input pin, calibration, phase_shift
ct1.current(1, 60.606);
pinMode(LEDpin, OUTPUT);
digitalWrite(LEDpin, HIGH);
boolean notConnected = true;
// After starting the modem with GSM.begin()
// attach the shield to the GPRS network with the APN, login and password
while(notConnected)
{
if((gsmAccess.begin(PINNUMBER)==GSM_READY) &
(gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)==GPRS_READY))
notConnected = false;
else
{
Serial.println("Not connected");
delay(1000);
}
}
Serial.println("Connected to GPRS network"); // Current: input pin, calibration.
}
void loop()
{
ct1.calcVI(20,2000); // Calculate all. No.of half wavelengths (crossings), time-out
ct1.serialprint(); // Print out all variables (realpower, apparent power, Vrms, Irms, power factor)
float realPower = ct1.realPower; //extract Real Power into variable
Serial.print("ct1.realpower ");
Serial.print(" ");
}
// this method makes a HTTP connection to the server:
void sendData(float realPower) {
// if there's a successful connection:
if (client.connect(server, 80)) {
Serial.println("Connecting...");
// send the HTTP PUT request:
//client.print(" /emoncms/input/post.json?apikey=MYAPIKEY&json={power");
client.print("GET /emoncms.org/input/post.json?json={power:200}&apikey=b340460c4175317XXXXX6809fb0297");
client.print(realPower);
client.println("} HTTP/1.1");
client.println("Host: emoncms.org");
client.println("User-Agent: GSM shield");
client.println("Connection: close");
client.println();
}
else {
// if you couldn't make a connection:
Serial.println("Connection failed");
Serial.println("Disconnecting...");
client.stop();
}
}