Strana článku … 3/3
————————————————————————————————
Nyní se můžeme pustit do předvedení samotného zdrojového kódu. Předem se musím omluvit za mix anglického a českého okomentování, ale už nebyla chuť to přepisovat do jednoho nebo druhého. Kód by šel ještě učesat nebo rozšířit, ale pro účel který byl sestaven, je takto dostačující a zde je presentován jako případná pomůcka začínajícím.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 |
/* WebNet Climatic Regulator - Regulator prostredi. Author: BorgMcz borgm@seznam(DOT)cz Date: 1.11.2015 Version: 1.2.0 web: www.dccmm.cz Pouzite komponenty: Arduino Mega Ethernet shiel - Wiznet5100 TFT LCD 2,4" ILI 9341 8bit shield 2x DS18B20 3wire relay shield Pouzite knihovny: Webduino - More informations about Webduino can be found at https://github.com/sirleech/Webduino EEPROMAnything.h - look at http://playground.arduino.cc/Code/EEPROMWriteAnything EepromUtil - look at http://playground.arduino.cc/Code/EepromUtil OneWire - look at http://www.pjrc.com/teensy/td_libs_OneWire.html Dallas Temperature - look at https://github.com/milesburton/Arduino-Temperature-Control-Library Adafruit GFX AS - modifi version - to download from the project's site http://www.dccmm.cz CZ Adafruit TFT - to download from the project's site http://www.dccmm.cz */ /* * It's possible to configure the following network settings: * - Network setings - MAC address - IP address - Subnet - Gateway - DNS Server - Webserver port - USE DHCP YES/NO (if you use DHCP connect per serial port - 9600 baud - on powerup to see which ip address is assigned) - DHCP renew interval * - Display Arduino uptime * - Display used RAM * - System configs - Temperatur - Auto / manual regulation * - Email configs - smtp server - from email - to email * - ThingSpeak configs - enable / disable send data - API key - send time * * It is possible to connect a RESET button. If the button is pressed and the Arduino is turned on * the default values would be restored too. * See #define RESET_PIN. * * * Enter the following URL for the setup page: * http://ip saddresses/setupNet.html * * Please note that no input checks are done!! * This means that no error would be thrown if you type a wrong IP address or other failures. * Keep this in mind. * * BUGS: * - After uploading your first sketch the arduino is not reachable. --> Reset your Arduino!! */ #define version "V 1.2.0"; #define WEBDUINO_FAVICON_DATA "" // no favicon //#define DEBUGE //uncomment for serial debug network output #define USE_SYSTEM_LIBRARY //comment out if you want to save some space (about 1 Byte). You wouldn't see uptime and free RAM if it's commented out. #include <SPI.h> #include "avr/pgmspace.h" #include <Ethernet.h> #include <WebServer.h> #include <avr/wdt.h> #include <OneWire.h> #include <DallasTemperature.h> // DS18B20 support #include <EEPROM.h> // Code for the EEPROM related things #include "EEPROMAnything.h" // saved configure numbers value to eeprom #include <EepromUtil.h> // saved configure string value to eeprom #include <Adafruit_GFX_AS.h> // Core graphics library #include <CZ_Adafruit_TFTLCD.h> // Hardware-specific library unsigned int tdhcp=0; // casovani pro obnoveni dhcp unsigned int ttemp=0; // casovani pro mereni teploty unsigned int tstate=0; // casovani pro vyhodnocovani stavu unsigned int tlcd=0; // casovani pro zmeny na LCD unsigned long tlcdfull=0; // casovani pro plnou obnovu LCD (cca 30min) unsigned long tthing=0; // casovani pro zapis na server ThingSpeak unsigned long tthing_set; // casovani pro zapis na server ThingSpeak static bool zavada = false; // zavada na cidlech static bool old_zavada = true; // pro ucel LCD static bool zavadaCidlaSend = true; // zda ma byt poslan mail pri zavade static bool alarm_teplota=false; // Alarm vysoke teploty static bool old_alarm_teplota=true; // pro ucel LCD static bool alarm_teplotaSend = true; // zda ma byt poslan mail pri vysoke teplote unsigned long oldtmp; // pro mereni casu vyhodnocovani cidel (poze DEBUG static unsigned int state_regul = 10; // status regulace (10 clima, 20 ventilace, 30 stop vse) static float aThermometerIn=0.00; // vysledky mereni A static float old_A = 111.00; // pro LCD static float aThermometerOut=0.00; // vysledek mereni B static float old_B = 111.00; // pro LCD static bool old_ventilation = 1; // pro LCD static bool old_climatic = 1; // pro LCD static bool old_auto_set = 1; // pro LCD static bool fail_ether = 0; // fail status dhcp static bool fail_thing = 0; // fail status data send static bool fail_mail = 0; // fail status send mail unsigned int fail_zmena = 0; // fail status zmena old static int case_lcd = 1; // pro postupne zobrazovani zmen na LCD String str_smtp; // promena smtp serveru String str_mail_from; // promena email adresy od String str_mail_to; // promena email adresy kumu // ThingSpeak Settings char thingSpeakAddress[] = "api.thingspeak.com"; String writeAPIKey; #define RESET_PIN 40 // Connect a button to this PIN. If the button is hold, an the device is turned on the default settings are restored. #define CLIMATIC_PIN 32 // Connect to relay climatic #define VENTILATION_PIN 33 // Connect to relay ventilation #define RESET_ETH A5 // Connect to reset PIN in ethernet shield // parameter for the OneWire library #define ONE_WIRE_BUSA 22 // vnitrni cidlo #define ONE_WIRE_BUSB 23 // venkovni cidlo OneWire oneWireA(ONE_WIRE_BUSA); OneWire oneWireB(ONE_WIRE_BUSB); DallasTemperature sensorsA (&oneWireA) ; DallasTemperature sensorsB (&oneWireB) ; DeviceAddress insideThermometer, outsideThermometer; // The control pins for the LCD can be assigned to any digital or // analog pins...but we'll use the analog pins as this allows us to // double up the pins with the touch screen (see the TFT paint example). #define LCD_CS A3 // Chip Select goes to Analog 3 #define LCD_CD A2 // Command/Data goes to Analog 2 #define LCD_WR A1 // LCD Write goes to Analog 1 #define LCD_RD A0 // LCD Read goes to Analog 0 #define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin // Assign human-readable names to some common 16-bit color values: #define BLACK 0x0000 #define NAVY 0x0010 #define BLUE 0x001F #define RED 0xF800 #define GREEN 0x3666 #define CYAN 0x07FF #define MAGENTA 0xF81F #define YELLOW 0xFFE0 #define WHITE 0xFFFF Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET); /* When using the BREAKOUT BOARD only, use these 8 data lines to the LCD: // For the Arduino Uno, Duemilanove, Diecimila, etc.: // D0 connects to digital pin 8 (Notice these are // D1 connects to digital pin 9 NOT in order!) // D2 connects to digital pin 2 // D3 connects to digital pin 3 // D4 connects to digital pin 4 // D5 connects to digital pin 5 // D6 connects to digital pin 6 // D7 connects to digital pin 7 // For the Arduino Mega, use digital pins 22 through 29 // (on the 2-row header at the end of the board). */ int DEBUG = 0; // DEBUG system counter; if set to 1, will write values back via serial /* structure which is stored in the eeprom. * Look at "EEPROMAnything.h" for the functions storing and reading the struct */ struct config_t { byte config_set; byte use_dhcp; byte dhcp_refresh_minutes; byte mac[6]; byte ip[4]; byte gateway[4]; byte subnet[4]; byte dns_server[4]; unsigned int webserverPort; int climatic_temp; int ventilation_temp; int minimal_temp; int alarm_temp; byte auto_set; byte clima_set; byte ventilation_set; byte thingspeak_set; byte thingspeak_time; } eeprom_config; /** * set_EEPROM_Default() function * * The default settings. * This settings are used when no config is present or the reset button is pressed. */ void set_EEPROM_Default() { eeprom_config.config_set=1; // dont change! It's used to check if the config is already set eeprom_config.use_dhcp=0; // use DHCP per default eeprom_config.dhcp_refresh_minutes=3; // refresh the DHCP every 60 minutes // set the default MAC address. In this case its DE:AD:BE:EF:FE:ED eeprom_config.mac[0]=0xDE; eeprom_config.mac[1]=0xAD; eeprom_config.mac[2]=0xBE; eeprom_config.mac[3]=0xEF; eeprom_config.mac[4]=0xFE; eeprom_config.mac[5]=0xED; // set the default IP address for the arduino. In this case its 192.168.1.100 eeprom_config.ip[0]=192; eeprom_config.ip[1]=168; eeprom_config.ip[2]=1; eeprom_config.ip[3]=100; // set the default GATEWAY. In this case its 192.168.1.1 eeprom_config.gateway[0]=192; eeprom_config.gateway[1]=168; eeprom_config.gateway[2]=1; eeprom_config.gateway[3]=1; // set the default SUBNET. In this case its 255.255.255.0 eeprom_config.subnet[0]=255; eeprom_config.subnet[1]=255; eeprom_config.subnet[2]=255; eeprom_config.subnet[3]=0; // set the default DNS SERVER. In this case its 192.168.1.1 eeprom_config.dns_server[0]=192; eeprom_config.dns_server[1]=168; eeprom_config.dns_server[2]=1; eeprom_config.dns_server[3]=1; // set the default Webserver Port. In this case its Port 80 eeprom_config.webserverPort=80; // set the default temperature to start condicioner. In this case its 24°C eeprom_config.climatic_temp=24; // set the default temperature to start ventilation. In this case its 18°C eeprom_config.ventilation_temp=18; // set the default temperature to start ventilation. In this case its 18°C eeprom_config.minimal_temp=18; // set the default temperature to start alarm send. In this case its 26°C eeprom_config.alarm_temp=26; // set the default auto mode. In this case its 1 = Auto eeprom_config.auto_set=1; // set the default airconditioner manual status. In this case its 0 = Off eeprom_config.clima_set=1; // set the default ventilation manual status. In this case its 0 = Off eeprom_config.ventilation_set=0; // set the default smtp server. In this case its smtp.example.com str_smtp="smtp.example.com"; // set the default smtp server. In this case its smtp.example.com str_mail_from="from@email.com"; // set the default smtp server. In this case its smtp.example.com str_mail_to="to@email.com"; // set to API key to send ThingSpeak writeAPIKey="XXXXXXXXXXXXXXXX"; // set to enable/disable send to ThingSpeak eeprom_config.thingspeak_set=0; // set to time send to ThingSpeak eeprom_config.thingspeak_time=5; #ifdef DEBUGE Serial.println("Config reset"); #endif } /** * read_EEPROM_Settings function * This function is used to read the EEPROM settings at startup */ void read_EEPROM_Settings() { // read the current config EEPROM_readAnything(0, eeprom_config); if (DEBUG) { Serial.print("budu cist eeprom : "); } char char_smtp[35]; EepromUtil::eeprom_read_string(300, char_smtp, 36); if (DEBUG) { Serial.print(char_smtp); } // String str_smtp(char_smtp); str_smtp=String(char_smtp); if (DEBUG) { Serial.print(" - ve string je ted ulozeno : "); Serial.println(str_smtp); } char char_mail_from[35]; EepromUtil::eeprom_read_string(340, char_mail_from, 36); str_mail_from=String(char_mail_from); char char_mail_to[35]; EepromUtil::eeprom_read_string(380, char_mail_to, 36); str_mail_to=String(char_mail_to); char char_writeAPIKey[20]; EepromUtil::eeprom_read_string(420, char_writeAPIKey, 21); writeAPIKey=String(char_writeAPIKey); tthing_set = eeprom_config.thingspeak_time * 5700UL; // nastaveni casu zasilani thingspeak Serial.println(tthing_set); // check if config is present if (eeprom_config.config_set != 1) { // set default values set_EEPROM_Default(); // write the config to eeprom EEPROM_writeAnything(0, eeprom_config); /* convert sring STR_SMTP to char SMTP_NAME Length (with one extra character for the null terminator) */ if (DEBUG) { Serial.print("budu ukladat DEF, prevadim : "); } int str_len = str_smtp.length() + 1; // Length (with one extra character for the null terminator) char char_smtp[str_len]; // Prepare the character array (the buffer) str_smtp.toCharArray(char_smtp, str_len); // Copy it over if (DEBUG) { Serial.print("prevedeno DEF: "); Serial.print(char_smtp); } EepromUtil::eeprom_write_string(300, char_smtp); if (DEBUG) { Serial.println(" : Ulozeno "); } str_len = str_mail_from.length() + 1; char char_mail_from[str_len]; str_mail_from.toCharArray(char_mail_from, str_len); EepromUtil::eeprom_write_string(340, char_mail_from); str_len = str_mail_to.length() + 1; char char_mail_to[str_len]; str_mail_to.toCharArray(char_mail_to, str_len); EepromUtil::eeprom_write_string(380, char_mail_to); str_len = writeAPIKey.length() + 1; char char_writeAPIKey[str_len]; writeAPIKey.toCharArray(char_writeAPIKey, str_len); EepromUtil::eeprom_write_string(420, char_writeAPIKey); } } void save_default_setings_eeprom () { // check reset buton to LOW if (digitalRead(RESET_PIN) == LOW) { // set default values set_EEPROM_Default(); // write the config to eeprom EEPROM_writeAnything(0, eeprom_config); /* convert sring STR_SMTP to char SMTP_NAME Length (with one extra character for the null terminator) */ if (DEBUG) { Serial.print("budu ukladat DEF, prevadim : "); } int str_len = str_smtp.length() + 1; // Length (with one extra character for the null terminator) char char_smtp[str_len]; // Prepare the character array (the buffer) str_smtp.toCharArray(char_smtp, str_len); // Copy it over if (DEBUG) { Serial.print("prevedeno DEF: "); Serial.print(char_smtp); } EepromUtil::eeprom_write_string(300, char_smtp); if (DEBUG) { Serial.println(" : Ulozeno "); } str_len = str_mail_from.length() + 1; char char_mail_from[str_len]; str_mail_from.toCharArray(char_mail_from, str_len); EepromUtil::eeprom_write_string(340, char_mail_from); str_len = str_mail_to.length() + 1; char char_mail_to[str_len]; str_mail_to.toCharArray(char_mail_to, str_len); EepromUtil::eeprom_write_string(380, char_mail_to); str_len = writeAPIKey.length() + 1; char char_writeAPIKey[str_len]; writeAPIKey.toCharArray(char_writeAPIKey, str_len); EepromUtil::eeprom_write_string(420, char_writeAPIKey); tft.println(F(" Save default setings to eeprom.")); // print to LCD } } /** * print_EEPROM_Settings() function * * This function is used for debugging the configuration. * It prints the actual configuration to the serial port. */ #ifdef DEBUGE void print_EEPROM_Settings() { Serial.print(F("IP: ")); for(int i = 0; i<4; i++) { Serial.print(eeprom_config.ip[i]); if (i<3) { Serial.print(F(".")); } } Serial.println(); Serial.print(F("Subnet: ")); for(int i = 0; i<4; i++) { Serial.print(eeprom_config.subnet[i]); if (i<3) { Serial.print(F(".")); } } Serial.println(); Serial.print(F("Gateway: ")); for(int i = 0; i<4; i++) { Serial.print(eeprom_config.gateway[i]); if (i<3) { Serial.print(F(".")); } } Serial.println(); Serial.print(F("DNS Server: ")); for(int i = 0; i<4; i++) { Serial.print(eeprom_config.dns_server[i]); if (i<3) { Serial.print("."); } } Serial.println(); Serial.print(F("MAC: ")); for (int a=0;a<6;a++) { Serial.print(eeprom_config.mac[a],HEX); if(a<5) { Serial.print(F(":")); } } Serial.println(); Serial.print(F("Webserver Port: ")); Serial.println(eeprom_config.webserverPort); Serial.print(F("USE DHCP: ")); Serial.println(eeprom_config.use_dhcp); Serial.print(F(" DHCP renew every ")); Serial.print(eeprom_config.dhcp_refresh_minutes); Serial.println(F(" minutes")); Serial.print(F("Config Set: ")); Serial.println(eeprom_config.config_set); } #endif // ############################################################################################################################################################# /* START Network section ####################################################################################################################################### * Code for setting up network connection unsigned long last_dhcp_renew; byte dhcp_state; * renewDHCP() function * Renew the DHCP relase in a given interval. * * Overview: * - Check if interval = 0 and set it to 1 * - Check if renew interval is reached and renew the lease * void renewDHCP(int interval) { unsigned long interval_millis = interval * 60000; if (interval == 0 ) { interval = 1; } if (eeprom_config.use_dhcp==1) { if((millis() - last_dhcp_renew) > interval_millis) { last_dhcp_renew=millis(); dhcp_state = Ethernet.maintain(); } } } */ void setupNetwork() { read_EEPROM_Settings(); #ifdef DEBUGE print_EEPROM_Settings(); #endif // byte mac[] = { eeprom_config.mac[0], eeprom_config.mac[1], eeprom_config.mac[2], eeprom_config.mac[3], eeprom_config.mac[4], eeprom_config.mac[5] }; if (eeprom_config.use_dhcp != 1) { IPAddress ip(eeprom_config.ip[0], eeprom_config.ip[1], eeprom_config.ip[2], eeprom_config.ip[3]); IPAddress gateway (eeprom_config.gateway[0],eeprom_config.gateway[1],eeprom_config.gateway[2],eeprom_config.gateway[3]); IPAddress subnet (eeprom_config.subnet[0], eeprom_config.subnet[1], eeprom_config.subnet[2], eeprom_config.subnet[3]); IPAddress dns_server (eeprom_config.dns_server[0], eeprom_config.dns_server[1], eeprom_config.dns_server[2], eeprom_config.dns_server[3]); Ethernet.begin(eeprom_config.mac, ip, dns_server, gateway, subnet); tft.println(F("OK")); } else { if (Ethernet.begin(eeprom_config.mac) == 0) { Serial.print(F("Failed to configure Ethernet using DHCP")); tft.println(F("FAIL")); fail_ether = true; } else { tft.println(F("OK")); fail_ether = false; } Serial.println(Ethernet.localIP()); tft.print(F(" ")); tft.println(Ethernet.localIP()); } } // END Network section ######################################################################################################################################### #define nameMail "Regulator - " // nazev zarizeni // Ethernet client pro send mail EthernetClient client; /* This creates an instance of the webserver. By specifying a prefix * of "", all pages will be at the root of the server. */ //#define PREFIX "" //WebServer webserver(PREFIX, 80); /* WEB-Server section ####################################################################################################################################### * Webserver Code */ #ifdef USE_SYSTEM_LIBRARY #include "system.h" System sys; #endif /* Store all string in the FLASH storage to free SRAM. The P() is a function from Webduino. */ P(Page_start) = "<html><head><title>WebNet Climatic Regulator status page</title></head><body>\n"; P(Page_start_config) = "<html><head><title>Network and system config page</title></head><body>\n"; P(Page_start_reboot) = "<html><head><title>System rebooted</title></head><body>\n"; P(Page_end) = "</body></html>"; P(Page_back) = "<a href=\"index.html\"><<-BACK INDEX PAGE</a>"; P(Http400) = "HTTP 400 - BAD REQUEST"; P(Index) = "<p> </p> <br>Use the following link to setup the network and system.<br><a href=\"setupNet.html\">NEWORK AND SYSTEM SETUP->></a>"; P(align_right_start) = "<p align=\"right\">"; P(align_right_stop) = "</p>"; P(Version) = version; P(Form_eth_start) = "<FORM action=\"setupNet.html\" method=\"get\">"; P(Form_end) = "<FORM>"; P(Form_input_send) = "<b><INPUT type=\"submit\" value=\" Save config \"></b >"; P(Form_input_text_start) = "<input type=\"text\" name=\""; P(Form_input_value) = "\" value=\""; P(Form_input_size2) = "\" maxlength=\"2\" size=\"2"; P(Form_input_size3) = "\" maxlength=\"3\" size=\"3"; P(Form_input_size35) = "\" maxlength=\"35\" size=\"35"; P(Form_input_size20) = "\" maxlength=\"20\" size=\"20"; P(Form_input_end) = "\">\n"; P(EepromConfig) = "Config in EEPROM"; P(CurrentConfig) = " Actual config IP"; P(MAC) = "MAC address: "; P(IP) = "IP address: "; P(SUBNET) = "Subnet: "; P(GW) = "GW address: "; P(DNS_SERVER) = "DNS server: "; P(WEB_PORT) = "Webserver port (1-65535): "; P(DHCP_ACTIVE) = "Use DHCP: "; P(DHCP_REFRESH) = "Renew interval for DHCP in minutes (1 - 255): "; P(use_dhcp_print) = "<i>IP from the DHCP</i>"; P(use_ip_static) = "<i>IP is static</i>"; P(i_start) = "<i>"; P(i_stop) = "</i>"; P(range_tt) = "<i>1..60 min</i>"; P(only_manual) = "<i>Only in manual mode.</i>"; P(range_temp) = "<i>-40..80 C</i>"; P(clima_temp_start) = "Climatic temp.: "; P(ventilation_temp_start) = "Ventilation temp.: "; P(minimal_temp_start) = "Minimal indoor temp.: "; P(alarm_temp_start) = "Alarm temperatur: "; P(Auto_mode_ACTIVE) = "Automatic mode: "; P(clima_mode_ACTIVE) = "Manual climatic: "; P(thingspeak_enable) = "ThingSpeak data send: "; P(thingspeak_key) = "ThingSpeak write API Key: "; P(thingspeak_timeset) = "Send time: "; P(ventilation_mode_ACTIVE) = "Manual ventilation: "; P(Bold_config) = "<b>Network config: </b>"; P(Bold_config2) = "<b>System config: </b>"; P(Bold_config3) = "<b>E-mail config: </b>"; P(Bold_config4) = "<b>ThingSpeak config: </b>"; P(smtp) = "SMTP server: "; P(climatic_ventilation) = "<tr><td width=\"120\" align=\"center\"> CLIMATIC </td><td width=\"120\" align=\"center\">VENTILATION</td></tr>"; P(ON) = "<td width=\"120\" align=\"center\" bgcolor=\"#009900\"><b><br> ON <br><br></b></td>"; P(OFF) = "<td width=\"120\" align=\"center\" bgcolor=\"#FF0000\"><b><br> OFF <br><br></b></td>"; P(td_marge_start) = "<td align=\"center\" colspan=\"2\">"; P(mode_auto) = "<b>MODE AUTO</b>"; P(mode_manual) = "<font color=\"#FF0000\"><b>MANUAL MODE</b></font>"; P(zavada_cidel) = "<br><font color=\"#FF0000\"><b>TEMPERATURE SENSOR FAULT!</b></font>"; P(vysoka_teplota) = "<br><font color=\"#FF0000\"><b>HIGH TEMPERATURE INDOOR!</b></font>"; P(Form_cb) = "<input type=\"radio\" name=\"23\" value=\""; P(Form_cb29) = "<input type=\"radio\" name=\"29\" value=\""; P(Form_cb30) = "<input type=\"radio\" name=\"30\" value=\""; P(Form_cb31) = "<input type=\"radio\" name=\"31\" value=\""; P(Form_cb35) = "<input type=\"radio\" name=\"35\" value=\""; P(Form_cb_checked) = " checked "; P(Form_cb_on) = ">On"; P(Form_cb_off) = ">Off"; P(br) = "<br>\n"; P(br2) = "<br> <br> <br>"; P(mezera) = " "; P(table_start) = "<table>"; P(table_tr_start) = "<tr>"; P(table_tr_end) = "</tr>"; P(table_td_start) = "<td>"; P(table_td_end) = "</td>"; P(table_end) = "</table>"; P(Config_set) = "<font size=\"5\" color=\"red\">New configuration stored! <br>Changing the network configuration will take effect after a REBOOT system!</font><br>"; P(status_index) = "<h1>On-Line System Status<br><font size=\"3\">WebNet Climatic Regulator</font></h1>"; P(status_tin) = "Indoor temperature: "; P(status_tout) = "Outdoor temperature: "; P(celsius) = " (C)"; P(mail_from) = "E-mail From:"; P(mail_to) = "E-mail To:"; P(status_index_reboot) = "<br><h1>System rebooted ..... </h1>"; P(message_reboot) = "NO REFRESH PAGE!!<br>Connect to index page."; P(link_reboot) = "<br> <br>Use the following link to reboot device.<br> <a href=\"reboot.html\">..::SYSTEM REBOOT::..</a>"; P(UPTIME) = "Uptime: "; #ifdef USE_SYSTEM_LIBRARY P(RAM_1) = "RAM (byte): "; P(RAM_2) = " free of "; #endif /* This creates an pointer to instance of the webserver. */ WebServer * webserver; /** * indexHTML() function * This function is used to send the index.html to the client. */ void indexHTML(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete) { /* this line sends the standard "we're all OK" headers back to the browser */ server.httpSuccess(); /* if we're handling a GET or POST, we can output our data here. For a HEAD request, we just stop after outputting headers. */ if (type == WebServer::HEAD) return; server.printP(Page_start); server.printP(status_index); server.printP(table_start); server.printP(table_td_start); server.printP(Version); server.printP(table_td_end); server.printP(table_td_start); server.printP(align_right_start); server.print(sys.uptime()); server.printP(align_right_stop); server.printP(table_td_end); server.printP(table_tr_end); server.printP(table_tr_start); server.printP(table_td_start); server.printP(mezera); server.printP(table_td_end); server.printP(table_td_start); server.printP(table_td_end); server.printP(table_tr_end); // aktualni vnitrni teplota server.printP(table_tr_start); server.printP(table_td_start); server.printP(status_tin); server.printP(table_td_end); server.printP(table_td_start); server.print(aThermometerIn); server.printP(celsius); server.printP(table_td_end); server.printP(table_tr_end); // aktualni venkovni teplota server.printP(table_tr_start); server.printP(table_td_start); server.printP(status_tout); server.printP(table_td_end); server.printP(table_td_start); server.print(aThermometerOut); server.printP(celsius); server.printP(table_td_end); server.printP(table_tr_end); server.printP(table_end); server.printP(br); server.printP(table_start); server.printP(table_tr_start); server.printP(td_marge_start); if (eeprom_config.auto_set==1) { server.printP(mode_auto); } else { server.printP(mode_manual); } server.printP(table_td_end); server.printP(table_tr_end); server.printP(climatic_ventilation); server.printP(table_tr_start); if (digitalRead(CLIMATIC_PIN)==HIGH) { server.printP(ON); } else { server.printP(OFF); } if (digitalRead(VENTILATION_PIN)==HIGH) { server.printP(ON); } else { server.printP(OFF); } server.printP(table_tr_end); server.printP(table_tr_start); server.printP(td_marge_start); server.printP(table_td_end); server.printP(table_tr_end); server.printP(table_end); server.printP(br); server.printP(Index); server.printP(link_reboot); // odkaz na stranku s rebootem server.printP(Page_end); } /** * setupNetHTML() function * This function is used to send the setupNet.html to the client. * * Overview: * - Send a HTTP 200 OK Header * - If get parameters exists assign them to the corresponding variable in the eeprom_config struct * - Print the configuration * * Parameters are simple numbers. The name of the parameter is converted to an int with the atoi function. * This saves some code for setting the MAC and IP addresses. //#define NAMELEN 5 //#define VALUELEN 7 void setupNetHTML(WebServer &server, WebServer::ConnectionType type, char *, bool) { if (server.checkCredentials("YWRtaW46YWRtaW4=")) { */ #define NAMELEN 5 #define VALUELEN 36 void setupNetHTML(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete) { if (server.checkCredentials("YWRtaW46YWRtaW4=")) /* see "http://base64-encoder-online.waraxe.us/ default admin:admin YWRtaW46YWRtaW4= */ { URLPARAM_RESULT rc; char name[NAMELEN]; char value[VALUELEN]; boolean params_present = false; byte param_number = 0; /* this line sends the standard "we're all OK" headers back to the browser */ server.httpSuccess(); /* if we're handling a GET or POST, we can output our data here. For a HEAD request, we just stop after outputting headers. */ if (type == WebServer::HEAD) return; server.printP(Page_start_config); // check for parameters if (strlen(url_tail)) { while (strlen(url_tail)) { rc = server.nextURLparam(&url_tail, name, NAMELEN, value, VALUELEN); if (rc != URLPARAM_EOS) { params_present=true; // debug output for parameters #ifdef DEBUGE Serial.print(name); server.print(name); Serial.print(F(" - ")); server.print(F(" - ")); Serial.println(value); server.print(value); server.print(F("<br>")); #endif param_number = atoi(name); // read MAC address if (param_number >=0 && param_number <=5) { eeprom_config.mac[param_number]=strtol(value,NULL,16); } // read IP address if (param_number >=6 && param_number <=9) { eeprom_config.ip[param_number-6]=atoi(value); } // read SUBNET if (param_number >=10 && param_number <=13) { eeprom_config.subnet[param_number-10]=atoi(value); } // read GATEWAY if (param_number >=14 && param_number <=17) { eeprom_config.gateway[param_number-14]=atoi(value); } // read DNS-SERVER if (param_number >=18 && param_number <=21) { eeprom_config.dns_server[param_number-18]=atoi(value); } // read WEBServer port if (param_number == 22) { eeprom_config.webserverPort=atoi(value); } // read DHCP ON/OFF if (param_number == 23) { eeprom_config.use_dhcp=atoi(value); } // read DHCP renew interval if (param_number == 24) { eeprom_config.dhcp_refresh_minutes=atoi(value); } // read internal temp if (param_number == 25) { eeprom_config.climatic_temp=atoi(value); } // read outdoor temp if (param_number == 26) { eeprom_config.ventilation_temp=atoi(value); } // read outdoor temp if (param_number == 27) { eeprom_config.minimal_temp=atoi(value); } // read alarm temp if (param_number == 28) { eeprom_config.alarm_temp=atoi(value); } // read auto mod set if (param_number == 29) { eeprom_config.auto_set=atoi(value); } // read manual climatic if (param_number == 30) { eeprom_config.clima_set=atoi(value); } // read manual ventilation if (param_number == 31) { eeprom_config.ventilation_set=atoi(value); } // read smtp server if (param_number == 32) { str_smtp = value; } // read mail from if (param_number == 33) { str_mail_from = value; } // read mail to if (param_number == 34) { str_mail_to = value; } // read eneble/disable send ThingSpeak if (param_number == 35) { eeprom_config.thingspeak_set=atoi(value); } // read API Key to ThingSpeak if (param_number == 36) { writeAPIKey = value; } // read time to send ThingSpeak if (param_number == 37) { eeprom_config.thingspeak_time=atoi(value); } } } EEPROM_writeAnything(0, eeprom_config); /* convert sring STR_SMTP to char SMTP_NAME Length (with one extra character for the null terminator) */ if (DEBUG) { Serial.print("budu prekladat : "); Serial.print(str_smtp); } int str_len = str_smtp.length() + 1; // Length (with one extra character for the null terminator) char char_smtp[str_len]; // Prepare the character array (the buffer) str_smtp.toCharArray(char_smtp, str_len); // Copy it over if (DEBUG) { Serial.print(" : prevedeno : "); Serial.print(char_smtp); Serial.print(" : budu ukladat : "); } EepromUtil::eeprom_write_string(300, char_smtp); // ulozeni promene str_smtp do eeprom (36pozic) if (DEBUG) { Serial.println("ulozeno "); } str_len = str_mail_from.length() + 1; char char_mail_from[str_len]; str_mail_from.toCharArray(char_mail_from, str_len); EepromUtil::eeprom_write_string(340, char_mail_from); str_len = str_mail_to.length() + 1; char char_mail_to[str_len]; str_mail_to.toCharArray(char_mail_to, str_len); EepromUtil::eeprom_write_string(380, char_mail_to); str_len = writeAPIKey.length() + 1; char char_writeAPIKey[str_len]; writeAPIKey.toCharArray(char_writeAPIKey, str_len); EepromUtil::eeprom_write_string(420, char_writeAPIKey); tthing=0; // mazani pri ulozeni (restart casu) tthing_set = eeprom_config.thingspeak_time * 5700UL; } //print the form server.printP(Form_eth_start); if(params_present==true) { server.printP(Config_set); } server.printP(table_start); #ifdef USE_SYSTEM_LIBRARY //print uptime server.printP(table_tr_start); server.printP(table_td_start); server.printP(UPTIME); server.printP(table_td_end); server.printP(table_td_start); server.print(sys.uptime()); server.printP(table_td_end); server.printP(table_td_start); server.printP(Page_back); server.printP(table_td_end); server.printP(table_tr_end); server.printP(table_tr_start); server.printP(table_td_start); server.printP(RAM_1); server.print(sys.ramFree()); server.printP(RAM_2); server.print(sys.ramSize()); server.printP(table_td_end); server.printP(table_td_start); server.printP(table_td_end); server.printP(table_td_start); server.printP(table_td_end); server.printP(table_tr_end); server.printP(table_tr_start); server.printP(table_td_start); server.printP(mezera); server.printP(table_td_end); server.printP(table_td_start); server.printP(table_td_end); server.printP(table_td_start); server.printP(table_td_end); server.printP(table_tr_end); #endif // print info text server.printP(table_tr_start); server.printP(table_td_start); server.printP(Bold_config); server.printP(table_td_end); server.printP(table_td_start); server.printP(EepromConfig); server.printP(table_td_end); server.printP(table_td_start); server.printP(CurrentConfig); server.printP(table_td_end); server.printP(table_tr_end); // print the current MAC server.printP(table_tr_start); server.printP(table_td_start); server.printP(MAC); server.printP(table_td_end); server.printP(table_td_start); for (int a=0;a<6;a++) { server.printP(Form_input_text_start); server.print(a); server.printP(Form_input_value); server.print(eeprom_config.mac[a],HEX); server.printP(Form_input_size2); server.printP(Form_input_end); } server.printP(table_td_end); server.printP(table_td_start); // server.print(eeprom_config.mac); server.printP(table_td_end); server.printP(table_tr_end); // print the current IP server.printP(table_tr_start); server.printP(table_td_start); server.printP(IP); server.printP(table_td_end); server.printP(table_td_start); for (int a=0;a<4;a++) { server.printP(Form_input_text_start); server.print(a+6); server.printP(Form_input_value); server.print(eeprom_config.ip[a]); server.printP(Form_input_size3); server.printP(Form_input_end); } server.printP(table_td_end); server.printP(table_td_start); // print the value of each byte of the IP address: server.printP(i_start); server.print(Ethernet.localIP()); server.printP(i_stop); server.printP(table_td_end); server.printP(table_tr_end); // print the current SUBNET server.printP(table_tr_start); server.printP(table_td_start); server.printP(SUBNET); server.printP(table_td_end); server.printP(table_td_start); for (int a=0;a<4;a++) { server.printP(Form_input_text_start); server.print(a+10); server.printP(Form_input_value); server.print(eeprom_config.subnet[a]); server.printP(Form_input_size3); server.printP(Form_input_end); } server.printP(table_td_end); server.printP(table_td_start); server.printP(i_start); server.print(Ethernet.subnetMask()); server.printP(i_stop); server.printP(table_td_end); server.printP(table_tr_end); // print the current GATEWAY server.printP(table_tr_start); server.printP(table_td_start); server.printP(GW); server.printP(table_td_end); server.printP(table_td_start); for (int a=0;a<4;a++) { server.printP(Form_input_text_start); server.print(a+14); server.printP(Form_input_value); server.print(eeprom_config.gateway[a]); server.printP(Form_input_size3); server.printP(Form_input_end); } server.printP(table_td_end); server.printP(table_td_start); server.print(" "); server.printP(i_start); server.print(Ethernet.gatewayIP()); server.printP(i_stop); server.printP(table_td_end); server.printP(table_tr_end); // print the current DNS-SERVER server.printP(table_tr_start); server.printP(table_td_start); server.printP(DNS_SERVER); server.printP(table_td_end); server.printP(table_td_start); for (int a=0;a<4;a++) { server.printP(Form_input_text_start); server.print(a+18); server.printP(Form_input_value); server.print(eeprom_config.dns_server[a]); server.printP(Form_input_size3); server.printP(Form_input_end); } server.printP(table_td_end); server.printP(table_td_start); server.printP(i_start); server.print(Ethernet.dnsServerIP()); server.printP(i_stop); server.printP(table_td_end); server.printP(table_tr_end); // print the current webserver port server.printP(table_tr_start); server.printP(table_td_start); server.printP(WEB_PORT); server.printP(table_td_end); server.printP(table_td_start); server.printP(Form_input_text_start); server.print(22); server.printP(Form_input_value); server.print(eeprom_config.webserverPort); server.printP(Form_input_end); server.printP(table_td_end); server.printP(table_td_start); server.printP(table_td_end); server.printP(table_tr_end); //print the current DHCP config server.printP(table_tr_start); server.printP(table_td_start); server.printP(DHCP_ACTIVE); server.printP(table_td_end); server.printP(table_td_start); server.printP(Form_cb); server.print("0\""); if(eeprom_config.use_dhcp != 1) { server.printP(Form_cb_checked); } server.printP(Form_cb_off); server.printP(Form_cb); server.print("1\""); if(eeprom_config.use_dhcp == 1) { server.printP(Form_cb_checked); } server.printP(Form_cb_on); server.printP(table_td_end); server.printP(table_td_start); if(eeprom_config.use_dhcp == 1) { server.printP(use_dhcp_print); } else { server.printP(use_ip_static); } server.printP(table_td_end); server.printP(table_tr_end); // print info free server.printP(table_tr_start); server.printP(table_td_start); server.print(" "); // volny radek server.printP(table_td_end); server.printP(table_td_start); server.printP(table_td_end); server.printP(table_td_start); server.printP(table_td_end); server.printP(table_tr_end); // print info text server.printP(table_tr_start); server.printP(table_td_start); server.printP(Bold_config2); // volny radek server.printP(table_td_end); server.printP(table_td_start); server.printP(table_td_end); server.printP(table_td_start); server.printP(table_td_end); server.printP(table_tr_end); //print the clima start temperatur server.printP(table_tr_start); server.printP(table_td_start); server.printP(clima_temp_start); server.printP(table_td_end); server.printP(table_td_start); server.printP(Form_input_text_start); server.print(25); server.printP(Form_input_value); server.print(eeprom_config.climatic_temp); server.printP(Form_input_size3); server.printP(Form_input_end); server.print("C"); server.printP(table_td_end); server.printP(table_td_start); server.printP(range_temp); server.printP(table_td_end); server.printP(table_tr_end); //print the ventilation start temperatur server.printP(table_tr_start); server.printP(table_td_start); server.printP(ventilation_temp_start); server.printP(table_td_end); server.printP(table_td_start); server.printP(Form_input_text_start); server.print(26); server.printP(Form_input_value); server.print(eeprom_config.ventilation_temp); server.printP(Form_input_size3); server.printP(Form_input_end); server.print("C"); server.printP(table_td_end); server.printP(table_td_start); server.printP(range_temp); server.printP(table_td_end); server.printP(table_tr_end); //print the ventilation and climatic stop temperatur server.printP(table_tr_start); server.printP(table_td_start); server.printP(minimal_temp_start); server.printP(table_td_end); server.printP(table_td_start); server.printP(Form_input_text_start); server.print(27); server.printP(Form_input_value); server.print(eeprom_config.minimal_temp); server.printP(Form_input_size3); server.printP(Form_input_end); server.print("C"); server.printP(table_td_end); server.printP(table_td_start); server.printP(range_temp); server.printP(table_td_end); server.printP(table_tr_end); //print the alarm temperatur server.printP(table_tr_start); server.printP(table_td_start); server.printP(alarm_temp_start); server.printP(table_td_end); server.printP(table_td_start); server.printP(Form_input_text_start); server.print(28); server.printP(Form_input_value); server.print(eeprom_config.alarm_temp); server.printP(Form_input_size3); server.printP(Form_input_end); // server.print((char)176); server.print("C"); server.printP(table_td_end); server.printP(table_td_start); server.printP(range_temp); server.printP(table_td_end); server.printP(table_tr_end); //print the current auto mode server.printP(table_tr_start); server.printP(table_td_start); server.printP(Auto_mode_ACTIVE); server.printP(table_td_end); server.printP(table_td_start); server.printP(Form_cb29); server.print("0\""); if(eeprom_config.auto_set != 1) { server.printP(Form_cb_checked); } server.printP(Form_cb_off); server.printP(Form_cb29); server.print("1\""); if(eeprom_config.auto_set == 1) { server.printP(Form_cb_checked); } server.printP(Form_cb_on); server.printP(table_td_end); server.printP(table_td_start); server.printP(table_td_end); server.printP(table_tr_end); //print the current climatic set server.printP(table_tr_start); server.printP(table_td_start); server.printP(clima_mode_ACTIVE); server.printP(table_td_end); server.printP(table_td_start); server.printP(Form_cb30); server.print("0\""); if(eeprom_config.clima_set != 1) { server.printP(Form_cb_checked); } server.printP(Form_cb_off); server.printP(Form_cb30); server.print("1\""); if(eeprom_config.clima_set == 1) { server.printP(Form_cb_checked); } server.printP(Form_cb_on); server.printP(table_td_end); server.printP(table_td_start); server.printP(only_manual); server.printP(table_td_end); server.printP(table_tr_end); //print the current ventilation set server.printP(table_tr_start); server.printP(table_td_start); server.printP(ventilation_mode_ACTIVE); server.printP(table_td_end); server.printP(table_td_start); server.printP(Form_cb31); server.print("0\""); if(eeprom_config.ventilation_set != 1) { server.printP(Form_cb_checked); } server.printP(Form_cb_off); server.printP(Form_cb31); server.print("1\""); if(eeprom_config.ventilation_set == 1) { server.printP(Form_cb_checked); } server.printP(Form_cb_on); server.printP(table_td_end); server.printP(table_td_start); server.printP(only_manual); server.printP(table_td_end); server.printP(table_tr_end); // print info free server.printP(table_tr_start); server.printP(table_td_start); server.print(" "); // volny radek server.printP(table_td_end); server.printP(table_td_start); server.printP(table_td_end); server.printP(table_td_start); server.printP(table_td_end); server.printP(table_tr_end); // print info text server.printP(table_tr_start); server.printP(table_td_start); server.printP(Bold_config3); // volny radek server.printP(table_td_end); server.printP(table_td_start); server.printP(table_td_end); server.printP(table_td_start); server.printP(table_td_end); server.printP(table_tr_end); //print the current smtp server set server.printP(table_tr_start); server.printP(table_td_start); server.printP(smtp); server.printP(table_td_end); server.printP(table_td_start); server.printP(Form_input_text_start); server.print(32); server.printP(Form_input_value); server.print(str_smtp); server.printP(Form_input_size35); server.printP(Form_input_end); server.printP(table_td_end); server.printP(table_td_start); server.printP(table_td_end); server.printP(table_tr_end); //print the current mail From: set server.printP(table_tr_start); server.printP(table_td_start); server.printP(mail_from); server.printP(table_td_end); server.printP(table_td_start); server.printP(Form_input_text_start); server.print(33); server.printP(Form_input_value); server.print(str_mail_from); server.printP(Form_input_size35); server.printP(Form_input_end); server.printP(table_td_end); server.printP(table_td_start); server.printP(table_td_end); server.printP(table_tr_end); //print the current mail To: set server.printP(table_tr_start); server.printP(table_td_start); server.printP(mail_to); server.printP(table_td_end); server.printP(table_td_start); server.printP(Form_input_text_start); server.print(34); server.printP(Form_input_value); server.print(str_mail_to); server.printP(Form_input_size35); server.printP(Form_input_end); server.printP(table_td_end); server.printP(table_td_start); server.printP(table_td_end); server.printP(table_tr_end); /* //print DHCP status if(eeprom_config.use_dhcp == 1) { server.printP(table_tr_start); server.printP(table_td_start); server.printP(DHCP_STATE); server.printP(table_td_end); server.printP(table_td_start); server.print(dhcp_state); server.printP(table_td_end); server.printP(table_tr_end); server.printP(table_tr_start); server.printP(table_td_start); server.printP(DHCP_STATE_TIME); server.printP(table_td_end); server.printP(table_td_start); server.print(last_dhcp_renew/1000); server.printP(table_td_end); server.printP(table_td_start); server.printP(table_td_end); server.printP(table_tr_end); } */ // ThingSpeak config // print info free server.printP(table_tr_start); server.printP(table_td_start); server.print(" "); // volny radek server.printP(table_td_end); server.printP(table_td_start); server.printP(table_td_end); server.printP(table_td_start); server.printP(table_td_end); server.printP(table_tr_end); // print info text server.printP(table_tr_start); server.printP(table_td_start); server.printP(Bold_config4); // volny radek server.printP(table_td_end); server.printP(table_td_start); server.printP(table_td_end); server.printP(table_td_start); server.printP(table_td_end); server.printP(table_tr_end); //print the current enable / disable data sent to ThingSpeak server.printP(table_tr_start); server.printP(table_td_start); server.printP(thingspeak_enable); server.printP(table_td_end); server.printP(table_td_start); server.printP(Form_cb35); server.print("0\""); if(eeprom_config.thingspeak_set != 1) { server.printP(Form_cb_checked); } server.printP(Form_cb_off); server.printP(Form_cb35); server.print("1\""); if(eeprom_config.thingspeak_set == 1) { server.printP(Form_cb_checked); } server.printP(Form_cb_on); server.printP(table_td_end); server.printP(table_td_start); server.printP(table_td_end); server.printP(table_tr_end); //print the current ThingSpeak API key server.printP(table_tr_start); server.printP(table_td_start); server.printP(thingspeak_key); server.printP(table_td_end); server.printP(table_td_start); server.printP(Form_input_text_start); server.print(36); server.printP(Form_input_value); server.print(writeAPIKey); server.printP(Form_input_size20); server.printP(Form_input_end); server.printP(table_td_end); server.printP(table_td_start); server.printP(table_td_end); server.printP(table_tr_end); //print the ventilation start temperatur server.printP(table_tr_start); server.printP(table_td_start); server.printP(thingspeak_timeset); server.printP(table_td_end); server.printP(table_td_start); server.printP(Form_input_text_start); server.print(37); server.printP(Form_input_value); server.print(eeprom_config.thingspeak_time); server.printP(Form_input_size2); server.printP(Form_input_end); server.print("min"); server.printP(table_td_end); server.printP(table_td_start); server.printP(range_tt); server.printP(table_td_end); server.printP(table_tr_end); // end and send button server.printP(table_tr_start); server.printP(table_td_start); server.printP(table_td_end); server.printP(table_td_start); server.printP(table_td_end); server.printP(table_td_start); server.printP(table_td_end); server.printP(table_tr_end); server.printP(table_tr_start); server.printP(table_td_start); server.printP(table_td_end); server.printP(table_td_start); server.printP(Form_input_send); server.printP(table_td_end); server.printP(table_td_start); server.printP(table_td_end); server.printP(table_tr_end); server.printP(table_end); //print the send button // server.printP(Form_input_send); server.printP(Form_end); server.printP(link_reboot); server.printP(br2); server.printP(Page_back); server.printP(Page_end); } else { /* send a 401 error back causing the web browser to prompt the user for credentials */ server.httpUnauthorized(); } } /** * rebootHTML() function * This function is rebooted this device.. */ void rebootHTML(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete) { if (server.checkCredentials("YWRtaW46YWRtaW4=")) /* see "http://base64-encoder-online.waraxe.us/ default admin:admin YWRtaW46YWRtaW4= */ { server.httpSuccess(); if (type != WebServer::HEAD) { server.printP(Page_start); server.printP(status_index_reboot); server.printP(br); server.printP(message_reboot); server.printP(Page_back); server.printP(Page_end); delay(100); wdt_disable(); wdt_enable(WDTO_1S); } } else { /* send a 401 error back causing the web browser to prompt the user for credentials */ server.httpUnauthorized(); } } /** * errorHTML() function * This function is called whenever a non extisting page is called. * It sends a HTTP 400 Bad Request header and the same as text. */ void errorHTML(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete) { /* this line sends the standard "HTTP 400 Bad Request" headers back to the browser */ server.httpFail(); /* if we're handling a GET or POST, we can output our data here. For a HEAD request, we just stop after outputting headers. */ if (type == WebServer::HEAD) return; server.printP(Http400); server.printP(Page_end); } // END WEBCODE ###################################################################################################################################################### // Setup runs once at power on or reset void setup(void){ wdt_disable(); Serial.begin(9600); Serial.println(F("TFT LCD START")); pinMode(RESET_PIN, INPUT); // defaul setings pins (reset config) digitalWrite(RESET_PIN, HIGH); pinMode(RESET_ETH, OUTPUT); digitalWrite(RESET_ETH, LOW); // set reset ETH shield pinMode(CLIMATIC_PIN, OUTPUT); digitalWrite(CLIMATIC_PIN, LOW); // set stop Climatic pinMode(VENTILATION_PIN, OUTPUT); digitalWrite(VENTILATION_PIN, LOW); // set stop Ventilation tft.reset(); uint16_t identifier = tft.readID(); if(identifier == 0x9325) { Serial.println(F("Found ILI9325 LCD driver")); } else if(identifier == 0x9327) { Serial.println(F("Found ILI9327 LCD driver")); } else if(identifier == 0x9328) { Serial.println(F("Found ILI9328 LCD driver")); } else if(identifier == 0x7575) { Serial.println(F("Found HX8347G LCD driver")); } else if(identifier == 0x9341) { Serial.println(F("Found ILI9341 LCD driver")); } else if(identifier == 0x8357) { Serial.println(F("Found HX8357D LCD driver")); } else if(identifier == 0x0154) { Serial.println(F("Found S6D0154 LCD driver")); } else if(identifier == 0x9488) { Serial.println(F("Found ILI9488 LCD driver")); } else { Serial.print(F("Unknown LCD driver chip: ")); Serial.println(identifier, HEX); return; } tft.begin(identifier); tft.setRotation(0); tft.fillScreen(WHITE); tft.setTextSize(1); // print to LCD tft.setTextColor(BLUE); tft.println(F(" ")); tft.println(F(" System starting ....")); delay(200); save_default_setings_eeprom (); // test activate reset pin delay(200); digitalWrite(RESET_ETH, HIGH); // set no reset ETH shield delay(200); /* initialize the Ethernet adapter with the settings from eeprom */ tft.print(F(" Network starting ....")); setupNetwork(); delay(200); // some time to settle tft.print(F(" Webserver starting ....")); #define PREFIX "" webserver = new WebServer(PREFIX, eeprom_config.webserverPort); /* setup our default command that will be run when the user accesses * the root page on the server */ webserver->setDefaultCommand(&indexHTML); /* setup our default command that will be run when the user accesses * a page NOT on the server */ webserver->setFailureCommand(&errorHTML); /* run the same command if you try to load /index.html, a common * default page name */ webserver->addCommand("index.html", &indexHTML); /* display a network setup form. The configuration is stored in eeprom */ webserver->addCommand("setupNet.html", &setupNetHTML); /* display a rebbot this device */ webserver->addCommand("reboot.html", &rebootHTML); /* start the webserver */ webserver->begin(); tft.println(F("OK")); tft.print(F(" Sensor starting ....")); // setup OneWire bus sensorsA.begin(); sensorsB.begin(); // zjisti ID cidel teploty oneWireA.reset_search(); if (!oneWireA.search(insideThermometer)){ Serial.println(F("Vnitrni teplomer nenalezen!")); tft.print(F("A-FAIL, ")); } else { tft.print(F("A-OK, ")); } oneWireB.reset_search(); if (!oneWireB.search(outsideThermometer)){ Serial.println(F("Vnejsi teplomer nenalezen!")); tft.println(F("B-FAIL")); } else { tft.println(F("B-OK")); } Serial.print(F("Adresa teplomeru 1: ")); printAddress(insideThermometer); Serial.println(); Serial.print(F("Adresa teplomeru 2: ")); printAddress(outsideThermometer); Serial.println(); sensorsA.setResolution(insideThermometer,11); // nastavuje rozliseni sensorsB.setResolution(outsideThermometer,11); sensorsA.setWaitForConversion(0); // zakazuje cekani na dokonceni converze teploty sensorsB.setWaitForConversion(0); if (!DEBUG) email("RESTART", "System byl restartovan.", false); tft.println(F(" .... start complete.")); delay(3000); lcd_background (); } // End of Setup void loop() { char buff[372]; int len = 372; /* process incoming connections one at a time forever */ webserver->processConnection(buff, &len); delay (10); // zapis na server ThingSpeak (10min) 57 000 if (tthing == tthing_set){ tthing=0; if (eeprom_config.thingspeak_set == 1){ updateThingSpeak("field1="+String(aThermometerIn, DEC)+"&field2="+String(aThermometerOut, DEC)+"&field3="+String((digitalRead(CLIMATIC_PIN)), DEC)+"&field4="+String((digitalRead(VENTILATION_PIN)), DEC)+"&field5="+String(state_regul, DEC)+"&field6="+String(alarm_teplota, DEC)+"&field7="+String(zavada, DEC)); } } tthing++; // zobrazeni na LCD PLNE (jednou za hodinu) if (tlcdfull == 180000){ tlcdfull=0; lcd_background(); } tlcdfull++; // zobrazovani na LCD if (tlcd == 50){ lcd_print (); tlcd=0; } tlcd++; // obnoveni DHCP if (tdhcp == 20000){ dhcp_renew(); tdhcp = 0; } tdhcp++; // mereni a vycteni teploty z cidel if (ttemp == 10){ convert_temp(); } if (ttemp == 300){ read_temp(); ttemp=0; } ttemp++; // vyhodnocovani regulace if (tstate == 600){ tstate=0; if (eeprom_config.auto_set==1) { // Auto mode if (state_regul==10){ // state Climatic ClimaticVoid(); } else if (state_regul==20){ // state Ventilation VentilationVoid(); } else if (state_regul==30){ // state all Off AllOffVoid(); } } else { // Manual mode if (eeprom_config.clima_set==1) { digitalWrite(CLIMATIC_PIN, HIGH); } else { digitalWrite(CLIMATIC_PIN, LOW); } if (eeprom_config.ventilation_set==1) { digitalWrite(VENTILATION_PIN, HIGH); } else { digitalWrite(VENTILATION_PIN, LOW); } if (aThermometerIn>eeprom_config.alarm_temp) { // vyvola poslani alarmu na vysokou teplotu alarm_teplota=true; } if (aThermometerIn<(eeprom_config.alarm_temp-0.5)) { // zruseni alarmu teploty alarm_teplota=false; } } } tstate++; } // podprogram posilani mailu (predmet, zprava, 0/1 - info o systemu bool email(char* esubject, char* etext, bool stavsys) { bool success = false; /* convert sring STR_SMTP to char SMTP_NAME Length (with one extra character for the null terminator) */ int str_len = str_smtp.length() + 1; // Length (with one extra character for the null terminator) char char_smtp[str_len]; // Prepare the character array (the buffer) str_smtp.toCharArray(char_smtp, str_len); // Copy it over str_len = str_mail_from.length() + 1; // Length (with one extra character for the null terminator) char char_mail_from[str_len]; // Prepare the character array (the buffer) str_mail_from.toCharArray(char_mail_from, str_len); // Copy it over str_len = str_mail_to.length() + 1; // Length (with one extra character for the null terminator) char char_mail_to[str_len]; // Prepare the character array (the buffer) str_mail_to.toCharArray(char_mail_to, str_len); // Copy it over if (DEBUG) { Serial.println(F("Sending email...")); } if (client.connect(char_smtp, 25)){ //25 is SMTP Server port if (DEBUG) { Serial.println(F("connected")); } delay(100); client.println(F("EHLO arduino")); for(int i=0; i<999; ++i){ if(client.read() > 0) break; } if (DEBUG) { Serial.println(F("responded")); } //client.println("AUTH LOGIN"); //see "http://base64-encoder-online.waraxe.us/" //client.println("xxxxxxxxxx"); //Type your username and encode it //client.println("yyyyyyyyyy"); //Type your password and encode it</p> // Put your "from" email address here client.print(F("MAIL FROM:<")); client.print(char_mail_from); client.println(F(">")); //Seems you can write what you want here... for(int i=0; i<999; ++i){ if(client.read() > 0) break; } client.print(F("RCPT TO:<")); client.print(char_mail_to); client.println(">"); for(int i=0; i<999; ++i){ if(client.read() > 0) break; } client.println(F("DATA")); for(int i=0; i<999; ++i){ if(client.read() > 0) break; } //Sender client.print(F("from: ")); client.println(char_mail_from); //Sender address client.print(F("to: ")); client.println(char_mail_to); //Receiver address client.print(F("SUBJECT: ")); client.print(nameMail); client.println(esubject); client.println(""); client.println(etext); if (stavsys) { client.println(); client.println(F("Stav systemu:")); client.print(F("Vnitrni cidlo: ")); client.print(aThermometerIn); client.println(F(" C")); client.print(F("Venkovni cidlo: ")); client.print(aThermometerOut); client.println(F(" C")); client.print(F("Externi ventilator: ")); if (digitalRead(VENTILATION_PIN)) { client.print(F("ZAPNUT")); } else { client.print(F("VYPNUT")); } client.println(); client.print(F("Vnitrni klimatizace: ")); if (digitalRead(CLIMATIC_PIN)) { client.print(F("ZAPNUTA")); } else { client.print(F("VYPNUTA")); } client.println(); } client.println(F(".")); client.println(F("QUIT")); for (int i = 0; i<999; ++i){ if(i > 998){ if (DEBUG) { Serial.println(F("error: No response")); } fail_mail = true; } if(client.read() > 0) break; } success = true; fail_mail = false; client.println(); if (DEBUG) { Serial.println(F("end")); } } else { if (DEBUG) { Serial.println(F("Failed")); } fail_mail = true; client.println(F("QUIT")); //Disconnection } client.stop(); return success; } // podprogram Climatizovani void ClimaticVoid () { digitalWrite(VENTILATION_PIN, LOW); digitalWrite(CLIMATIC_PIN, HIGH); if ((aThermometerOut<eeprom_config.ventilation_temp) && (zavada==0) && (aThermometerIn<(eeprom_config.climatic_temp-0.5))) { // bez zavady cidla, teplota musi byt mensi nez teplota pro prechod na klimatizaci a venkovni teplota pod teplotou pro vetrani state_regul=20; // prejde na ventilaci } if (aThermometerIn>eeprom_config.alarm_temp) { // vysoka teplota alarm_teplota=true; alarm_temp_high(); } if (aThermometerIn<(eeprom_config.alarm_temp-0.5)) { // teplota je uz OK alarm_teplota=false; alarm_teplotaSend=true; } } // podprogram Ventilace void VentilationVoid () { digitalWrite(CLIMATIC_PIN, LOW); digitalWrite(VENTILATION_PIN, HIGH); if (zavada==1) { // v pripade zavady prechod na klimatizovani state_regul=10; return; } if (aThermometerIn>eeprom_config.climatic_temp) { // teplota mistnosti je nad teplotou pro klimatizovani state_regul=10; } if (aThermometerOut>(eeprom_config.ventilation_temp+1.5)) { // teplota venkovni je vetsi nez teplota pro ventilovani + 1,5 state_regul=10; } if (aThermometerIn<eeprom_config.minimal_temp) { // teplota mistnosti je mensi nez nejmensi mozna state_regul=30; } } // podprogram vse vypnuto void AllOffVoid () { digitalWrite(VENTILATION_PIN, LOW); digitalWrite(CLIMATIC_PIN, LOW); if (zavada==1) { // v pripade zavady prechod na klimatizovani state_regul=10; return; } if (aThermometerIn>(eeprom_config.minimal_temp+2)) { // teplota v mistnosti je vetsi nez vypinaci + 2 state_regul=20; } } // podrogram potreby obnoveni IP z DHCP void dhcp_renew () { if(eeprom_config.use_dhcp) { int status = Ethernet.maintain(); /* returns: 0: nothing happened 1: renew failed 2: renew success 3: rebind fail 4: rebind success */ if (DEBUG) { Serial.print(status); Serial.print(F(" ")); } if(status == 2){ if (DEBUG) { Serial.print(F("Status:")); Serial.println(status, DEC); Serial.println(F("IP address after renew/rebind:")); print_info(); } getDhcp(); } } } // podprogram nacteni IP z DHCP void getDhcp() { // ethernet up conection Serial.println(F("Trying to connect")); if (!Ethernet.begin(eeprom_config.mac)){ Serial.println(F("Failed to DHCP")); fail_ether = true; // verifyng connection // while(true); } delay(300); fail_ether = false; if (DEBUG) { // IP address is: Serial.print(F("IP address: ")); for (byte thisByte = 0; thisByte < 4; thisByte++) { Serial.print(Ethernet.localIP()[thisByte], DEC); Serial.print("."); } Serial.println(); } } // podprogram zobrazei IP configuration void print_info(){ print_ip(Ethernet.localIP()); print_ip(Ethernet.subnetMask()); print_ip(Ethernet.gatewayIP()); print_ip(Ethernet.dnsServerIP()); } void print_ip(IPAddress ip){ for (byte thisByte = 0; thisByte < 4; thisByte++) { // print the value of each byte of the IP address: Serial.print(ip[thisByte], DEC); if (thisByte != 3) Serial.print("."); } Serial.println(); } // podprogram spusteni prevodu teploty na cidlech void convert_temp () { // themperatures from all sensors if (DEBUG) oldtmp = millis(); sensorsA.requestTemperatures(); sensorsB.requestTemperatures(); if (DEBUG) Serial.println(millis() - oldtmp, DEC); } // podprogram vycteni teloty z cidel a priznak zavady a odeslani zpravy void read_temp () { aThermometerIn = sensorsA.getTempC(insideThermometer); aThermometerOut = sensorsB.getTempC(outsideThermometer); if (DEBUG) { Serial.print(F("Teplotni cidlo 1: ")); Serial.println(aThermometerIn, 3); Serial.print(F("Teplotni cidlo 2: ")); Serial.println(aThermometerOut, 3); } if ((aThermometerIn == -127.00) || (aThermometerOut == -127.00)) { Serial.println(F("Zavada teplotniho cidla")); zavada = true; state_regul=10; if (zavadaCidlaSend) { email("ZAVADA", "Zavada cidla teploty.", true); zavadaCidlaSend = false; } } else { zavadaCidlaSend = true; zavada = false; } } // podprogram odesilani varovneho maili na vysokou teplotu void alarm_temp_high () { if (alarm_teplotaSend==true) { email("VAROVANI", "Prilis vysoka teplota v mistnosti.", true); alarm_teplotaSend = false; } } // podprogram prevodu ID teplotnich cidel do zobrazovane podoby void printAddress(DeviceAddress deviceAddress) { for (uint8_t i = 0; i < 8; i++) { // zero pad the address if necessary if (deviceAddress[i] < 16) Serial.print("0"); Serial.print(deviceAddress[i], HEX); } } // print LCD background void lcd_background () { tft.fillScreen(0xBF3F); tft.setTextColor(NAVY); tft.setTextSize(1); tft.drawString("WebNet Climatic", 10, 10, 4); tft.setTextColor(WHITE); tft.drawString("Powered by BorgMcz", 105, 27, 2); tft.setTextColor(WHITE); tft.setCursor(10, 308); tft.setTextSize(1); tft.print(F("www.dccmm.cz")); tft.setTextSize(1); tft.setCursor(142,308); tft.print(F("borgm@seznam.cz")); tft.drawRoundRect(3, 50, 115, 90, 7, BLUE); tft.drawRoundRect(122, 50, 115, 90, 7, BLUE); tft.fillRoundRect(10, 55, 5, 20, 2, RED); tft.fillCircle(12, 75, 5, RED); tft.fillRoundRect(11, 67, 3, 8, 1, YELLOW); tft.fillCircle(12, 75, 4, YELLOW); tft.setTextSize(1); tft.setTextColor(BLUE); tft.drawString("INDOOR", 45, 55, 2); tft.fillRoundRect(132, 55, 5, 20, 2, RED); tft.fillCircle(134, 75, 5, RED); tft.fillRoundRect(133, 63, 3, 12, 1, YELLOW); tft.fillCircle(134, 75, 4, YELLOW); tft.setTextSize(1); tft.setTextColor(BLUE); tft.drawString("OUTDOOR", 155, 55, 2); tft.drawRoundRect(3, 182, 115, 77, 7, BLUE); tft.drawRoundRect(122, 182, 115, 77, 7, BLUE); tft.setTextSize(1); tft.setTextColor(BLUE); tft.drawString("CLIMATIC", 32, 187, 2); tft.drawString("VENTILATION", 140, 187, 2); old_A=88.8; lcd_print_t_left(); old_B=88.8; lcd_print_t_right(); old_climatic = (digitalRead(CLIMATIC_PIN)); // nacte a pak zneguje stav, aby se vykreslil old_climatic = !old_climatic; lcd_print_o_climatic(); old_ventilation = (digitalRead(VENTILATION_PIN)); // nacte a pak zneguje stav, aby se vykreslil old_ventilation = !old_ventilation; lcd_print_o_ventilation(); old_auto_set = !eeprom_config.auto_set; lcd_print_auto_man(); lcd_fail_print(); } // print LCD value void lcd_print () { switch (case_lcd) { case 1: lcd_print_t_left(); break; case 2: lcd_print_t_right(); break; case 3: lcd_print_o_climatic(); break; case 4: lcd_print_o_ventilation(); break; case 5: lcd_print_auto_man(); break; case 6: lcd_fail(); break; default: case_lcd = 1; break; } } void lcd_print_t_left() { if (aThermometerIn != old_A) { // neni stejny obsah jako predtim old_A = aThermometerIn; if (old_A == -0.0) { tft.setTextColor(BLACK, 0xBF3F); tft.drawString(" ",4 , 82, 7); tft.drawString("0.0", 48, 85, 6); }else if (old_A < -99 || old_A > 99) { tft.fillRect(4, 85, 113, 50, 0xBF3F); // lcd errr left tft.setTextColor(RED); tft.setCursor(40, 105); tft.setTextSize(2); tft.print("ERR"); tft.setTextSize(1); } else if (old_A <= -10.00) { // zaporne dvojcislo tft.setTextColor(BLACK, 0xBF3F); tft.drawFloat(old_A, 1, 4, 85, 6); } else if (old_A < 0.00) { // zaporne jednocislo tft.setTextColor(BLACK, 0xBF3F); tft.drawString(" ",4 , 82, 7); tft.drawFloat(old_A, 1, 31, 85, 6); } else if (old_A < 10.00) { // kladne jednocislo tft.setTextColor(BLACK, 0xBF3F); tft.drawString(" ",4 , 82, 7); tft.drawFloat(old_A, 1, 48, 85, 6); } else if (old_A < 100.00) { // kladne dvoucislo tft.setTextColor(BLACK, 0xBF3F); tft.drawString(" ",4 , 82, 7); //3 4 tft.drawFloat(old_A, 1, 21, 85, 6); } } case_lcd++; } void lcd_print_t_right() { if (aThermometerOut != old_B) { // neni stejny obsah jako predtim old_B = aThermometerOut; if (old_B == -0.0) { tft.setTextColor(BLACK, 0xBF3F); tft.drawString(" ",123, 82, 7); tft.drawString("0.0", 167, 85, 6); } else if (old_B < -99 || old_B > 99) { tft.fillRect(123, 85, 113, 50, 0xBF3F); // lcd errr left tft.setTextColor(RED); tft.setCursor(160, 105); tft.setTextSize(2); tft.print("ERR"); tft.setTextSize(1); } else if (old_B <= -10) { // zaporne dvojcislo tft.setTextColor(BLACK, 0xBF3F); tft.drawFloat(old_B, 1, 123, 85, 6); } else if (old_B < 0) { // zaporne jednocislo tft.setTextColor(BLACK, 0xBF3F); tft.drawString(" ",123, 82, 7); tft.drawFloat(old_B, 1, 150, 85, 6); } else if (old_B < 10) { // kladne jednocislo tft.setTextColor(BLACK, 0xBF3F); tft.drawString(" ",123, 82, 7); tft.drawFloat(old_B, 1, 167, 85, 6); } else if (old_B < 100) { // kladne dvoucislo tft.setTextColor(BLACK, 0xBF3F); tft.drawString(" ",123, 82, 7); tft.drawFloat(old_B, 1, 140, 85, 6); } } case_lcd++; } void lcd_print_o_climatic() { if (old_climatic != (digitalRead(CLIMATIC_PIN))) { old_climatic = (digitalRead(CLIMATIC_PIN)); if (old_climatic == true) { tft.setTextColor(BLACK); tft.fillRoundRect(19, 210, 82, 35, 10, GREEN); tft.drawString("ON", 41, 217, 4); } else { tft.setTextColor(BLACK); tft.fillRoundRect(19, 210, 82, 35, 10, RED); tft.drawString("OFF", 36, 217, 4); } } case_lcd++; } void lcd_print_o_ventilation() { if (old_ventilation != (digitalRead(VENTILATION_PIN))) { old_ventilation = (digitalRead(VENTILATION_PIN)); if (old_ventilation == true) { tft.setTextColor(BLACK); tft.fillRoundRect(138, 210, 82, 35, 10, GREEN); tft.drawString("ON", 160, 217, 4); } else { tft.setTextColor(BLACK); tft.fillRoundRect(138, 210, 82, 35, 10, RED); tft.drawString("OFF", 155, 217, 4); } } case_lcd++; } void lcd_print_auto_man() { if (old_auto_set != eeprom_config.auto_set) { old_auto_set = eeprom_config.auto_set; if (old_auto_set == true) { tft.setTextColor(BLACK, 0xBF3F); tft.drawString(" AUTO MODE ", 33, 150, 4); } else { tft.setTextColor(RED, 0xBF3F); tft.drawString("MODE MANUAL", 33, 150, 4); } } case_lcd++; } // testuje na zmenu v alarmech void lcd_fail() { unsigned int pocty = 0; if (zavada) pocty += 1; if (alarm_teplota) pocty += 2; if (fail_mail) pocty +=4; if (fail_ether) pocty +=8; if (fail_thing) pocty +=16; if (pocty != fail_zmena) { fail_zmena = pocty; lcd_fail_print(); } case_lcd++; } // vykresluje alarmy void lcd_fail_print() { tft.fillRect(20, 262, 215, 40, 0xBF3F); if (zavada || alarm_teplota || fail_mail || fail_ether || fail_thing) { // pokud je nekde zavada provede vykresleni tft.drawTriangle( 20, 300, 41, 265, 61, 300, RED); tft.drawTriangle( 21, 299, 41, 266, 60, 299, RED); tft.drawTriangle( 22, 299, 41, 267, 59, 299, RED); tft.drawTriangle( 23, 298, 41, 268, 58, 298, RED); tft.drawTriangle( 24, 298, 41, 269, 57, 298, RED); tft.fillTriangle( 25, 297, 41, 270, 56, 297, YELLOW); tft.setTextColor(RED); tft.setTextSize(1); tft.drawString("!", 37, 277, 4); tft.setTextColor(YELLOW); tft.setTextSize(2); tft.setCursor(57,266); if (fail_ether) tft.print(F("ETH ")); if (fail_mail) tft.print(F("MAIL ")); if (alarm_teplota) tft.print(F("TEMP")); tft.setCursor(66,286); if (fail_thing) tft.print(F("DATA ")); if (zavada) tft.print(F("SENSOR")); tft.setTextSize(1); } } // odesila data na server void updateThingSpeak(String tsData) { int str_len = writeAPIKey.length() + 1; // Length (with one extra character for the null terminator) char char_writeAPIKey[str_len]; // Prepare the character array (the buffer) writeAPIKey.toCharArray(char_writeAPIKey, str_len); // Copy it over if (client.connect(thingSpeakAddress, 80)) { client.print("POST /update HTTP/1.1\n"); client.print("Host: api.thingspeak.com\n"); client.print("Connection: close\n"); client.print("X-THINGSPEAKAPIKEY: "); client.print(char_writeAPIKey); client.print("\n"); client.print("Content-Type: application/x-www-form-urlencoded\n"); client.print("Content-Length: "); client.print(tsData.length()); client.print("\n\n"); client.print(tsData); if (client.connected()) { fail_thing = false; if (DEBUG) Serial.println(F("Connecting to ThingSpeak...")); } else { if (DEBUG) Serial.println(F("Connection to ThingSpeak failed")); fail_thing = true; } } else { if (DEBUG) Serial.println(F("Connection to ThingSpeak failed")); fail_thing = true; } delay(50); client.stop(); } |
První věcí kterou by jste měli začít je změna hesla pro přístup na stránku configurace a rebootu. Změnu provedete na řádku č. 807 pro configurační stránku a řádku č. 1615, kde najdete řetězec hodnoty “YWRtaW46YWRtaW4=” , který odpovídá současné hodnotě “admin:admin“. Pro změnu je třeba použít stránku, která váš řetězec převede do kódu base64 – http://base64-encoder-online.waraxe.us/. Například nové hodnotě “admin:heslo” odpovídá po encodování řetězec “YWRtaW46aGVzbG8=” , ten pak na uvedechých řádcích vyměňte.
Pokud váš SMTP server odchozí pošty bude vyžadovat ověření heslem, je možné v kódu odkomentovat řádky č. 1906 až 1908 a doplníte encodované jméno a heslo na stejné stránce jako u přístupového hesla na web.
Ostatní změny v kódu už jsou pak pouze na vašem rozhodnutí a nepovinné
Co se týká zapnutí a oživení, je třeba regulátor napájet externím zdrojem ideálně v rozmezí 7,5 – 12V. Napájení pouze pomocí USB portu je nedostatečné.
Při prvním zapnutí po nahrání kódu pomocí IDE, je třeba naplnit defaultní hodnoty do EEPROM. To se provádí propojením vstupu “Default” pin40 a svorky “GND“. Teprve nyní se přivede napájecí napětí a vyčká se do vypsání hlášky o nastavení defaultních hodnot během bootovacího výpisu na LCD. Nyní se může napájení odpojit, rozpojit pin Default a GND. Po následném zapnutí napájení, už systém startuje ve výchozím nastavení. Výchozí IP adresa je nastavena statická na hodnotu “192.168.1.100” a přístupové údaje na web “admin / admin“.
Doufám, že článek někomu pomůže v jeho tvorbě.
Zdrojový kód je pak šířen pomocí Open GPL licence.
————————————————————————————————————————————————-
Soubory ke stažení:
————————————————————————————————————————————————-
______________________________________________________________________________________
______________________________________________________________________________________