#include #include #include #include #define DS3231_I2C_ADDRESS 104 #define SSID "NPG_GUEST2"//your network name #define PASS "npgandour2017"//your network password #define IP "karlytau.raidghost.com" // thingspeak.com #define port ",80"//port #define Baud_Rate 115200 //Another common value is 9600 #define DELAY_TIME 600000 //time in ms between posting data to ThingSpeak //http://www.timestamp.fr/? byte seconds, minutes, hours, day, date, month, year; char weekDay[4]; byte tMSB, tLSB; float temp3231; // ultrasonic int trig = 12; int echo = 11; long lecture_echo; //DS18S20 Sonde de temperature signal pin on digital 2 int DS18S20_Pin = 2; //choix de l'adresse mac pour le reseau byte mac[] = { //0xBA, 0xAD, 0xBE, 0xEF, 0xFE, 0x03 // prod3 //0xBA, 0xAD, 0xBE, 0xEF, 0xFE, 0x02 // prod2 //0xBA, 0xAD, 0xBE, 0xEF, 0xFE, 0x04// prod4 //0xBA, 0xAD, 0xBE, 0xEF, 0xFE, 0x01// prod1 }; //T1124154091014 //ajout ds18b20 //Temperature chip i/o OneWire ds(DS18S20_Pin); // on digital pin 2 //fin ds18b20 // Enter the IP address for Arduino, as mentioned we will use 192.168.1.33 // Be careful to use , insetead of . when you enter the address here //IPAddress ip(192,168,1,22); //prod2 //IPAddress ip(192,168,1,46); //prod3 //IPAddress ip(192,168,1,41);//prod1 //IPAddress ip(192,168,1,42);//prod4 int photocellPin = 0; // Analog input pin on Arduino we connected the SIG pin from sensor int photocellReading; // Here we will place our reading String GET = "GET /test.php?value="; float h = 0; int i = 0; float y = 0; float x = 0; float z = 0; float w = 0; char essai = 0; char server[] = "karlytau.raidghost.com"; //char server[] = "karlytau.fr"; // Initialize the Ethernet server library EthernetClient client; void setup() { Wire.begin(); // temp time // Serial.begin starts the serial connection between computer and Arduino Serial.begin(9600); Serial.println("AT"); delay(5000); bool connected = connectWiFi(); // start the Ethernet connection //Ethernet.begin(mac, ip); //Ethernet.begin(mac); pinMode(trig, OUTPUT); digitalWrite(trig, LOW); pinMode(echo, INPUT); } void loop() { delay(DELAY_TIME); get3231Date(); x = get3231Temp(); float temperature_ds18b20 = getTemp(); //Serial.println(temperature_ds18b20); z = temperature_ds18b20; delay(1000); Serial.println(x); Serial.println(z); digitalWrite(trig, HIGH); delayMicroseconds(10); digitalWrite(trig, LOW); lecture_echo = pulseIn(echo, HIGH); y = lecture_echo / 58; Serial.println(y); // Connect to the server (your computer or web page) String cmd = "AT+CIPSTART=\"TCP\",\""; //add IP address and port // la forme est AT+CIPSTART="TCP","116.228.221.51","80" cmd += IP; cmd += "\",80"; Serial.println(cmd); delay(2000); String GET = "GET /write_data_full.php?value="; GET += y + "&t_cuve=" + z + "&t_gara=" + x + "&local=" + "&ID=" + ID; /* client.print(year, DEC); client.print("-"); client.print(month, DEC); client.print("-"); client.print(date, DEC); client.print("%20"); client.print(hours, DEC); client.print(":"); client.print(minutes, DEC); client.print(":"); client.print(seconds, DEC); */ h == 0; i == 0; cmd = GET; cmd += " HTTP/1.0\r\n"; cmd += "Host: karlytau.raidghost.com\r\n\r\n"; GET == 0; //Serial.println(cmd); //Use AT commands to send data Serial.print("AT+CIPSEND="); Serial.println(cmd.length()); if(Serial.find(">")){ //send through command to update values Serial.println(cmd); Serial.println("test ok"); }else{ //cmd = ">" + cmd; //Serial.println("AT+CIPCLOSE"); //je l'ai supprimé car sinon le wifi s'arrete. Serial.println("ERROR"); } // la requette doit etre comme cela http://karlytau.raidghost.com/test.php?value=20&local=2017-01-29%2022:29:47 //elle est visible dans la console if(Serial.find("OK")){ //success! Your most recent values should be online. //Serial.println("OK"); return true; }else{ Serial.println("ERROR"); return false; } } else { // If Arduino can't connect to the server (your computer or web page) Serial.println("--> connection failed\n"); } // Give the server some time to recieve the data and store it. I used 10 seconds here. Be advised when delaying. //If u use a short delay, the server might not capture data because of Arduino transmitting new data too soon. delay(4000); } // Convert normal decimal numbers to binary coded decimal byte decToBcd(byte val) { return ( (val/10*16) + (val%10) ); } void get3231Date() { // send request to receive data starting at register 0 Wire.beginTransmission(DS3231_I2C_ADDRESS); // 104 is DS3231 device address Wire.write(0x00); // start at register 0 Wire.endTransmission(); Wire.requestFrom(DS3231_I2C_ADDRESS, 7); // request seven bytes if(Wire.available()) { seconds = Wire.read(); // get seconds minutes = Wire.read(); // get minutes hours = Wire.read(); // get hours day = Wire.read(); date = Wire.read(); month = Wire.read(); //temp month year = Wire.read(); seconds = (((seconds & B11110000)>>4)*10 + (seconds & B00001111)); // convert BCD to decimal minutes = (((minutes & B11110000)>>4)*10 + (minutes & B00001111)); // convert BCD to decimal hours = (((hours & B00110000)>>4)*10 + (hours & B00001111)); // convert BCD to decimal (assume 24 hour mode) day = (day & B00000111); // 1-7 date = (((date & B00110000)>>4)*10 + (date & B00001111)); // 1-31 month = (((month & B00010000)>>4)*10 + (month & B00001111)); //msb7 is century overflow year = (((year & B11110000)>>4)*10 + (year & B00001111)); } else { //oh noes, no data! } } float get3231Temp() { //temp registers (11h-12h) get updated automatically every 64s Wire.beginTransmission(DS3231_I2C_ADDRESS); Wire.write(0x11); Wire.endTransmission(); Wire.requestFrom(DS3231_I2C_ADDRESS, 2); if(Wire.available()) { tMSB = Wire.read(); //2's complement int portion tLSB = Wire.read(); //fraction portion temp3231 = (tMSB & B01111111); //do 2's math on Tmsb temp3231 += ( (tLSB >> 6) * 0.25 ); //only care about bits 7 & 8 } else { //oh noes, no data! } return temp3231; } //ajout ds18b20 float getTemp(){ //returns the temperature from one DS18S20 in DEG Celsius byte data[12]; byte addr[8]; if ( !ds.search(addr)) { //no more sensors on chain, reset search ds.reset_search(); return -1000; } if ( OneWire::crc8( addr, 7) != addr[7]) { Serial.println("CRC is not valid!"); return -1000; } if ( addr[0] != 0x10 && addr[0] != 0x28) { Serial.print("Device is not recognized"); return -1000; } ds.reset(); ds.select(addr); ds.write(0x44,1); // start conversion, with parasite power on at the end byte present = ds.reset(); ds.select(addr); ds.write(0xBE); // Read Scratchpad for (int i = 0; i < 9; i++) { // we need 9 bytes data[i] = ds.read(); } ds.reset_search(); byte MSB = data[1]; byte LSB = data[0]; float tempRead = ((MSB << 8) | LSB); //using two's compliment float TemperatureSum = tempRead / 16; return TemperatureSum; } } boolean connectWiFi(){ //set ESP8266 mode with AT commands Serial.println("AT+CWMODE=1"); delay(2000); //build connection command String cmd="AT+CWJAP=\""; cmd+=SSID; cmd+="\",\""; cmd+=PASS; cmd+="\""; //connect to WiFi network and wait 5 seconds Serial.println(cmd); delay(5000); //if connected return true, else false if(Serial.find("OK")){Serial.println("OK WIFI"); return true; }else{ Serial.println("NO WIFI"); return false; }