Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define APP_VERSION "1.07" // verze aplikace
- #include <Ethernet.h> // standardni knihovna pro W5100
- #include <EthernetUdp.h>
- #include <Time.h>
- #include <RTClib.h> // https://github.com/adafruit/RTClib
- #include "Adafruit_LEDBackpack.h" // https://github.com/adafruit/Adafruit-LED-Backpack-Library
- #include <OneWire.h> // https://github.com/PaulStoffregen/OneWire nebo http://www.pjrc.com/teensy/td_libs_OneWire.html
- #include <DallasTemperature.h> // https://github.com/milesburton/Arduino-Temperature-Control-Library
- #include "Tasker.h" // https://github.com/joysfera/arduino-tasker
- #define _NTP_SYNCHRO_
- #define TASKER_MAX_TASKS 8 // maximalni pocet uloh pro tasker
- #define MAX_SENSORS_COUNT 5 // maximalni pocet cidel DS18B20
- #define DISPLAY_ADDRESS 0x70 // I2C address of the display. Stick with the default address of 0x70
- #define MY_TIME_ZONE 1 * ONE_HOUR
- #define MY_DST eu_dst
- #define UNIX_EPOCH 2208988800UL
- byte mac[] = { 0x12, 0x34, 0x56, 0x01, 0x01, 0x04 };
- EthernetServer server(80);
- EthernetUDP udpClient;
- Tasker tasker(false); // Petruv Tasker pro prepinani uloh
- bool netReady = false; // jede ethernet (dostal jsem IP)
- const char timeServer[] = "ntp.nic.cz"; // NTP server
- void setup()
- {
- Serial.begin(115200);
- Serial.print(F("Verze "));
- Serial.println(F(APP_VERSION));
- initEthernet(0);
- tasker.setInterval(merTeplotu, 10000); // mereni teploty
- tasker.setInterval(nastavJas, 5000); // nastaveni jasu display
- tasker.setInterval(prepniDvojtecku, 500); // prepinani dvojtecky na hodinach kazdych 500 ms
- }
- void loop()
- {
- if (netReady)
- {
- EthernetClient client = server.available();
- if (client) web(&client); // prisel HTTP pozadavek, obslouzim klienta
- }
- tasker.loop();
- }
- void initEthernet(int)
- {
- if (netReady) return;
- Serial.println(F("Ziskani IP z DHCP"));
- if (Ethernet.begin(mac) == 1)
- {
- Serial.print(F("IP: "));
- Serial.println(Ethernet.localIP());
- netReady = true;
- setTime();
- }
- else
- {
- chyba(3);
- tasker.setTimeout(initEthernet, 1000 * 60 * 5); // za 5 minut zkusim znovu ziskat IP
- }
- }
- void web( EthernetClient * client)
- {
- Serial.println(F("HTTP Req"));
- bool currLineBlank = true;
- while (client->connected())
- {
- if (client->available())
- {
- char c = client->read();
- if (c == '\n' && currLineBlank)
- {
- client->println(F("HTTP/1.1 200 OK"));
- client->println(F("Access-Control-Allow-Origin: *"));
- client->println(F("Access-Control-Allow-Methods: GET"));
- client->println(F("Content-Type: application/xml"));
- client->println();
- client->println(F("<?xml version = \"1.0\" encoding=\"UTF-8\"?>"));
- client->print(F("<!--v"));
- client->print(F(APP_VERSION));
- client->println(F("-->"));
- client->print(F("<cidla timestamp='"));
- client->print(millis());
- client->println(F("'>"));
- for (byte i = 0; i < sensors.getDeviceCount() ; i++)
- {
- client->print(F("<cidlo typ='DS18B20' adresa='"));
- printDS18B20Address(&sensors, i, client);
- client->print(F("' teplota='"));
- client->print(sensors.getDeviceTemperature(i));
- client->println(F("'>"));
- client->print(F("<teplota>"));
- client->print(sensors.getDeviceTemperature(i),1 );
- client->println(F("</teplota>"));
- client->println(F("</cidlo>"));
- }
- #if defined(_NTP_SYNCHRO_)
- client->print(F("<ntp lastsynchronization='"));
- client->print(lastSynchronization);
- client->println(F("' />"));
- #endif
- client->print(F("</cidla>"));
- break;
- }
- if (c == '\n') // you're starting a new line
- currLineBlank = true;
- else if (c != '\r') // you've gotten a character on the current line
- currLineBlank = false;
- }
- }
- delay(5); // give the web browser time to receive the data
- client->stop(); // close the connection:
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement