Hi!
I have started my energy monitor proj. Using http://emoncms.org/ website to upload energy meter data but arduino won´t do it.
#include <SPI.h> #include <Ethernet.h> // assign a MAC address for the ethernet controller. // fill in your address here: byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; // fill in an available IP address on your network here, // for manual configuration: IPAddress ip(192, 168, 0, 27); // initialize the library instance: EthernetClient client; //IPAddress server(176,227,193,50); char server[] = "emoncms.org"; unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds boolean lastConnected = false; // state of the connection last time through the main loop const unsigned long postingInterval = 15*1000; // delay between updates, in milliseconds void setup() { // start serial port: Serial.begin(115200); // give the ethernet module time to boot up: delay(1000); // start the Ethernet connection using a fixed IP address and DNS server: 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()) { char c = client.read(); Serial.print(c); } // 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(); } // if you're not connected, and ten seconds have passed since // your last connection, then connect again and send data: if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) { httpRequest(); } // 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 httpRequest() { // if there's a successful connection: if (client.connect(server, 80)) { Serial.println("connecting..."); // send the HTTP GET request: client.print("GET /node/set.json?nodeid=10&data=20,20,20,20&apikey=xxxxxxxxxxxx HTTP/1.1"); client.print("Host:emoncms.org"); client.print("User-Agent: Arduino"); client.print("Connection: close"); client.println(); // note the time that the connection was made: lastConnectionTime = millis(); } else { // if you couldn't make a connection: Serial.println("connection failed"); Serial.println("disconnecting."); client.stop(); } }
It just simple code to get arduino sending data to emoncms.
Server response:
GET /node/set.json?nodeid=10&data=20,20,20,20&apikey=xxxxxxxxxxxxx HTTP/1.1 Host:emoncms.org User-Agent: Arduino Connection: close HTTP/1.1 400 Bad Request Date: Sat, 12 Apr 2014 12:44:48 GMT Server: Apache/2.2.22 (Ubuntu) Vary: Accept-Encoding Content-Length: 329 Connection: close Content-Type: text/html; charset=iso-8859-1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>400 Bad Request</title> </head><body> <h1>Bad Request</h1> <p>Your browser sent a request that this server could not understand.<br /> </p> <hr> <address>Apache/2.2.22 (Ubuntu) Server at h176-227-193-50.host.redstation.co.uk Port 80</address> </body></html>
Re: 400 Bad request
Log into emoncms.org and take a look at the Input Api Help Page (on the Input page) which lists the data formats.
I can't see "/node/set.json" on the list.
Re: 400 Bad request
From the http://emoncms.org/node/api
With write apikey: http://emoncms.org/node/set.json?nodeid=10&data=20,20,20,20&apikey=xxxxx...