Advertisement
Guest User

Untitled

a guest
Jun 20th, 2013
206
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // This is a demo of the RBBB running as webserver with the Ether Card
  2. // 2010-05-28 <jc@wippler.nl> http://opensource.org/licenses/mit-license.php
  3.  
  4. #include <EtherCard.h>
  5. #include <OneWire.h>
  6. #include <DallasTemperature.h>
  7.  
  8. #define ONE_WIRE_BUS 6
  9.  
  10. // ethernet interface mac address, must be unique on the LAN
  11. static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
  12. static byte myip[] = { 192,168,2,200 };
  13.  
  14. byte Ethernet::buffer[500];
  15. BufferFiller bfill;
  16.  
  17. OneWire oneWire(ONE_WIRE_BUS);
  18. DallasTemperature sensors(&oneWire);
  19.  
  20. DeviceAddress insideThermometer = { 0x28, 0x96, 0xC2, 0xBC, 0x04, 0x00, 0x00, 0xA1 };
  21. DeviceAddress outsideThermometer = { 0x28, 0xA5, 0x0E, 0xBD, 0x04, 0x00, 0x00, 0x99 };
  22.  
  23. void setup () {
  24.  
  25. // teplota sa bude zobrazovat na seriovej konzole
  26. Serial.begin(57600);
  27. Serial.println("\n[Webserver]");
  28. // Start kniznice
  29. sensors.begin();
  30. // Nastavenie rozlisenia na 10 bitov
  31. sensors.setResolution(insideThermometer, 10);
  32. sensors.setResolution(outsideThermometer, 10);
  33.  
  34. if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
  35. Serial.println( "Failed to access Ethernet controller");
  36. ether.staticSetup(myip);
  37. }
  38.  
  39. float printTemperature(DeviceAddress deviceAddress)
  40. {
  41. float tempC = sensors.getTempC(deviceAddress);
  42. if (tempC == -127.00) {
  43. Serial.print("Chyba, senzor neodpoveda");
  44. } else {
  45. Serial.print("C: ");
  46. Serial.print(tempC);
  47.  
  48. return(tempC);
  49.  
  50. }
  51. }
  52. static word homePage() {
  53. long t = millis() / 1000;
  54. word h = t / 3600;
  55. byte m = (t / 60) % 60;
  56. byte s = t % 60;
  57. sensors.requestTemperatures();
  58. bfill = ether.tcpOffset();
  59. bfill.emit_p(PSTR(
  60. "HTTP/1.0 200 OK\r\n"
  61. "Content-Type: text/html\r\n"
  62. "Pragma: no-cache\r\n"
  63. "\r\n"
  64. "<meta http-equiv='refresh' content='2'/>"
  65. "<title>Teplotny server</title>"
  66. "<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);
  67.  
  68. return bfill.position();
  69. }
  70.  
  71.  
  72.  
  73. void loop () {
  74. word len = ether.packetReceive();
  75. word pos = ether.packetLoop(len);
  76.  
  77.  
  78. if (pos) // check if valid tcp data is received
  79. ether.httpServerReply(homePage()); // send web page data
  80. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement