Hi, Im trying to use emoncms for logging data online from my arduino I got a code and modified it:
/*
HTTP emoncms client
This sketch connects to an emoncms server and sends sensor readings.
Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
* DHT22 temperature and humidity sensor attached to port A0
* Light sensor attached to port A1
created 19 Apr 2012
by Tom Igoe
modified 3 Apr 2013
by Baptiste Gaultier
based on
http://arduino.cc/en/Tutorial/WebClientRepeating
This code is in the public domain.
*/
#include <SPI.h>
#include <Ethernet.h>
#include "DHT.h"
#define DHTPIN 5 //Ersätt 13 med vilken digital pin som du vill ha givar signal till
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
short h = dht.readHumidity(); //short ger inga decimaler till värdet av luftfuktigheten, läses av i %
short t = dht.readTemperature (); //short ger inga decimaler till temperaturen, läses av i celsius
// number of readings we made since the last packet sent :
byte readings = 0;
// assign a MAC address for the ethernet controller.
// fill in your address here:
byte mac[] = {
0x90, 0xA2, 0xDA, 0x00, 0x69, 0xD5};
// fill in an available IP address on your network here,
// for auto configuration:
IPAddress ip( 192, 168, 254, 188 );
IPAddress subnet(255, 255, 255, 0);
// initialize the library instance:
EthernetClient client;
char server[] = "www.baptistegaultier.fr"; //emoncms URL
boolean lastConnected = false; // state of the connection last time through the main loop
void setup() {
// start serial port:
Serial.begin(9600);
dht.begin();
// give the ethernet module and DHT22 sensor time to boot up:
delay(1000);
// Display a welcome message
Serial.println("HTTP emoncms client v0.1 starting...");
// attempt a DHCP connection:
Serial.println("Attempting to get an IP address using DHCP:");
if (!Ethernet.begin(mac)) {
// if DHCP fails, start with a hard-coded address:
Serial.println("failed to get an IP address using DHCP, trying manually");
Ethernet.begin(mac, ip);
}
// print the Ethernet board/shield's IP address:
Serial.print("My IP address: ");
Serial.println(Ethernet.localIP());
}
void loop() {
// if there's incoming data from the net connection.
// send it out the serial port. This is for debugging
// purposes only:
if (client.available()) {
client.flush();
client.stop();
}
// if there's no net connection, but there was one last time
// through the loop, then stop the client:
if (!client.connected() && lastConnected) {
Serial.println();
Serial.println("Disconnecting...");
client.stop();
}
short h = dht.readHumidity(); //short ger inga decimaler till värdet av luftfuktigheten, läses av i %
short t = dht.readTemperature (); //short ger inga decimaler till temperaturen, läses av i celsius
Serial.print("Temperatur: "); // Texten innan temperaturvärdet
Serial.print(t); //temperaturens värde i grader celsius
Serial.print(" *C "); //visar på monitorn att det är grader celsius
Serial.print(" Luftfuktighet: "); //texten innan luftluktighetens värde.
Serial.print(h); //luftfuktighetens värde i %
Serial.print(" %\t"); // vet inte vad detta är???
Serial.println(" ");//gör så att nästa indata på monitorn hoppar ett steg ner (som när man trycker på enter, istället för att det ska tabbas vidare till höger.
Serial.print("Sending data to emoncms");
sendData(t, h);
readings = 0;
// store the state of the connection for next time through
// the loop:
lastConnected = client.connected();
}
// this method makes a HTTP connection to the server:
void sendData(short t, short h) {
// 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=178cf0ce5e3a46295b48e6b1bfc20932");
client.print(":");
client.print(",Temperatur:");
client.print(t);
client.print(",Luftfuktighet:");
client.print(h);
client.println("} HTTP/1.1");
client.println("Host: www.baptistegaultier.fr");
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();
}
delay(1000);
}
But nothing happens at all, nothing is printed to the seriall monitor or anything, I can't figure out whats wrong, it
get verified and everything. It's nothing wrong with the arduino (have tried other codes that I know work).
Could someone please help me figure out whats wrong?
Tank you!