Sorry for my bad presentation. Perhaps my english isn't really good.
My local web site is on my PC. I don't know if it possible to have a web server and a web client in the same time on Arduino.
The RST answer of my web site is at the end of the exchange between ethernet shield and my web server. And it interrupts the connection.
#include <Arduino.h>
#include "SdFat.h"
#include <SPI.h>
#include <RTClib.h>
#include <Wire.h>
#include <Ethernet.h>
RTC_DS1307 rtc;
SdFat sd;
File logFile;
#define FILE_BASE_NAME "Data"
const uint8_t chipSelect = 4;
const char fileName[] = "datalog.txt";
// Error messages stored in flash.
#define error(msg) sd.errorHalt(F(msg))
// this must be unique
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x59, 0x67 };
// change to your network settings
byte ip[] = { 192, 168, 5, 53 };
byte gateway[] = { 192, 168, 5, 1 };
byte subnet[] = { 255, 255, 255, 0 };
char server[] = "192.168.5.50";
EthernetClient client;
String apikey = "aaaabbbbbcccccdddddddeeeeeeeee"; //localhost api key
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 = 10 * 1000; // delay between updates, in milliseconds
//============================================================
int value1[17] = {25341, 440, 5879, 222478, 15, 48, 65, 95, 99, 75, 32, 147, 258, 963, 5789, 11, 28};
int value2[11] = {25341, 440, 5879, 222478, 15, 48, 65, 95, 99, 75, 32};
//=============================================================
void dateTime(uint16_t* date, uint16_t* time) {
DateTime now = rtc.now();
// return date using FAT_DATE macro to format fields
*date = FAT_DATE(now.year(), now.month(), now.day());
// return time using FAT_TIME macro to format fields
*time = FAT_TIME(now.hour(), now.minute(), now.second());
}
//============================================================
void writeSD() {
const uint8_t BASE_NAME_SIZE = sizeof(FILE_BASE_NAME) - 1;
char fileName[13] = FILE_BASE_NAME "00.csv";
// Find an unused file name.
if (BASE_NAME_SIZE > 6) {
("FILE_BASE_NAME too long");
}
while (sd.exists(fileName)) {
if (fileName[BASE_NAME_SIZE + 1] != '9') {
fileName[BASE_NAME_SIZE + 1]++;
} else if (fileName[BASE_NAME_SIZE] != '9') {
fileName[BASE_NAME_SIZE + 1] = '0';
fileName[BASE_NAME_SIZE]++;
} else {
error("Can't create file name");
}
}
DateTime now = rtc.now();
unsigned long currentTime = now.unixtime();
SdFile::dateTimeCallback(dateTime);
if (!logFile.open(fileName, O_CREAT | O_WRITE | O_EXCL)) {
error("write_logFile.open");
}
logFile.print("GET /emoncms/input/bulk?data=[[");
/*logFile.print("34,0,{\"temp\":");
logFile.print(temperature);
logFile.print("}],[34,1,{\"H2\":");
logFile.print(MQGetGasPercentage(MQRead(MQ_PIN\) / Ro, GAS_H2));
logFile.print("}],[34,2,{\"power1\":");
logFile.print(Irms1 * volt);
logFile.print("}],[34,3,{\"power2\":");
logFile.print(Irms2 * volt);
logFile.print("}],[");*/
logFile.print("34,4,{\"V\":");
logFile.print(value1[3]);
logFile.print("},{\"I\":");
logFile.print(value1[4]);
logFile.print("},{\"VPV\":");
logFile.print(value1[5]);
logFile.print("},{\"PPV\":");
logFile.print(value1[6]);
logFile.print("},{\"CS\":");
logFile.print(value1[7]);
logFile.print("},{\"ERR\":");
logFile.print(value1[8]);
logFile.print("},{\"H19\":");
logFile.print(value1[10]);
logFile.print("},{\"H20\":");
logFile.print(value1[11]);
logFile.print("},{\"H21\":");
logFile.print(value1[12]);
logFile.print("},{\"H22\":");
logFile.print(value1[13]);
logFile.print("},{\"H23\":");
logFile.print(value1[14]);
logFile.print("},{\"HSDS\":");
logFile.print(value1[15]);
logFile.print("}],[36,5,{\"MODE\":");
logFile.print(value2[3]);
logFile.print("},{\"CS\":");
logFile.print(value2[4]);
logFile.print("},{\"AC_OUT_V\":");
logFile.print(value2[5]);
logFile.print("},{\"AC_OUT_I\":");
logFile.print(value2[6]);
logFile.print("},{\"AR\":");
logFile.print(value2[7]);
logFile.print("},{\"WARN\":");
logFile.print(value2[8]);
/*logFile.print("}],[34,6,{\"V\":");
logFile.print(value3[1]);
logFile.print("},{\"I\":");
logFile.print(value3[2]);
logFile.print("},{\"P\":");
logFile.print(value3[3]);
logFile.print("}, {\"CE\":");
logFile.print(value3[4]);
logFile.print("},{\"SOC\":");
logFile.print(value3[5]);
logFile.print("},{\"TTG\":");
logFile.print(value3[6]);
logFile.print("},{\"AR\":");
logFile.print(value3[9]);
logFile.print("},{\"BMV\":");
logFile.print(value3[10]);
logFile.print("},{\"H1\":");
logFile.print(value3[13]);
logFile.print("},{\"H2\":");
logFile.print(value3[14]);
logFile.print("},{\"H3\":");
logFile.print(value3[15]);
logFile.print("},{\"H4\":");
logFile.print(value3[16]);
logFile.print("},{\"H5\":");
logFile.print(value3[17]);
logFile.print("},{\"H6\":");
logFile.print(value3[18]);
logFile.print("},{\"H7\":");
logFile.print(value3[19]);
logFile.print("},{\"H8\":");
logFile.print(value3[20]);
logFile.print("},{\"H9\":");
logFile.print(value3[21]);
logFile.print("},{\"H10\":");
logFile.print(value3[22]);
logFile.print("},{\"H11\":");
logFile.print(value3[23]);
logFile.print("},{\"H12\":");
logFile.print(value3[24]);
logFile.print("},{\"H17\":");
logFile.print(value3[25]);
logFile.print("},{\"H18\":");
logFile.print(value3[26]); */
logFile.print("}]]&time=");
logFile.print(currentTime - 7200);
logFile.print("&apikey=");
logFile.println(apikey);
logFile.println("HTTP/1.1");
logFile.println("Host:localhost");
logFile.println("User-Agent: Arduino-ethernet");
logFile.println("Connection: close");
logFile.println();
// Force data to SD and update the directory entry to avoid data loss.
if (!logFile.sync() || logFile.getWriteError()) {
error("logFile write error");
}
logFile.close();
Serial.println(F("Data writed"));
}