sorry!, here is my code:
/*
Project Arduino, FINAL V1.0 3 Sensors,Time&Date,FTP,SD,Errorlog
- Leest temperatuur en vochtigheid uit met behulp van SHT11 temperatuur/vochtigheid sensoren van Sensirion
- Slaat de logdata op SD op en verzend deze naar een FTP server
- Tijd word opgehaald van NTP server en gebruikt in de errorlog en logfile
- Filenaam om de Arduino te indentificeren instellen door het TXT bestand filename aan te passen op de SD kaart
- Errorlog word op de SD opgelsagen onder de naam ERRORLOG.TXT
By: Jan Verhoeckx
*/
// INCLUDED LIBRARIES
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\\
//Libraries:
#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <SD.h>
#include <Time.h>
#include <FTPsend.h>
#include <SHT1x.h>
#include <Streaming.h>
// GLOBALE VARIABELEN
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\\
//Pin 4 reserveren voor SD:
const int chipSelect = 4;
//Globale variabelen:
int localtimeA = 0;
int localtimeB = 0;
int localtimeC = 0;
char time[20] = {0};
char fileName[50] = {0};
float temp_c;
float humidity;
float temp_c2;
float humidity2;
float temp_c3;
float humidity3;
long previousMillis = 0;
long interval = 1000;
// ETHERNET INSTELLINGEN
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\\
// MAC adres van de Arduino
byte mac[] = {
0x90, 0xA2, 0xDA, 0x0D, 0x2A, 0x59 };
// PINNEN VOOR SENSOREN DEFINEREN
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\\
// SHT11 sensor define datapin en clockpin
#define dataPin3 8
#define dataPin2 9
#define dataPin 10
#define clockPin 11
SHT1x sht1x(dataPin, clockPin);
SHT1x sht2x(dataPin2, clockPin);
SHT1x sht3x(dataPin3, clockPin);
// BEGIN SETUP && ETHERNET VERBINDING STARTEN && VERSIE PRINTEN VIA SD
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\\
void setup()
{
// Serial output:
Serial.begin(38400);
Serial.println("STX11 sensors with time, SD, Ethernet, FTP, Errorlog --->> By: Jan Verhoeckx FINAL V1.0 <<---");
// start Ethernet en UDP connectie
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// Als er geen verbinding kan worden gemaamkt, niet verder gaan:
for(;;);
}
Serial.println("My IP address: ");
for (byte thisByte = 0; thisByte < 4; thisByte++) {
// print het ip over serial:
Serial.print(Ethernet.localIP()[thisByte], DEC);
Serial.print(".");
}
//UDP begin:
Udp.begin(localPort);
// SD INITIALISEREN
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\\
//SD begin:
digitalWrite(10, HIGH);
// Kijken of er een SD kaart aanwezig is, aangeven via serial of de SD gereed is:
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
return;
}
Serial.println("card initialized.");
}
// BEGIN LOOP && TIMER INSTELLEN OM DE MINUUT METEN
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\\
void loop()
{
//Om de minuut meten en de data naar de FTP server verzenden:
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
// TIJD BEREKENEN VAN NTP SERVER
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\\
//Tijd van NTP server verkrijgen:
sendNTPpacket(timeServer); // send an NTP packet to a time server
// wait to see if a reply is available
if ( Udp.parsePacket() ) {
// We've received a packet, read the data from it
Udp.read(packetBuffer,NTP_PACKET_SIZE); // read the packet into the buffer
//the timestamp starts at byte 40 of the received packet and is four bytes,
// or two words, long. First, esxtract the two words:
unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);
unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]);
// combine the four bytes (two words) into a long integer
// this is NTP time (seconds since Jan 1 1900):
unsigned long secsSince1900 = highWord << 16 | lowWord;
// Unix time starts on Jan 1 1970. In seconds, that's 2208988800:
const unsigned long seventyYears = 2208988800UL;
// subtract seventy years:
unsigned long epoch = secsSince1900 - seventyYears;
// Set time voor time librarie
setTime(secsSince1900 - seventyYears);
//Bereken local time en schrijf weg naar localtimeA, B en C
localtimeA = ((epoch % 86400L) /3600 +1); //86400L //9300L
localtimeB = ((epoch % 3600) / 60);
localtimeC = (epoch % 60);
}
// SENSOREN UITLEZEN
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\\
// Data van de sensor uitlezen
temp_c = sht1x.readTemperatureC();
humidity = sht1x.readHumidity();
//sensor2
temp_c2 = sht2x.readTemperatureC();
humidity2 = sht2x.readHumidity();
//sensor3
temp_c3 = sht3x.readTemperatureC();
humidity3 = sht3x.readHumidity();
// LOGDATA NAAR SD SCHRIJVEN
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\\
//Naam van het bestand van de SD kaart aflezen, zo word de Arduino in Hobbit geïndentificeerd.
File FileNameonSD = SD.open("filename.txt");
byte index = 0;
while (FileNameonSD.available())
{
fileName[index++] = FileNameonSD.read();
fileName[index] = '\0';
}
Serial.println(fileName);
//tijd, en meetwaardes naar SD schrijven
//verwijder oud logfile
SD.remove(fileName);
Serial.print("naar SD schrijven...");
File dataFile = SD.open(fileName, FILE_WRITE);
if (dataFile) {
if (localtimeB < 10 ) {
dataFile << "" << "Localtime: " << localtimeA << ":" << "0" << localtimeB << "\n" << endl;}
else{
dataFile << "" << "Localtime: " << localtimeA << ":" << localtimeB << "\n" << endl;}
dataFile << "" << "Sensor1 Humidity: " << humidity << " %\t " << "Temperature: " << temp_c << " *C\n" << endl;
dataFile << "" << "Sensor2 Humidity: " << humidity2 << " %\t " << "Temperature: " << temp_c2 << " *C\n" << endl;
dataFile << "" << "Sensor3 Humidity: " << humidity3 << " %\t " << "Temperature: " << temp_c3 << " *C\n" << endl;
dataFile.close();
}
// Als de SD niet bereikbaar is, geef een error via serial en in de errorlog:
else {
Serial.println("error opening SD");
}
// LOGDATA VIA FTP VERZENDEN
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\\
//Gegevens over FTP naar FTP server verzenden
//FTP
if(sentFile(fileName)){
Serial.println("FTP OK");
}
else{
Serial.println("FTP FAIL");
File errorfile = SD.open("errorlog.txt", FILE_WRITE);
if (errorfile) {
errorfile << "local time: " << year() << "/" << month() << "/" << day() << "" << endl;
if (localtimeB < 10 ) {
dataFile << "" << "Localtime: " << localtimeA << ":" << "0" << localtimeB << "Failed sending data over FTP\n" << endl;}
else{
dataFile << "" << "Localtime: " << localtimeA << ":" << localtimeB << "Failed sending data over FTP\n" << endl;}
errorfile.close();
}
}
}
}