seconda parte ( tagliato in due per pubblicarlo )
Wire.beginTransmission(0x68);
Wire.write(0x00); for (byte x2 = 0; x2 < 7; x2++) { Wire.write(time[x2]); } Wire.endTransmission();
case 6 : getTime(); client.print("{\"ore\":"); client.print(time[2], HEX); client.print(",\"minuti\":"); client.print(time[1], HEX); client.print(",\"secondi\":"); client.print(time[0], HEX); client.print(",\"gSettimana\":"); client.print(time[3], HEX); client.print(",\"gMese\":"); client.print(time[4], HEX); client.print(",\"mese\":"); client.print(time[5], HEX); client.print(",\"anno\":"); client.print(time[6], HEX); client.println("}"); break;
case 7 : if (get[8] >= 0 && get[8] <= 1) { x1 = get[5] * 24 + (get[6] * 10 + get[7]); crono[x1] = get[8]; EEPROM.write(x1 + 5, crono[x1]); }
case 8 : client.print("["); for (byte x2 = 0; x2 < 167; x2++) { client.print(crono[x2]); client.print(","); } client.print(crono[167]); client.println("]"); break;
case 9 : if (get[5] == 1) { if (get[6] >= 0 && get[6] <= 2) { mode = get[6]; EEPROM.write(0, mode); } }
if (get[7] == 1) { x1 = get[8] * 10 + get[9];
if (x1 >= tMin && x1 <= tMax) { tSet = x1; EEPROM.write(3, tSet); } }
default : check();
client.print("{\"temp\":"); client.print(temp); client.print(",\"tSet\":"); client.print(tSet); client.print(",\"tMin\":"); client.print(tMin); client.print(",\"tMax\":"); client.print(tMax); client.print(",\"mode\":"); client.print(mode); client.print(",\"info\":"); client.print(info); client.print("}"); } }
break; }
if (c == '\n') { currentLineIsBlank = true; }
else if (c != '\r') { currentLineIsBlank = false; } } } delay(1); client.stop(); } }
void getTemp() { byte msByte; byte lsByte;
Wire.beginTransmission(0x48); Wire.write(0xAA); Wire.endTransmission();
Wire.requestFrom(0x48, 2); if (Wire.available()) { lsByte = Wire.read(); } if (Wire.available()) { msByte = Wire.read(); } temp = float(lsByte) + float(msByte >> 3) * 0.03125; }
void getTime() {
Wire.beginTransmission(0x68); Wire.write(0x00); Wire.endTransmission();
Wire.requestFrom(0x68, 7);
for (byte x1 = 0; x1 < 7; x1++) { if (Wire.available()) { time[x1] = Wire.read(); } } }
void check() { getTemp();
switch(mode) { case 0 : digitalWrite(pinRele, LOW); info = 0; break;
case 1 : if (temp < float(tSet)) { digitalWrite(pinRele, HIGH); info = 1; }
else if (temp >= float(tSet + isteresi)) { digitalWrite(pinRele, LOW); info = 0; }
break;
case 2 : getTime(); byte x1 = (time[3] - 1) * 24 + ((time[2] >> 4) * 10) + (time[2] & 15);
if (crono[x1] != 0 && temp < float(tSet)) { digitalWrite(pinRele, HIGH); info = 1; }
else if (crono[x1] == 0 || temp >= float(tSet + isteresi)) { digitalWrite(pinRele, LOW); info = 0; } } }