Benvenuti sul Forum di AcquaPortal, la più grande community italiana di acquariofilia!
Sul Forum di AcquaPortal puoi discutere con altri appassionati di acquariofilia, tenere un tuo Blog personale, inserire foto e video, chattare, ed aiutarci a creare un grande database con schede di pesci, invertebrati e prodotti di acquariofilia.
Per entrar a far parte della comunità occorre registrarsi.
Per farlo premi su
Al momento della registrazione ti verrà richiesto di accettare il Regolamento che ti consigliamo di leggere attentamente.
Ti consigliamo inoltre di leggere le FAQ per apprendere le funzionalità principali del forum.
Se invece sei un utente registrato e hai dimenticato i tuoi dati di accesso devi effettuare il Recupero dati.
Fai da te marinoPer parlare delle tecniche di costruzione artigianale, per presentare le vostre realizzazioni, e per avere informazioni su dove reperire materiale ed attrezzatura risparmiando tempo e denaro.
void inizializza_sd()
{
sdError = 0;
msLogger = 0;
sdLogInCorso = 0;
if (!SD.begin(SD_CS)) {sdError = 1;} // memory non inerita all'accensione
else
{
sdDataFile = SD.open("logger.txt", FILE_READ);
if (sdDataFile)
{
if (sdDataFile.available())
{
if (sdDataFile.read() == 70) {sdError = 0;} // Ok il file deve iniziare con una "F"
else {sdError = 2;} // file corrotto (non inizia con la lettera giusta all'accensione
}
else {sdError = 3;} // file vuoto all'accensione
}
else {sdError = 4;} // file non esistente all'accensione
sdDataFile.close();
}
}
void logger_sd()
{
// String sdDataString = "";
if (sdLogInCorso)
{
if((msCurrent - msLogger) > 5000) // LIMITE tenere se possibile 5 secondi con 1 alle volte si una un crash
{
msLogger = msCurrent;
if (sdError) {return;}
// test se la memory funziona o se è stata rimossa durante il log
sdDataFile = SD.open("logger.txt", FILE_READ);
if (sdDataFile)
{
if (sdDataFile.available())
{
if (sdDataFile.read() == 70) {sdError = 0;} // Ok il file deve iniziare con una "F"
else {sdError = 5;} // file corrotto (non inizia con la lettera giusta) durante la scrittura
}
else {sdError = 6;} // file vuoto durante la scrittura
}
else {sdError = 7;} // file non esistente durante la scrittura
sdDataFile.close();
if (sdError != 0)
{
sdLogInCorso = 0;
return;
}
// scrittura dei file di log
// sdDataString = String(millis());
sdDataString = "";
sdDataString += "4"; // LIMITE alle volte nel log al posto della prima colonna 4 mette 111. Non si capisce cosa è 111
sdDataString += ",";
// if (rtcMonth < 10) {sdDataString += "0";}
// sdDataString += String(rtcMonth);
// if (rtcMonthDay < 10) {sdDataString += "0";}
// sdDataString += String(rtcMonthDay);
// if (rtcHour < 10) {sdDataString += "0";}
// sdDataString += String(rtcHour);
// if (rtcMinute < 10) {sdDataString += "0";}
// sdDataString += String(rtcMinute);
// if (rtcSecond < 10) {sdDataString += "0";}
// sdDataString += String(rtcSecond);
// sdDataString += " 1234567890 1234567890 1234567890"; // LIMITE tenere massimo 40 caratteri per scrittura. con più caratteri alle volte si una un crash
// sdDataString += ","; // LIMITE tenere massimo 40 caratteri per scrittura. con più caratteri alle volte si una un crash
sdDataString += String(luciCurrentBluDx);
sdDataString += ",";
sdDataString += String(luciCurrentBluSx);
sdDataString += ",";
sdDataString += String(luciCurrent10kDx);
sdDataString += ",";
sdDataString += String(luciCurrent10kSx);
sdDataString += ",";
sdDataString += String(luciCurrent20kDx);
sdDataString += ",";
sdDataString += String(luciCurrent20kSx);
// sdDataString += ",";
// sdDataString += String(luciCurrentRRGB);
// sdDataString += ",";
// sdDataString += String(luciCurrentGRGB);
// sdDataString += ",";
// sdDataString += String(luciCurrentBRGB);
sdDataFile = SD.open("logger.txt", FILE_WRITE);
sdDataFile.println(sdDataString);
sdDataFile.close();
}
}
}
void formattazione_sd()
{
sdError = 0;
SD.remove("logger.txt");
sdDataFile = SD.open("logger.txt", FILE_WRITE);
sdDataFile.println("File di LOG del controller per acquari AquaControl");
sdDataFile.close();
}
web.h
codice:
// The ethernet shield
EtherShield es = EtherShield();
#include "pagine.h"
void inizializza_sd();
void formattazione_sd();
void rtc_setDateTime();
// The returned value is stored in the global var strbuf
uint8_t find_key_val(char *str,char *key)
{
uint8_t found = 0;
uint8_t i = 0;
char *kp;
kp = key;
while(*str && *str!=' ' && found == 0)
{
if (*str == *kp)
{
kp++;
if (*kp == '\0')
{
str++;
kp = key;
if (*str == '=') {found = 1;}
}
}
else {kp = key;}
str++;
}
if (found == 1)
{
// while(*str && *str != ' ' && *str != '&' && i < STR_BUFFER_SIZE)
while(*str && *str != ' ' && *str != '&' && i < STR_BUFFER_SIZE)
{
strbuf[i] = *str;
i++;
str++;
}
strbuf[i] = '\0'
}
return(found);
}
int8_t analyse_sez(char *str)
{
int8_t r = -1;
if (find_key_val(str,"sez")) {if (*strbuf < 0x3a && *strbuf > 0x2f) {r = (*strbuf - 0x30);}}
return r;
}
int8_t analyse_cmd(char *str)
{
int8_t r = -1;
if (find_key_val(str,"cmd")) {if (*strbuf < 0x3a && *strbuf > 0x2f) {r = (*strbuf - 0x30);}}
return r;
}
int8_t analyse_act(char *str)
{
int8_t r = -1;
if (find_key_val(str,"act")) {if (*strbuf < 0x3a && *strbuf > 0x2f) {r = (*strbuf - 0x30);}}
return r;
}
void webserver()
{
uint16_t plen, dat_p;
int8_t sez;
int8_t cmd;
int8_t act;
// LIMITE ogni 30 secondi è bene resettare il webserver che impiegherà 2 secondi a ripartire (serve in caso di crash)
if((msCurrent - msResetWeb) > 30000)
{
msResetWeb = msCurrent;
es.ES_enc28j60Init(mymac);
es.ES_init_ip_arp_udp_tcp(mymac,myip, MYWWWPORT);
}
while(1) {
// read packet, handle ping and wait for a tcp packet:
dat_p = es.ES_packetloop_icmp_tcp(buf,es.ES_enc28j60PacketReceive(BUFFER_SIZE, buf));
/* dat_p will be unequal to zero if there is a valid
* http get */
if (dat_p == 0)
{
return;
}
// tcp port 80 begin
if (strncmp("GET ",(char *)&(buf[dat_p]),4) != 0)
{
// head, post and other methods:
dat_p = http200ok();
dat_p = es.ES_fill_tcp_data_p(buf,dat_p,PSTR("<h1>200 OK</h1>"));
goto SENDTCP;
}
// just one web page in the "root directory" of the web server
if (strncmp("/ ",(char *) & (buf[dat_p + 4]),2) == 0)
{
dat_p = homepage(buf);
goto SENDTCP;
}
sez = analyse_sez((char *) & (buf[dat_p+5]));
cmd = analyse_cmd((char *) & (buf[dat_p+5]));
act = analyse_act((char *) & (buf[dat_p+5]));
//***********************************************************************************************************************
//***********************************************************************************************************************
//***********************************************************************************************************************
//***********************************************************************************************************************
//***********************************************************************************************************************
if (sez == 4)
{
if ((cmd == 1) || (cmd == 2))
{
if (cmd == 1)
{
if (act == 1)
{
if (luciOraAccensione >= 23) {luciOraAccensione = 0u;}
else {luciOraAccensione++;}
EEPROM.write(INDIRIZZOLUCIORAACCENSIONE, luciOraAccensione);
}
else if (act == 2)
{
if (luciOraAccensione == 0) {luciOraAccensione = 23u;}
else {luciOraAccensione--;}
EEPROM.write(INDIRIZZOLUCIORAACCENSIONE, luciOraAccensione);
}
else if (act == 3)
{
if (luciMinutoAccensione >= 59) {luciMinutoAccensione = 0u;}
else {luciMinutoAccensione++;}
EEPROM.write(INDIRIZZOLUCIMINUTOACCENSIONE, luciMinutoAccensione);
}
else if (act == 4)
{
if (luciMinutoAccensione == 0) {luciMinutoAccensione = 59u;}
else {luciMinutoAccensione--;}
EEPROM.write(INDIRIZZOLUCIMINUTOACCENSIONE, luciMinutoAccensione);
}
else if (act == 5)
{
if (luciMinutiDurataAlba >= 54) {luciMinutiDurataAlba = 5u;}
else {luciMinutiDurataAlba++;}
EEPROM.write(INDIRIZZOLUCIMINUTIDURATAALBA, luciMinutiDurataAlba);
}
else if (act == 6)
{
if (luciMinutiDurataAlba <= 5) {luciMinutiDurataAlba = 54u;}
else {luciMinutiDurataAlba--;}
EEPROM.write(INDIRIZZOLUCIMINUTIDURATAALBA, luciMinutiDurataAlba);
}
}
else
{
if (act == 1)
{
if (luciOreAccensioneCompleta >= 16) {luciOreAccensioneCompleta = 0u;}
else {luciOreAccensioneCompleta++;}
EEPROM.write(INDIRIZZOLUCIOREACCENSIONECOMPLETA, luciOreAccensioneCompleta);
}
else if (act == 2)
{
if (luciOreAccensioneCompleta == 0) {luciOreAccensioneCompleta = 16u;}
else {luciOreAccensioneCompleta--;}
EEPROM.write(INDIRIZZOLUCIOREACCENSIONECOMPLETA, luciOreAccensioneCompleta);
}
else if (act == 3)
{
if (luciMinutiAccensioneCompleta >= 59) {luciMinutiAccensioneCompleta = 0u;}
else {luciMinutiAccensioneCompleta++;}
EEPROM.write(INDIRIZZOLUCIMINUTIACCENSIONECOMPLETA, luciMinutiAccensioneCompleta);
}
else if (act == 4)
{
if (luciMinutiAccensioneCompleta == 0) {luciMinutiAccensioneCompleta = 59u;}
else {luciMinutiAccensioneCompleta--;}
EEPROM.write(INDIRIZZOLUCIMINUTIACCENSIONECOMPLETA, luciMinutiAccensioneCompleta);
}
else if (act == 5)
{
if (luciMinutiDurataTramonto >= 54) {luciMinutiDurataTramonto = 5u;}
else {luciMinutiDurataTramonto++;}
EEPROM.write(INDIRIZZOLUCIMINUTIDURATATRAMANTO, luciMinutiDurataTramonto);
}
else if (act == 6)
{
if (luciMinutiDurataTramonto <= 5) {luciMinutiDurataTramonto = 54u;}
else {luciMinutiDurataTramonto--;}
EEPROM.write(INDIRIZZOLUCIMINUTIDURATATRAMANTO, luciMinutiDurataTramonto);
}
}
dat_p = page_fotoperiodo(buf);
}
else if ((cmd == 3) || (cmd == 4))
{
if (cmd == 3)
{
if (act == 1)
{
if (luciTargetBluSx >= 255) {luciTargetBluSx = 0u;}
else {luciTargetBluSx++;}
EEPROM.write(INDIRIZZOLUCITARGETBLUSX, luciTargetBluSx);
}
else if (act == 2)
{
if (luciTargetBluSx == 0) {luciTargetBluSx = 255u;}
else {luciTargetBluSx--;}
EEPROM.write(INDIRIZZOLUCITARGETBLUSX, luciTargetBluSx);
}
else if (act == 3)
{
if (luciTargetRRGB >= 255) {luciTargetRRGB = 0u;}
else {luciTargetRRGB++;}
EEPROM.write(INDIRIZZOLUCITARGETRRGB, luciTargetRRGB);
}
else if (act == 4)
{
if (luciTargetRRGB == 0) {luciTargetRRGB = 255u;}
else {luciTargetRRGB--;}
EEPROM.write(INDIRIZZOLUCITARGETRRGB, luciTargetRRGB);
}
else if (act == 5)
{
if (luciTargetBluDx >= 255) {luciTargetBluDx = 0u;}
else {luciTargetBluDx++;}
EEPROM.write(INDIRIZZOLUCITARGETBLUDX, luciTargetBluDx);
}
else if (act == 6)
{
if (luciTargetBluDx == 0) {luciTargetBluDx = 255u;}
else {luciTargetBluDx--;}
EEPROM.write(INDIRIZZOLUCITARGETBLUDX, luciTargetBluDx);
}
else if (act == 7)
{
if (luciTarget10kSx >= 255) {luciTarget10kSx = 0u;}
else {luciTarget10kSx++;}
EEPROM.write(INDIRIZZOLUCITARGET10KSX, luciTarget10kSx);
}
else if (act == 8)
{
if (luciTarget10kSx == 0) {luciTarget10kSx = 255u;}
else {luciTarget10kSx--;}
EEPROM.write(INDIRIZZOLUCITARGET10KSX, luciTarget10kSx);
}
else if (act == 9)
{
if (luciTargetGRGB >= 255) {luciTargetGRGB = 0u;}
else {luciTargetGRGB++;}
EEPROM.write(INDIRIZZOLUCITARGETGRGB, luciTargetGRGB);
}
}
else if (cmd == 4)
{
if (act == 1)
{
if (luciTargetGRGB == 0) {luciTargetGRGB = 255u;}
else {luciTargetGRGB--;}
EEPROM.write(INDIRIZZOLUCITARGETGRGB, luciTargetGRGB);
}
else if (act == 2)
{
if (luciTarget10kDx >= 255) {luciTarget10kDx = 0u;}
else {luciTarget10kDx++;}
EEPROM.write(INDIRIZZOLUCITARGET10KDX, luciTarget10kDx);
}
else if (act == 3)
{
if (luciTarget10kDx == 0) {luciTarget10kDx = 255u;}
else {luciTarget10kDx--;}
EEPROM.write(INDIRIZZOLUCITARGET10KDX, luciTarget10kDx);
}
else if (act == 4)
{
if (luciTarget20kSx >= 255) {luciTarget20kSx = 0u;}
else {luciTarget20kSx++;}
EEPROM.write(INDIRIZZOLUCITARGET20KSX, luciTarget20kSx);
}
else if (act == 5)
{
if (luciTarget20kSx == 0) {luciTarget20kSx = 255u;}
else {luciTarget20kSx--;}
EEPROM.write(INDIRIZZOLUCITARGET20KSX, luciTarget20kSx);
}
else if (act == 6)
{
if (luciTargetBRGB >= 255) {luciTargetBRGB = 0u;}
else {luciTargetBRGB++;}
EEPROM.write(INDIRIZZOLUCITARGETBRGB, luciTargetBRGB);
}
else if (act == 7)
{
if (luciTargetBRGB == 0) {luciTargetBRGB = 255u;}
else {luciTargetBRGB--;}
EEPROM.write(INDIRIZZOLUCITARGETBRGB, luciTargetBRGB);
}
else if (act == 8)
{
if (luciTarget20kDx >= 255) {luciTarget20kDx = 0u;}
else {luciTarget20kDx++;}
EEPROM.write(INDIRIZZOLUCITARGET20KDX, luciTarget20kDx);
}
else if (act == 9)
{
if (luciTarget20kDx == 0) {luciTarget20kDx = 255u;}
else {luciTarget20kDx--;}
EEPROM.write(INDIRIZZOLUCITARGET20KDX, luciTarget20kDx);
}
}
dat_p = page_illuminazione_potenza(buf);
}
else if (cmd == 5)
{
if (luciTipoAlbaTramonto >= 4u) {luciTipoAlbaTramonto = 0u;}
if (act == 1)
{
if (luciTipoAlbaTramonto == 0u) {luciTipoAlbaTramonto = 1u;}
else if (luciTipoAlbaTramonto == 1u) {luciTipoAlbaTramonto = 0u;}
else if (luciTipoAlbaTramonto == 2u) {luciTipoAlbaTramonto = 3u;}
else if (luciTipoAlbaTramonto == 3u) {luciTipoAlbaTramonto = 2u;}
EEPROM.write(INDIRIZZOLUCITIPOALBATRAMONTO, luciTipoAlbaTramonto);
}
else if (act == 2)
{
if (luciTipoAlbaTramonto == 0u) {luciTipoAlbaTramonto = 2u;}
else if (luciTipoAlbaTramonto == 1u) {luciTipoAlbaTramonto = 3u;}
else if (luciTipoAlbaTramonto == 2u) {luciTipoAlbaTramonto = 0u;}
else if (luciTipoAlbaTramonto == 3u) {luciTipoAlbaTramonto = 1u;}
EEPROM.write(INDIRIZZOLUCITIPOALBATRAMONTO, luciTipoAlbaTramonto);
}
else if (act == 3)
{
if (luciTargetRRGBLunare >= 255) {luciTargetRRGBLunare = 0u;}
else {luciTargetRRGBLunare++;}
EEPROM.write(INDIRIZZOLUCITARGETRRGBLUNARE, luciTargetRRGBLunare);
}
else if (act == 4)
{
if (luciTargetRRGBLunare == 0) {luciTargetRRGBLunare = 255u;}
else {luciTargetRRGBLunare--;}
EEPROM.write(INDIRIZZOLUCITARGETRRGBLUNARE, luciTargetRRGBLunare);
}
else if (act == 5)
{
if (luciTargetGRGBLunare >= 255) {luciTargetGRGBLunare = 0u;}
else {luciTargetGRGBLunare++;}
EEPROM.write(INDIRIZZOLUCITARGETGRGBLUNARE, luciTargetGRGBLunare);
}
else if (act == 6)
{
if (luciTargetGRGBLunare == 0) {luciTargetGRGBLunare = 255u;}
else {luciTargetGRGBLunare--;}
EEPROM.write(INDIRIZZOLUCITARGETGRGBLUNARE, luciTargetGRGBLunare);
}
else if (act == 7)
{
if (luciTargetBRGBLunare >= 255) {luciTargetBRGBLunare = 0u;}
else {luciTargetBRGBLunare++;}
EEPROM.write(INDIRIZZOLUCITARGETBRGBLUNARE, luciTargetBRGBLunare);
}
else if (act == 8)
{
if (luciTargetBRGBLunare == 0) {luciTargetBRGBLunare = 255u;}
else {luciTargetBRGBLunare--;}
EEPROM.write(INDIRIZZOLUCITARGETBRGBLUNARE, luciTargetBRGBLunare);
}
dat_p = page_illuminazione_effetti(buf);
}
else
{
dat_p = page_illuminazione(buf);
}
goto SENDTCP;
}
//***********************************************************************************************************************
//***********************************************************************************************************************
//***********************************************************************************************************************
//***********************************************************************************************************************
//***********************************************************************************************************************
if (sez == 8)
{
if (act == 1) {rtcHour++;}
if (rtcHour >= 24) {rtcHour = 0u;}
if (act == 2)
{
if (rtcHour == 0) {rtcHour = 23u;}
else {rtcHour--;}
}
if (act == 3) {rtcMinute++;}
if (rtcMinute >= 60) {rtcMinute = 0u;}
if (act == 4)
{
if (rtcMinute == 0) {rtcMinute = 59u;}
else {rtcMinute--;}
}
if (act == 5) {rtcMonthDay++;}
if (rtcMonthDay >= 32) {rtcMonthDay = 1u;}
if (act == 6)
{
if (rtcMonthDay <= 1) {rtcMonthDay = 31u;}
else {rtcMonthDay--;}
}
if (act == 7) {rtcMonth++;}
if (rtcMonth >= 13) {rtcMonth = 1u;}
if (act == 8) {rtcYear++;}
if (rtcYear >= 100) {rtcYear = 11u;}
if (act == 9) {rtcYear--;}
if (rtcYear <= 10) {rtcYear = 99u;}
if (act == 0) {rtcWeekDay++;}
if (rtcWeekDay >= 8) {rtcWeekDay = 1u;}
rtc_setDateTime();
dat_p = page_orologio(buf);
goto SENDTCP;
}
//***********************************************************************************************************************
//***********************************************************************************************************************
//***********************************************************************************************************************
//***********************************************************************************************************************
//***********************************************************************************************************************
if (sez == 9)
{
if ((act == 1) && (sdError == 0)) {sdLogInCorso = 1;}
if (act == 2) {sdLogInCorso = 0;}
if (act == 3)
{
inizializza_sd();
sdError = 0;
}
if (act == 4) {formattazione_sd();}
dat_p = page_logger(buf);
goto SENDTCP;
}
//***********************************************************************************************************************
//***********************************************************************************************************************
//***********************************************************************************************************************
//***********************************************************************************************************************
//***********************************************************************************************************************
SENDTCP:
es.ES_www_server_reply(buf,dat_p); // send web page data
// tcp port 80 end
}
}
void inizializza_enc28j60()
{
// Configuro l'uscita per il CS del chip
pinMode(ENC28J60_CONTROL_CS, OUTPUT);
// initialize enc28j60
es.ES_enc28j60Init(mymac);
// init the ethernet/ip layer:
es.ES_init_ip_arp_udp_tcp(mymac,myip, MYWWWPORT);
msResetWeb = 0;
}
Tramite internet si regola l'orologio, l'ora di accensione della lampada, la durata dell'alba, la durata del tramonto, il tipo di dimmerazione (blu e bianchi assieme oppure prima blu poi bianchi e sinistra e destra assieme o prima sinistra poi destra), la potenza massima di ogni uscita, il colore del led rgb di notte o di giorno ed altro.