#include #include "RTClib.h" #define transmit 2 #define Vref 5000 #define IO0 5 //MICS5525_HEATHER #define IO1 13 //MICS2710_HEATHER #define IO2 9 //MICS2710_ALTAIMPEDANCIA #define IO3 10 //RHT22 #define S0 A4 //MICS_5525 #define S1 A5 //MICS_2710 #define S2 A2 //SENS_5525 #define S3 A3 //SENS_2710 #define S4 A0 //MICRO #define S5 A1 //LDR #define AWAKE 4 //Despertar WIFI #define PANEL A8 //Entrada panel #define BAT A7 //Entrada bateria #define MICS_5525 0 #define MICS_2710 1 #define DHT22_PIN 10 RTC_DS1307 RTC; #define wiflyEnabled true #define SDEnabled false #if wiflyEnabled #include "WiFlyHTML.h" WiFlyHTML wifly; char uid[] = "Ardu"; int bid = 20; //char mySSID[] = "hangar_nau3"; //char myPassword[] = "m1cr0fug4s"; char mySSID[] = "Mi$Red"; char myPassword[] = "FINALFANTASY"; char wifiEncript[] = WPA2; char antenna[] = INT_ANT; // ANTENNA INTEGRADA #endif #if SDEnabled #include File myFile; #endif #define eeprom 0x50 // Direcion de la eeprom float TEMPvalue = 0; float HUMvalue = 0; float COvalue = 0; float NO2value = 0; float LIGHTvalue = 0; float NOISEvalue = 0; float BATvalue = 0; float PANELvalue = 0; boolean DHT22ok = false; boolean sleep = true; void updateSensors() { BATvalue = getBattery(); //% PANELvalue = getPanel(); // % } void fecha () { DateTime now = RTC.now(); Serial.print(now.year(), DEC); Serial.print('/'); Serial.print(now.month(), DEC); Serial.print('/'); Serial.print(now.day(), DEC); Serial.print(' '); Serial.print(now.hour(), DEC); Serial.print(':'); Serial.print(now.minute(), DEC); Serial.print(':'); Serial.print(now.second(), DEC); Serial.println(); } void setup() { Serial.begin(115200); Serial1.begin(9600); Wire.begin(); RTC.begin(); if (! RTC.isrunning()) { Serial.println("RTC is NOT running!"); // following line sets the RTC to the date & time this sketch was compiled RTC.adjust(DateTime(__DATE__, __TIME__)); } /*init Sensors*/ pinMode(IO0, OUTPUT); //VH_MICS5525 pinMode(IO1, OUTPUT); //VH_MICS2710 pinMode(IO2, OUTPUT); //MICS2710_ALTAIMPEDANCIA pinMode(IO3, OUTPUT); //DHT22 pinMode(AWAKE, OUTPUT); pinMode(MOSI, OUTPUT); pinMode(SCK, OUTPUT); digitalWrite(IO0, LOW); //VH_MICS5525 digitalWrite(IO1, LOW); //VH_MICS2710 digitalWrite(IO2, LOW); //RADJ_MICS2710 digitalWrite(IO3, HIGH); //DHT22 digitalWrite(AWAKE, HIGH); #if SDEnabled Serial.print("Initializing SD card..."); if (!SD.begin(11)) { Serial.println("initialization failed!"); return; } Serial.println("initialization done."); /*if (!SD.exists("config.txt")) { Serial.println("Creating config.txt..."); myFile = SD.open("config.txt", FILE_WRITE); myFile.close(); }*/ #endif /*init WiFly*/ #if wiflyEnabled digitalWrite(AWAKE, HIGH); wifly.ready(); // tiempo de espera para la conexion! //while (!wifly.join()) { // Cuidado!! Es bloqueante!! Serial.println("wifly disconnected!"); Serial.println("connecting..."); wifly.begin(mySSID, myPassword, wifiEncript, antenna); //} Serial.println("wifly connected!"); Serial.print("IP:"); Serial.println(wifly.ip()); updateSensors(); txWiFly(); #endif } void loop() { #if wiflyEnabled delay(transmit*1000); //CAMBIAR POR TEMPORIZADOR DE MILISEGUNDOS updateSensors(); txWiFly(); #endif }