I am new in Arduino Prograaming and I am trying to upload sensor data onto Emoncms website . I uploading data using GSM shield , EmonTx V2 Shield and Arduino duemilanove. 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. Please if somebody could help in GSM shield Syntax for data uploading
#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 = "b340460c31xxxxxxxxxxfb0297"; //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=b340460c4175317xxxxxxxx0297");
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();
}
}
Re: Data uploading onto Emoncms website using GSM Shield
Hello shreyas32177, can you tell us a bit more about the error's that you see? Why it isnt working for you.
Could it be that
client.print("GET /emoncms.org/input/post.json?json={power:200}&apikey=b340460c4175317xxxxxxxx0297");
needs to be:
client.print("GET http://emoncms.org/input/post.json?json={power:200}&apikey=b340460c4175317xxxxxxxx0297");
or
client.print("GET /input/post.json?json={power:200}&apikey=b340460c4175317xxxxxxxx0297");