Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This is a demo of the RBBB running as webserver with the Ether Card
- // 2010-05-28 <jc@wippler.nl> http://opensource.org/licenses/mit-license.php
- #include <EtherCard.h>
- #include <OneWire.h>
- #include <DallasTemperature.h>
- #define ONE_WIRE_BUS 6
- // ethernet interface mac address, must be unique on the LAN
- static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
- static byte myip[] = { 192,168,2,200 };
- byte Ethernet::buffer[500];
- BufferFiller bfill;
- OneWire oneWire(ONE_WIRE_BUS);
- DallasTemperature sensors(&oneWire);
- DeviceAddress insideThermometer = { 0x28, 0x96, 0xC2, 0xBC, 0x04, 0x00, 0x00, 0xA1 };
- DeviceAddress outsideThermometer = { 0x28, 0xA5, 0x0E, 0xBD, 0x04, 0x00, 0x00, 0x99 };
- void setup () {
- // teplota sa bude zobrazovat na seriovej konzole
- Serial.begin(57600);
- Serial.println("\n[Webserver]");
- // Start kniznice
- sensors.begin();
- // Nastavenie rozlisenia na 10 bitov
- sensors.setResolution(insideThermometer, 10);
- sensors.setResolution(outsideThermometer, 10);
- if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
- Serial.println( "Failed to access Ethernet controller");
- ether.staticSetup(myip);
- }
- float printTemperature(DeviceAddress deviceAddress)
- {
- float tempC = sensors.getTempC(deviceAddress);
- if (tempC == -127.00) {
- Serial.print("Chyba, senzor neodpoveda");
- } else {
- Serial.print("C: ");
- Serial.print(tempC);
- return(tempC);
- }
- }
- static word homePage() {
- long t = millis() / 1000;
- word h = t / 3600;
- byte m = (t / 60) % 60;
- byte s = t % 60;
- sensors.requestTemperatures();
- bfill = ether.tcpOffset();
- bfill.emit_p(PSTR(
- "HTTP/1.0 200 OK\r\n"
- "Content-Type: text/html\r\n"
- "Pragma: no-cache\r\n"
- "\r\n"
- "<meta http-equiv='refresh' content='2'/>"
- "<title>Teplotny server</title>"
- "<h1>Teplota zo solara: $TC<br> Teplota do solara: $TC</h1><br><br><h3>Cas od restartu: $D$D:$D$D:$D$D</h3>"),printTemperature(outsideThermometer), printTemperature(insideThermometer),h/10, h%10, m/10, m%10, s/10, s%10);
- return bfill.position();
- }
- void loop () {
- word len = ether.packetReceive();
- word pos = ether.packetLoop(len);
- if (pos) // check if valid tcp data is received
- ether.httpServerReply(homePage()); // send web page data
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement