alright here is my code:
/*
Mega2560 + HanRun HR911105A 11/46 + DHT22 + GY-65 + HD44780 + Photoresistor
HR911105A:
* Ethernet shield attached to pins 10, 11, 12, 13 - HanRun HR911105A
DHT22:
* Connect pin 1 (on the left) of the sensor to +5V
* Connect pin 2 of the sensor to whatever your DHTPIN is
* Connect pin 4 (on the right) of the sensor to GROUND
* Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor
GY-65:
* Connect VCC of the sensor to 3.3V (NOT 5.0V!)
* Connect SCL to i2c clock - on '168/'328 Arduino Uno/Duemilanove/etc thats Analog 5 - Arduino Mega pin 21
* Connect SDA to i2c data - on '168/'328 Arduino Uno/Duemilanove/etc thats Analog 4 - Arduino Mega pin 20
HD44780:
* 1: GND
* 2: VCC
* 3: To 10k ohm potentiometer
* 4: Connect to pin 7
* 5: GND
* 6: Connect to pin 8
* 11: Connect to pin 9
* 12: Connect to pin 10
* 13: Connect to pin 11
* 14: Connect to pin 12
* 15: VCC
* 16: GND
Photoresistor
* Connect to pin A0
*/
#include <SPI.h>
#include <Ethernet.h>
#include "DHT.h"
#include <floatToString.h> // Deprecated
#include <Wire.h>
#include <Adafruit_BMP085.h>
#include <elapsedMillis.h>
#include <LiquidCrystal.h>
#define DS1307_I2C_ADDRESS 0x68 // the I2C address of Tiny RTC
#define DHTPIN 2
#define DHTTYPE DHT22 // DHT 22 (AM2302)
char buffer[25]; // sorcery trick to concat the floats to string
elapsedMillis timer0;
#define interval 3600000
elapsedMillis timer1;
#define interval2 1000
Adafruit_BMP085 bmp;
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal lcd(7, 8, 9, 10, 11, 12); //On définie les Pins pour l'écran LCD
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
{
return ( (val/10*16) + (val%10) );
}
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
return ( (val/16*10) + (val%16) );
}
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
//IPAddress server(74,125,232,128); // numeric IP for the server (no DNS)
char server[] = "requesttests.appspot.com"; // name address for the server (using DNS)
// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(192,168,0,177);
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;
const int luminosityPin = A0;
int luminosityValue = 0;
int luminosityFinal = 0;
int cycle = 0;
// Function to set the currnt time, change the second&minute&hour to the right time
void setDateDs1307()
{
second =0;
minute = 0;
hour = 0;
dayOfWeek = 0;
dayOfMonth =0;
month =0;
year= 0;
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.write(decToBcd(0));
Wire.write(decToBcd(second)); // 0 to bit 7 starts the clock
Wire.write(decToBcd(minute));
Wire.write(decToBcd(hour)); // If you want 12 hour am/pm you need to set
// bit 6 (also need to change readDateDs1307)
Wire.write(decToBcd(dayOfWeek));
Wire.write(decToBcd(dayOfMonth));
Wire.write(decToBcd(month));
Wire.write(decToBcd(year));
Wire.endTransmission();
}
// Function to gets the date and time from the ds1307 and prints result
void getDateDs1307()
{
// Reset the register pointer
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.write(decToBcd(0));
Wire.endTransmission();
Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
second = bcdToDec(Wire.read() & 0x7f);
minute = bcdToDec(Wire.read());
hour = bcdToDec(Wire.read() & 0x3f); // Need to change this if 12 hour am/pm
dayOfWeek = bcdToDec(Wire.read());
dayOfMonth = bcdToDec(Wire.read());
month = bcdToDec(Wire.read());
year = bcdToDec(Wire.read());
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(hour, DEC);
lcd.print(":");
lcd.print(minute, DEC);
lcd.print(":");
lcd.print(second, DEC);
lcd.print(" ");
lcd.print(month, DEC);
lcd.print("/");
lcd.print(dayOfMonth, DEC);
lcd.print("/");
lcd.print(year,DEC);
lcd.setCursor(0, 1);
lcd.print("Cycle: ");
lcd.print(cycle);
//Serial.print("Day of week:");
}
void setup() {
Wire.begin();
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.print("XyliboxLabs !");
timer0 = 0; // clear the timer at the end of startup
// Open serial communications and wait for port to open:
Serial.begin(9600);
setDateDs1307(); //Set current time;
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
if (!bmp.begin()) {
Serial.println("Could not find a valid BMP085 sensor, check wiring!");
while (1) {}
}
SendShit();
}
void loop()
{
// if there are incoming bytes available
// from the server, read them and print them:
if (client.available()) {
char c = client.read();
Serial.print(c);
}
// if the server's disconnected, stop the client:
if (!client.connected()) {
//Serial.println();
//Serial.println("disconnecting.");
client.stop();
if (timer0 > interval) { // http://www.forward.com.au/pfod/ArduinoProgramming/TimingDelaysInArduino.html
timer0 -= interval; //reset the timer
SendShit();
}
}
if (timer1 > interval2) {
timer1 -= interval2; //reset the timer
getDateDs1307();//get the time data from tiny RTC
}
}
void SendShit()
{
dht.begin();
cycle = cycle + 1;
luminosityValue = analogRead(luminosityPin); // Read the value of the photoresistor
luminosityFinal = luminosityValue/10;
float h = dht.readHumidity();
float t = dht.readTemperature();
float Pa = bmp.readAltitude(101500);
float a = bmp.readPressure();
// check if returns are valid, if they are NaN (not a number) then something went wrong!
if (isnan(t) || isnan(h)) {
Serial.println("Failed to read from DHT");
} else {
Serial.println("[========= iNFOS ==========]");
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.println(" *C");
// GY-65
Serial.print("Pressure: ");
Serial.print(Pa);
Serial.print(" Pa \t");
// you can get a more precise measurement of altitude
// if you know the current sea level pressure which will
// vary with weather and such. If it is 1015 millibars
// that is equal to 101500 Pascals.
Serial.print("Altitude: ");
Serial.print(a);
Serial.println(" M");
Serial.print("Luminosity: ");
Serial.print(luminosityFinal);
Serial.print(" \t");
Serial.print("Cycle: ");
Serial.println(cycle);
}
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
// try to congifure using IP address instead of DHCP:
Ethernet.begin(mac, ip);
}
// give the Ethernet shield a second to initialize:
delay(1000);
Serial.println("[======== ETHERNET ========]");
Serial.println("connecting...");
// if you get a connection, report back via serial:
if (client.connect(server, 80)) {
Serial.println("connected");
// Make a HTTP request:
String stringOne = floatToString(buffer, h , 2); // Warning, shit is deprecated ! http://playground.arduino.cc/Main/FloatToString but that the only easy solution i've found, dtostrf(); is pain !
String stringTwo = floatToString(buffer, t , 2);
String stringThree = floatToString(buffer, Pa , 1);
String stringFour = floatToString(buffer, a , 2);
String stringFive = "GET /GetTester?getString=lolz&humidity=" + stringOne + "&temperature=" + stringTwo + "&pressure=" + stringThree + "&attitude=" + stringFour + "&lumi=" + luminosityFinal + "&cycle=" + cycle + " HTTP/1.1";
Serial.println(stringFive);
client.println(stringFive);
client.println("Host: requesttests.appspot.com");
client.println("Connection: close");
client.println();
}
else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
}
}
(a bit ugly i agree)