Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Ajout de ArduinoAtmogram

  • Loading branch information...
commit bdb734c3c881de2dcffce8a7597bbb18e30c79c0 1 parent 9294684
authored January 27, 2012

Showing 61 changed files with 6,427 additions and 0 deletions. Show diff stats Hide diff stats

  1. 40  ArduinoAtmogram/README
  2. BIN  ArduinoAtmogram/docs/LCD_preview.jpg
  3. BIN  ArduinoAtmogram/docs/poster1.pdf
  4. BIN  ArduinoAtmogram/docs/poster2.pdf
  5. BIN  ArduinoAtmogram/docs/screen_preview.png
  6. 184  ArduinoAtmogram/src/arduino/ArduinoAtmogram.ino
  7. 150  ArduinoAtmogram/src/arduino/librairies/DHTsensorLibrary/DHT.cpp
  8. 35  ArduinoAtmogram/src/arduino/librairies/DHTsensorLibrary/DHT.h
  9. 3  ArduinoAtmogram/src/arduino/librairies/DHTsensorLibrary/README.txt
  10. 44  ArduinoAtmogram/src/arduino/librairies/DHTsensorLibrary/examples/DHTtester/DHTtester.pde
  11. 349  ArduinoAtmogram/src/arduino/librairies/Ethernet/Dhcp.cpp
  12. 158  ArduinoAtmogram/src/arduino/librairies/Ethernet/Dhcp.h
  13. 423  ArduinoAtmogram/src/arduino/librairies/Ethernet/Dns.cpp
  14. 41  ArduinoAtmogram/src/arduino/librairies/Ethernet/Dns.h
  15. 95  ArduinoAtmogram/src/arduino/librairies/Ethernet/Ethernet.cpp
  16. 38  ArduinoAtmogram/src/arduino/librairies/Ethernet/Ethernet.h
  17. 165  ArduinoAtmogram/src/arduino/librairies/Ethernet/EthernetClient.cpp
  18. 37  ArduinoAtmogram/src/arduino/librairies/Ethernet/EthernetClient.h
  19. 91  ArduinoAtmogram/src/arduino/librairies/Ethernet/EthernetServer.cpp
  20. 22  ArduinoAtmogram/src/arduino/librairies/Ethernet/EthernetServer.h
  21. 183  ArduinoAtmogram/src/arduino/librairies/Ethernet/EthernetUdp.cpp
  22. 98  ArduinoAtmogram/src/arduino/librairies/Ethernet/EthernetUdp.h
  23. 222  ...mogram/src/arduino/librairies/Ethernet/examples/BarometricPressureWebServer/BarometricPressureWebServer.ino
  24. 63  ArduinoAtmogram/src/arduino/librairies/Ethernet/examples/ChatServer/ChatServer.ino
  25. 53  ArduinoAtmogram/src/arduino/librairies/Ethernet/examples/DhcpAddressPrinter/DhcpAddressPrinter.ino
  26. 80  ArduinoAtmogram/src/arduino/librairies/Ethernet/examples/DhcpChatServer/DhcpChatServer.ino
  27. 76  ArduinoAtmogram/src/arduino/librairies/Ethernet/examples/DnsWebClient/DnsWebClient.ino
  28. 144  ArduinoAtmogram/src/arduino/librairies/Ethernet/examples/PachubeClient/PachubeClient.ino
  29. 121  ArduinoAtmogram/src/arduino/librairies/Ethernet/examples/PachubeClientString/PachubeClientString.ino
  30. 87  ArduinoAtmogram/src/arduino/librairies/Ethernet/examples/TelnetClient/TelnetClient.ino
  31. 124  ArduinoAtmogram/src/arduino/librairies/Ethernet/examples/TwitterClient/TwitterClient.ino
  32. 118  ArduinoAtmogram/src/arduino/librairies/Ethernet/examples/UDPSendReceiveString/UDPSendReceiveString.ino
  33. 136  ArduinoAtmogram/src/arduino/librairies/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino
  34. 75  ArduinoAtmogram/src/arduino/librairies/Ethernet/examples/WebClient/WebClient.ino
  35. 82  ArduinoAtmogram/src/arduino/librairies/Ethernet/examples/WebServer/WebServer.ino
  36. 37  ArduinoAtmogram/src/arduino/librairies/Ethernet/keywords.txt
  37. 13  ArduinoAtmogram/src/arduino/librairies/Ethernet/util.h
  38. 400  ArduinoAtmogram/src/arduino/librairies/Ethernet/utility/socket.cpp
  39. 41  ArduinoAtmogram/src/arduino/librairies/Ethernet/utility/socket.h
  40. 188  ArduinoAtmogram/src/arduino/librairies/Ethernet/utility/w5100.cpp
  41. 397  ArduinoAtmogram/src/arduino/librairies/Ethernet/utility/w5100.h
  42. 215  ArduinoAtmogram/src/arduino/librairies/LCD4884/LCD4884.cpp
  43. 43  ArduinoAtmogram/src/arduino/librairies/LCD4884/LCD4884.h
  44. 89  ArduinoAtmogram/src/arduino/librairies/LCD4884/examples/LCD4884_deux/dfr48841.pde
  45. 23  ArduinoAtmogram/src/arduino/librairies/LCD4884/examples/LCD4884_menu/DFrobot_bmp.h
  46. 36  ArduinoAtmogram/src/arduino/librairies/LCD4884/examples/LCD4884_menu/DFrobot_chinese.h
  47. 284  ArduinoAtmogram/src/arduino/librairies/LCD4884/examples/LCD4884_menu/LCD4884_menu.pde
  48. 112  ArduinoAtmogram/src/arduino/librairies/LCD4884/examples/LCD4884_menu/wiring.h
  49. 101  ArduinoAtmogram/src/arduino/librairies/LCD4884/font_6x8.h
  50. 141  ArduinoAtmogram/src/arduino/librairies/LCD4884/font_big.h
  51. 112  ArduinoAtmogram/src/arduino/librairies/LCD4884/wiring.h
  52. 61  ArduinoAtmogram/src/arduino/librairies/SPI/SPI.cpp
  53. 70  ArduinoAtmogram/src/arduino/librairies/SPI/SPI.h
  54. 143  ArduinoAtmogram/src/arduino/librairies/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino
  55. 143  ...uino/librairies/SPI/examples/BarometricPressureSensor/BarometricPressureSensor/BarometricPressureSensor.ino
  56. 71  ArduinoAtmogram/src/arduino/librairies/SPI/examples/DigitalPotControl/DigitalPotControl.ino
  57. 36  ArduinoAtmogram/src/arduino/librairies/SPI/keywords.txt
  58. BIN  ArduinoAtmogram/src/webserver/chart_bg.jpg
  59. 0  ArduinoAtmogram/src/webserver/data.csv
  60. 118  ArduinoAtmogram/src/webserver/index.php
  61. 16  ArduinoAtmogram/src/webserver/js/jscharts.js
40  ArduinoAtmogram/README
... ...
@@ -0,0 +1,40 @@
  1
+** Arduino Atmogram **
  2
+
  3
+
  4
+* Description *
  5
+
  6
+Monitor and display temperature and humidity informations on a LCD screen and log it on a web server.
  7
+
  8
+Look at docs directory to look at preview.
  9
+
  10
+Arduino Uno with:
  11
+  - DHT11 (temperature & humidity sensors);
  12
+  - LCD 4884 screen;
  13
+  - Ethernet shield;
  14
+
  15
+
  16
+* Installation *
  17
+
  18
+Arduino:
  19
+  "ArduinoAtmogram.ino":
  20
+    - Define your sensor type : "#define DHTTYPE DHT11" or DHT22 if you use it and map the PIN;
  21
+    - Set up "IP Arduino" and "IP web server" depending on your config;
  22
+    - Add a gateway and a subnet if you don't post to a local server "Ethernet.begin(mac, ip, gw, sub)";
  23
+
  24
+  "librairies":
  25
+    - Librairies that you need are in librairies directory copy it in Arduino app folder.
  26
+
  27
+Web server:
  28
+  Set up:
  29
+    - Copy content of "webserver" directory to the root of your web server;
  30
+    - Be sure that "data.csv" is readable and writeable ('chmod 777 data.csv');
  31
+
  32
+
  33
+* Enjoy *
  34
+
  35
+We know that our program is not perfect, but it is enough for us.
  36
+
  37
+Fork the project and push me your improvements.
  38
+
  39
+vjo - https://github.com/vjo/
  40
+flissot - https://github.com/flissot
BIN  ArduinoAtmogram/docs/LCD_preview.jpg
BIN  ArduinoAtmogram/docs/poster1.pdf
Binary file not shown
BIN  ArduinoAtmogram/docs/poster2.pdf
Binary file not shown
BIN  ArduinoAtmogram/docs/screen_preview.png
184  ArduinoAtmogram/src/arduino/ArduinoAtmogram.ino
... ...
@@ -0,0 +1,184 @@
  1
+/*
  2
+ ArduinoAtmogram
  3
+ 
  4
+ Monitor the temperature and humidity and display the values on the LCD screen.
  5
+ It also POST the values to a web server to log it.
  6
+  
  7
+ Build on the top of Web client arduino's example.
  8
+ 
  9
+ Circuit:
  10
+ * Ethernet shield attached to pins 10, 11, 12, 13
  11
+ * DHT11 (temp & humidity sensors)
  12
+ * LCD4884 shield
  13
+ 
  14
+ Florian Lissot & Victor Jolissaint
  15
+ @ FabLab Telecom Bretagne 2012.
  16
+ */
  17
+
  18
+#include <SPI.h>
  19
+#include <Ethernet.h>
  20
+#include "LCD4884.h"
  21
+#include "DHT.h"
  22
+
  23
+#define DHTPIN A1       // what pin we're connected to
  24
+#define DHTTYPE DHT11   // DHT 11 : our captor
  25
+
  26
+DHT dht(DHTPIN, DHTTYPE);
  27
+
  28
+// Enter a MAC address for your controller below.
  29
+// Newer Ethernet shields have a MAC address printed on a sticker on the shield
  30
+byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
  31
+IPAddress ip(192,168,0, 2); // IP Arduino
  32
+IPAddress server(192,168,0, 254); // IP web server
  33
+
  34
+// Initialize the Ethernet client library
  35
+// with the IP address and port of the server 
  36
+// that you want to connect to (port 80 is default for HTTP):
  37
+EthernetClient client;
  38
+
  39
+void setup() {
  40
+  // start the serial library:
  41
+  Serial.begin(9600);
  42
+  // start the Ethernet connection:
  43
+  Ethernet.begin(mac, ip);
  44
+  
  45
+  // Show if the @IP is set
  46
+  // print your local IP address:
  47
+  Serial.print("My IP address: ");
  48
+  ip = Ethernet.localIP();
  49
+  for (byte thisByte = 0; thisByte < 4; thisByte++)
  50
+  {
  51
+    // print the value of each byte of the IP address:
  52
+    Serial.print(ip[thisByte], DEC);
  53
+    Serial.print("."); 
  54
+  }
  55
+  Serial.println();
  56
+  
  57
+  /* init lcd screen */
  58
+  lcd.LCD_init();
  59
+  lcd.LCD_clear();
  60
+  lcd.LCD_write_string(0, 0, "Florian &", MENU_NORMAL );
  61
+  lcd.LCD_write_string(0, 1, "Victor", MENU_NORMAL );
  62
+  lcd.LCD_write_string(0, 2, "presents:", MENU_NORMAL );
  63
+  lcd.LCD_write_string(0, 3, "", MENU_NORMAL );
  64
+  lcd.LCD_write_string(0, 4, "      Arduino", MENU_NORMAL );
  65
+  lcd.LCD_write_string(0, 5, "     Atmogram", MENU_NORMAL );
  66
+  
  67
+  // LCD blink 3 times
  68
+  lcdBlink(3, 200);
  69
+  
  70
+  // Sensors
  71
+  dht.begin();
  72
+  
  73
+  // Give the Ethernet shield a second to initialize:
  74
+  delay(1000);
  75
+  Serial.println("ready...");
  76
+}
  77
+
  78
+void loop()
  79
+{
  80
+  // Reading temperature or humidity takes about 250 milliseconds!
  81
+  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  82
+  float humi = dht.readHumidity();
  83
+  float temp = dht.readTemperature();
  84
+
  85
+  // Convert int to char
  86
+  char humiBuf[3];
  87
+  char tempBuf[3];
  88
+  sprintf(humiBuf, "%d", (int)humi);
  89
+  sprintf(tempBuf, "%d", (int)temp);  
  90
+
  91
+  // Check if returns are valid, if they are NaN (not a number) then something went wrong!
  92
+  if (isnan(temp) || isnan(humi)) {
  93
+    Serial.println("Failed to read from DHT");
  94
+  } 
  95
+  else {
  96
+    Serial.print("Humidity: "); 
  97
+    Serial.print(humi);
  98
+    Serial.print(" %\t");
  99
+    Serial.print("Temperature: "); 
  100
+    Serial.print(temp);
  101
+    Serial.println(" *C");
  102
+  }
  103
+  
  104
+  lcd.LCD_clear();
  105
+  
  106
+  // int raw = analogRead(8);
  107
+  // int temp = MULTIPLIER * (float) raw;
  108
+  char tempString[6] = "";
  109
+  char humiString[6] = "";
  110
+  
  111
+  sprintf(tempString,"%d",(int)temp);
  112
+  sprintf(humiString,"%d",(int)humi);
  113
+  
  114
+  // Draw a cloud    
  115
+  unsigned char sunnycloudbmp[] = 
  116
+  {
  117
+    0x00,0xE0,0x18,0x0C,0x0C,0x08,0x08,0xD0,0x20,0x10,0x08,0x08,0x08,0x10,0x10,0x30,0x10,0x20,0x24,0x44,0x48,0xB0,0x10,0x13,0x0C,0x08,0x08,0x1C,0x16,0x71,0xA0,0x10,0x18,0x08,0x00,
  118
+    0x00,0x71,0x9F,0x03,0x02,0x02,0x00,0x20,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x00,0x08,0x08,0x0F,0x08,0x88,0x88,0x90,0xF0,0x70,0xCC,0x0F,0x19,0x31,0x61,0x01,
  119
+    0x00,0x00,0x01,0x02,0x02,0x02,0x02,0x02,0x02,0x01,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x03,0x04,0x04,0x0C,0x08,0x08,0x08,0x0C,0x07,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00
  120
+  };
  121
+  lcd.LCD_draw_bmp_pixel(40, 0, sunnycloudbmp, 35,20); // (posi,tion , name, si,ze)
  122
+  
  123
+  // Display temp
  124
+  lcd.LCD_write_string(0, 1, "+", MENU_NORMAL);
  125
+  lcd.LCD_write_string_big(6, 0, tempString, MENU_NORMAL);
  126
+  lcd.LCD_write_string(30, 1, "C", MENU_NORMAL);
  127
+   
  128
+  // Draw a drop 
  129
+  unsigned char dropbmp[] = 
  130
+    {
  131
+      0x00,0x00,0x00,0x80,0x40,0x20,0x18,0x07,0x0C,0x10,0x60,0x80,0x00,0x00,0x00,
  132
+      0x00,0x00,0x06,0x0B,0x10,0x26,0x28,0x28,0x20,0x20,0x10,0x0F,0x00,0x00,0x00
  133
+    };
  134
+  lcd.LCD_draw_bmp_pixel(32,4, dropbmp, 15,15); // (posi,tion , name, si,ze) 
  135
+  
  136
+  // Display humidity
  137
+  lcd.LCD_write_string_big(50, 3, humiString, MENU_NORMAL);
  138
+  lcd.LCD_write_string(75, 4, "%", MENU_NORMAL);
  139
+  
  140
+  Serial.println("connecting...");
  141
+  
  142
+  // If you get a connection, report back via serial:
  143
+  if (client.connect(server, 80)) {
  144
+    Serial.println("connected");
  145
+    
  146
+    // Make a HTTP request:
  147
+    char req[80];
  148
+    sprintf(req, "GET /index.php?temp=%s&humi=%s HTTP/1.0", tempBuf, humiBuf);
  149
+    
  150
+    //Serial.println(req); // print the request
  151
+    
  152
+    client.println(req); //send request
  153
+    client.println();
  154
+  } 
  155
+  else {
  156
+    // if you didn't get a connection to the server:
  157
+    Serial.println("connection failed");
  158
+  }
  159
+  
  160
+  // if there are incoming bytes available 
  161
+  // from the server, read them and print them:
  162
+  if (client.available()) {
  163
+    char c = client.read();
  164
+    Serial.print(c);
  165
+  }
  166
+  
  167
+  client.stop(); // if not, it can re-connect anymore
  168
+  
  169
+  // Refresh time
  170
+  delay(10000);
  171
+
  172
+  // LCD blink 2 times to notify the refresh
  173
+  lcdBlink(2, 200);
  174
+}
  175
+
  176
+void lcdBlink(int count, int delayMs) {
  177
+    for(int i=0; i< count; i++){
  178
+      lcd.LCD_backlight(1);
  179
+      delay(delayMs);
  180
+      lcd.LCD_backlight(0);     
  181
+      delay(delayMs);
  182
+    }
  183
+    lcd.LCD_backlight(1);
  184
+}
150  ArduinoAtmogram/src/arduino/librairies/DHTsensorLibrary/DHT.cpp
... ...
@@ -0,0 +1,150 @@
  1
+/* DHT library 
  2
+
  3
+MIT license
  4
+written by Adafruit Industries
  5
+*/
  6
+
  7
+#include "DHT.h"
  8
+
  9
+DHT::DHT(uint8_t pin, uint8_t type) {
  10
+  _pin = pin;
  11
+  _type = type;
  12
+  firstreading = true;
  13
+}
  14
+
  15
+void DHT::begin(void) {
  16
+  // set up the pins!
  17
+  pinMode(_pin, INPUT);
  18
+  digitalWrite(_pin, HIGH);
  19
+  _lastreadtime = 0;
  20
+}
  21
+
  22
+float DHT::readTemperature(void) {
  23
+  float f;
  24
+
  25
+  if (read()) {
  26
+    switch (_type) {
  27
+    case DHT11:
  28
+      f = data[2];
  29
+      return f;
  30
+    case DHT22:
  31
+    case DHT21:
  32
+      f = data[2] & 0x7F;
  33
+      f *= 256;
  34
+      f += data[3];
  35
+      f /= 10;
  36
+      if (data[2] & 0x80)
  37
+	f *= -1;
  38
+
  39
+      return f;
  40
+    }
  41
+  }
  42
+  Serial.print("Read fail");
  43
+  return NAN;
  44
+}
  45
+
  46
+float DHT::readHumidity(void) {
  47
+  float f;
  48
+  if (read()) {
  49
+    switch (_type) {
  50
+    case DHT11:
  51
+      f = data[0];
  52
+      return f;
  53
+    case DHT22:
  54
+    case DHT21:
  55
+      f = data[0];
  56
+      f *= 256;
  57
+      f += data[1];
  58
+      f /= 10;
  59
+      return f;
  60
+    }
  61
+  }
  62
+  Serial.print("Read fail");
  63
+  return NAN;
  64
+}
  65
+
  66
+
  67
+boolean DHT::read(void) {
  68
+  uint8_t laststate = HIGH;
  69
+  uint8_t counter = 0;
  70
+  uint8_t j = 0, i;
  71
+  unsigned long currenttime;
  72
+
  73
+  // pull the pin high and wait 250 milliseconds
  74
+  digitalWrite(_pin, HIGH);
  75
+  delay(250);
  76
+
  77
+  currenttime = millis();
  78
+  if (currenttime < _lastreadtime) {
  79
+    // ie there was a rollover
  80
+    _lastreadtime = 0;
  81
+  }
  82
+  if (!firstreading && ((currenttime - _lastreadtime) < 2000)) {
  83
+    return true; // return last correct measurement
  84
+    //delay(2000 - (currenttime - _lastreadtime));
  85
+  }
  86
+  firstreading = false;
  87
+  /*
  88
+    Serial.print("Currtime: "); Serial.print(currenttime);
  89
+    Serial.print(" Lasttime: "); Serial.print(_lastreadtime);
  90
+  */
  91
+  _lastreadtime = millis();
  92
+
  93
+  data[0] = data[1] = data[2] = data[3] = data[4] = 0;
  94
+  
  95
+  // now pull it low for ~20 milliseconds
  96
+  pinMode(_pin, OUTPUT);
  97
+  digitalWrite(_pin, LOW);
  98
+  delay(20);
  99
+  cli();
  100
+  digitalWrite(_pin, HIGH);
  101
+  delayMicroseconds(40);
  102
+  pinMode(_pin, INPUT);
  103
+
  104
+  // read in timings
  105
+  for ( i=0; i< MAXTIMINGS; i++) {
  106
+    counter = 0;
  107
+    while (digitalRead(_pin) == laststate) {
  108
+      counter++;
  109
+      delayMicroseconds(1);
  110
+      if (counter == 255) {
  111
+        break;
  112
+      }
  113
+    }
  114
+    laststate = digitalRead(_pin);
  115
+
  116
+    if (counter == 255) break;
  117
+
  118
+    // ignore first 3 transitions
  119
+    if ((i >= 4) && (i%2 == 0)) {
  120
+      // shove each bit into the storage bytes
  121
+      data[j/8] <<= 1;
  122
+      if (counter > 6)
  123
+        data[j/8] |= 1;
  124
+      j++;
  125
+    }
  126
+
  127
+  }
  128
+
  129
+  sei();
  130
+  
  131
+  /*
  132
+  Serial.println(j, DEC);
  133
+  Serial.print(data[0], HEX); Serial.print(", ");
  134
+  Serial.print(data[1], HEX); Serial.print(", ");
  135
+  Serial.print(data[2], HEX); Serial.print(", ");
  136
+  Serial.print(data[3], HEX); Serial.print(", ");
  137
+  Serial.print(data[4], HEX); Serial.print(" =? ");
  138
+  Serial.println(data[0] + data[1] + data[2] + data[3], HEX);
  139
+  */
  140
+
  141
+  // check we read 40 bits and that the checksum matches
  142
+  if ((j >= 40) && 
  143
+      (data[4] == ((data[0] + data[1] + data[2] + data[3]) & 0xFF)) ) {
  144
+    return true;
  145
+  }
  146
+  
  147
+
  148
+  return false;
  149
+
  150
+}
35  ArduinoAtmogram/src/arduino/librairies/DHTsensorLibrary/DHT.h
... ...
@@ -0,0 +1,35 @@
  1
+#if ARDUINO >= 100
  2
+ #include "Arduino.h"
  3
+#else
  4
+ #include "WProgram.h"
  5
+#endif
  6
+
  7
+/* DHT library 
  8
+
  9
+MIT license
  10
+written by Adafruit Industries
  11
+*/
  12
+
  13
+// how many timing transitions we need to keep track of. 2 * number bits + extra
  14
+#define MAXTIMINGS 85
  15
+
  16
+#define DHT11 11
  17
+#define DHT22 22
  18
+#define DHT21 21
  19
+#define AM2301 21
  20
+
  21
+class DHT {
  22
+ private:
  23
+  uint8_t data[6];
  24
+  uint8_t _pin, _type;
  25
+  boolean read(void);
  26
+  unsigned long _lastreadtime;
  27
+  boolean firstreading;
  28
+
  29
+ public:
  30
+  DHT(uint8_t pin, uint8_t type);
  31
+  void begin(void);
  32
+  float readTemperature(void);
  33
+  float readHumidity(void);
  34
+
  35
+};
3  ArduinoAtmogram/src/arduino/librairies/DHTsensorLibrary/README.txt
... ...
@@ -0,0 +1,3 @@
  1
+This is an Arduino library for the DHT series of low cost temperature/humidity sensors. 
  2
+
  3
+To download. click the DOWNLOADS button in the top right corner, rename the uncompressed folder DHT. Check that the DHT folder contains DHT.cpp and DHT.h. Place the DHT library folder your <arduinosketchfolder>/libraries/ folder. You may need to create the libraries subfolder if its your first library. Restart the IDE.
44  ArduinoAtmogram/src/arduino/librairies/DHTsensorLibrary/examples/DHTtester/DHTtester.pde
... ...
@@ -0,0 +1,44 @@
  1
+// Example testing sketch for various DHT humidity/temperature sensors
  2
+// Written by ladyada, public domain
  3
+
  4
+#include "DHT.h"
  5
+
  6
+#define DHTPIN 2     // what pin we're connected to
  7
+
  8
+// Uncomment whatever type you're using!
  9
+//#define DHTTYPE DHT11   // DHT 11 
  10
+#define DHTTYPE DHT22   // DHT 22  (AM2302)
  11
+//#define DHTTYPE DHT21   // DHT 21 (AM2301)
  12
+
  13
+// Connect pin 1 (on the left) of the sensor to +5V
  14
+// Connect pin 2 of the sensor to whatever your DHTPIN is
  15
+// Connect pin 4 (on the right) of the sensor to GROUND
  16
+// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor
  17
+
  18
+DHT dht(DHTPIN, DHTTYPE);
  19
+
  20
+void setup() {
  21
+  Serial.begin(9600); 
  22
+  Serial.println("DHTxx test!");
  23
+ 
  24
+  dht.begin();
  25
+}
  26
+
  27
+void loop() {
  28
+  // Reading temperature or humidity takes about 250 milliseconds!
  29
+  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  30
+  float h = dht.readHumidity();
  31
+  float t = dht.readTemperature();
  32
+
  33
+  // check if returns are valid, if they are NaN (not a number) then something went wrong!
  34
+  if (isnan(t) || isnan(h)) {
  35
+    Serial.println("Failed to read from DHT");
  36
+  } else {
  37
+    Serial.print("Humidity: "); 
  38
+    Serial.print(h);
  39
+    Serial.print(" %\t");
  40
+    Serial.print("Temperature: "); 
  41
+    Serial.print(t);
  42
+    Serial.println(" *C");
  43
+  }
  44
+}
349  ArduinoAtmogram/src/arduino/librairies/Ethernet/Dhcp.cpp
... ...
@@ -0,0 +1,349 @@
  1
+// DHCP Library v0.3 - April 25, 2009
  2
+// Author: Jordan Terrell - blog.jordanterrell.com
  3
+
  4
+#include "w5100.h"
  5
+
  6
+#include <string.h>
  7
+#include <stdlib.h>
  8
+#include "Dhcp.h"
  9
+#include "Arduino.h"
  10
+#include "util.h"
  11
+
  12
+int DhcpClass::beginWithDHCP(uint8_t *mac, unsigned long timeout, unsigned long responseTimeout)
  13
+{
  14
+    uint8_t dhcp_state = STATE_DHCP_START;
  15
+    uint8_t messageType = 0;
  16
+  
  17
+    // zero out _dhcpMacAddr, _dhcpSubnetMask, _dhcpGatewayIp, _dhcpLocalIp, _dhcpDhcpServerIp, _dhcpDnsServerIp
  18
+    memset(_dhcpMacAddr, 0, 26); 
  19
+
  20
+    memcpy((void*)_dhcpMacAddr, (void*)mac, 6);
  21
+  
  22
+    // Pick an initial transaction ID
  23
+    _dhcpTransactionId = random(1UL, 2000UL);
  24
+    _dhcpInitialTransactionId = _dhcpTransactionId;
  25
+
  26
+    if (_dhcpUdpSocket.begin(DHCP_CLIENT_PORT) == 0)
  27
+    {
  28
+      // Couldn't get a socket
  29
+      return 0;
  30
+    }
  31
+    
  32
+    presend_DHCP();
  33
+    
  34
+    int result = 0;
  35
+    
  36
+    unsigned long startTime = millis();
  37
+    
  38
+    while(dhcp_state != STATE_DHCP_LEASED)
  39
+    {
  40
+        if(dhcp_state == STATE_DHCP_START)
  41
+        {
  42
+            _dhcpTransactionId++;
  43
+            
  44
+            send_DHCP_MESSAGE(DHCP_DISCOVER, ((millis() - startTime) / 1000));
  45
+            dhcp_state = STATE_DHCP_DISCOVER;
  46
+        }
  47
+        else if(dhcp_state == STATE_DHCP_DISCOVER)
  48
+        {
  49
+            uint32_t respId;
  50
+            messageType = parseDHCPResponse(responseTimeout, respId);
  51
+            if(messageType == DHCP_OFFER)
  52
+            {
  53
+                // We'll use the transaction ID that the offer came with,
  54
+                // rather than the one we were up to
  55
+                _dhcpTransactionId = respId;
  56
+                send_DHCP_MESSAGE(DHCP_REQUEST, ((millis() - startTime) / 1000));
  57
+                dhcp_state = STATE_DHCP_REQUEST;
  58
+            }
  59
+        }
  60
+        else if(dhcp_state == STATE_DHCP_REQUEST)
  61
+        {
  62
+            uint32_t respId;
  63
+            messageType = parseDHCPResponse(responseTimeout, respId);
  64
+            if(messageType == DHCP_ACK)
  65
+            {
  66
+                dhcp_state = STATE_DHCP_LEASED;
  67
+                result = 1;
  68
+            }
  69
+            else if(messageType == DHCP_NAK)
  70
+                dhcp_state = STATE_DHCP_START;
  71
+        }
  72
+        
  73
+        if(messageType == 255)
  74
+        {
  75
+            messageType = 0;
  76
+            dhcp_state = STATE_DHCP_START;
  77
+        }
  78
+        
  79
+        if(result != 1 && ((millis() - startTime) > timeout))
  80
+            break;
  81
+    }
  82
+    
  83
+    // We're done with the socket now
  84
+    _dhcpUdpSocket.stop();
  85
+    _dhcpTransactionId++;
  86
+    
  87
+    return result;
  88
+}
  89
+
  90
+void DhcpClass::presend_DHCP()
  91
+{
  92
+}
  93
+
  94
+void DhcpClass::send_DHCP_MESSAGE(uint8_t messageType, uint16_t secondsElapsed)
  95
+{
  96
+    uint8_t buffer[32];
  97
+    memset(buffer, 0, 32);
  98
+    IPAddress dest_addr( 255, 255, 255, 255 ); // Broadcast address
  99
+
  100
+    if (-1 == _dhcpUdpSocket.beginPacket(dest_addr, DHCP_SERVER_PORT))
  101
+    {
  102
+        // FIXME Need to return errors
  103
+        return;
  104
+    }
  105
+
  106
+    buffer[0] = DHCP_BOOTREQUEST;   // op
  107
+    buffer[1] = DHCP_HTYPE10MB;     // htype
  108
+    buffer[2] = DHCP_HLENETHERNET;  // hlen
  109
+    buffer[3] = DHCP_HOPS;          // hops
  110
+
  111
+    // xid
  112
+    unsigned long xid = htonl(_dhcpTransactionId);
  113
+    memcpy(buffer + 4, &(xid), 4);
  114
+
  115
+    // 8, 9 - seconds elapsed
  116
+    buffer[8] = ((secondsElapsed & 0xff00) >> 8);
  117
+    buffer[9] = (secondsElapsed & 0x00ff);
  118
+
  119
+    // flags
  120
+    unsigned short flags = htons(DHCP_FLAGSBROADCAST);
  121
+    memcpy(buffer + 10, &(flags), 2);
  122
+
  123
+    // ciaddr: already zeroed
  124
+    // yiaddr: already zeroed
  125
+    // siaddr: already zeroed
  126
+    // giaddr: already zeroed
  127
+
  128
+    //put data in W5100 transmit buffer
  129
+    _dhcpUdpSocket.write(buffer, 28);
  130
+
  131
+    memset(buffer, 0, 32); // clear local buffer
  132
+
  133
+    memcpy(buffer, _dhcpMacAddr, 6); // chaddr
  134
+
  135
+    //put data in W5100 transmit buffer
  136
+    _dhcpUdpSocket.write(buffer, 16);
  137
+
  138
+    memset(buffer, 0, 32); // clear local buffer
  139
+
  140
+    // leave zeroed out for sname && file
  141
+    // put in W5100 transmit buffer x 6 (192 bytes)
  142
+  
  143
+    for(int i = 0; i < 6; i++) {
  144
+        _dhcpUdpSocket.write(buffer, 32);
  145
+    }
  146
+  
  147
+    // OPT - Magic Cookie
  148
+    buffer[0] = (uint8_t)((MAGIC_COOKIE >> 24)& 0xFF);
  149
+    buffer[1] = (uint8_t)((MAGIC_COOKIE >> 16)& 0xFF);
  150
+    buffer[2] = (uint8_t)((MAGIC_COOKIE >> 8)& 0xFF);
  151
+    buffer[3] = (uint8_t)(MAGIC_COOKIE& 0xFF);
  152
+
  153
+    // OPT - message type
  154
+    buffer[4] = dhcpMessageType;
  155
+    buffer[5] = 0x01;
  156
+    buffer[6] = messageType; //DHCP_REQUEST;
  157
+
  158
+    // OPT - client identifier
  159
+    buffer[7] = dhcpClientIdentifier;
  160
+    buffer[8] = 0x07;
  161
+    buffer[9] = 0x01;
  162
+    memcpy(buffer + 10, _dhcpMacAddr, 6);
  163
+
  164
+    // OPT - host name
  165
+    buffer[16] = hostName;
  166
+    buffer[17] = strlen(HOST_NAME) + 3; // length of hostname + last 3 bytes of mac address
  167
+    strcpy((char*)&(buffer[18]), HOST_NAME);
  168
+
  169
+    buffer[24] = _dhcpMacAddr[3];
  170
+    buffer[25] = _dhcpMacAddr[4];
  171
+    buffer[26] = _dhcpMacAddr[5];
  172
+
  173
+    //put data in W5100 transmit buffer
  174
+    _dhcpUdpSocket.write(buffer, 27);
  175
+
  176
+    if(messageType == DHCP_REQUEST)
  177
+    {
  178
+        buffer[0] = dhcpRequestedIPaddr;
  179
+        buffer[1] = 0x04;
  180
+        buffer[2] = _dhcpLocalIp[0];
  181
+        buffer[3] = _dhcpLocalIp[1];
  182
+        buffer[4] = _dhcpLocalIp[2];
  183
+        buffer[5] = _dhcpLocalIp[3];
  184
+
  185
+        buffer[6] = dhcpServerIdentifier;
  186
+        buffer[7] = 0x04;
  187
+        buffer[8] = _dhcpDhcpServerIp[0];
  188
+        buffer[9] = _dhcpDhcpServerIp[1];
  189
+        buffer[10] = _dhcpDhcpServerIp[2];
  190
+        buffer[11] = _dhcpDhcpServerIp[3];
  191
+
  192
+        //put data in W5100 transmit buffer
  193
+        _dhcpUdpSocket.write(buffer, 12);
  194
+    }
  195
+    
  196
+    buffer[0] = dhcpParamRequest;
  197
+    buffer[1] = 0x06;
  198
+    buffer[2] = subnetMask;
  199
+    buffer[3] = routersOnSubnet;
  200
+    buffer[4] = dns;
  201
+    buffer[5] = domainName;
  202
+    buffer[6] = dhcpT1value;
  203
+    buffer[7] = dhcpT2value;
  204
+    buffer[8] = endOption;
  205
+    
  206
+    //put data in W5100 transmit buffer
  207
+    _dhcpUdpSocket.write(buffer, 9);
  208
+
  209
+    _dhcpUdpSocket.endPacket();
  210
+}
  211
+
  212
+uint8_t DhcpClass::parseDHCPResponse(unsigned long responseTimeout, uint32_t& transactionId)
  213
+{
  214
+    uint8_t type = 0;
  215
+    uint8_t opt_len = 0;
  216
+     
  217
+    unsigned long startTime = millis();
  218
+
  219
+    while(_dhcpUdpSocket.parsePacket() <= 0)
  220
+    {
  221
+        if((millis() - startTime) > responseTimeout)
  222
+        {
  223
+            return 255;
  224
+        }
  225
+        delay(50);
  226
+    }
  227
+    // start reading in the packet
  228
+    RIP_MSG_FIXED fixedMsg;
  229
+    _dhcpUdpSocket.read((uint8_t*)&fixedMsg, sizeof(RIP_MSG_FIXED));
  230
+  
  231
+    if(fixedMsg.op == DHCP_BOOTREPLY && _dhcpUdpSocket.remotePort() == DHCP_SERVER_PORT)
  232
+    {
  233
+        transactionId = ntohl(fixedMsg.xid);
  234
+        if(memcmp(fixedMsg.chaddr, _dhcpMacAddr, 6) != 0 || (transactionId < _dhcpInitialTransactionId) || (transactionId > _dhcpTransactionId))
  235
+        {
  236
+            // Need to read the rest of the packet here regardless
  237
+            _dhcpUdpSocket.flush();
  238
+            return 0;
  239
+        }
  240
+
  241
+        memcpy(_dhcpLocalIp, fixedMsg.yiaddr, 4);
  242
+
  243
+        // Skip to the option part
  244
+        // Doing this a byte at a time so we don't have to put a big buffer
  245
+        // on the stack (as we don't have lots of memory lying around)
  246
+        for (int i =0; i < (240 - (int)sizeof(RIP_MSG_FIXED)); i++)
  247
+        {
  248
+            _dhcpUdpSocket.read(); // we don't care about the returned byte
  249
+        }
  250
+
  251
+        while (_dhcpUdpSocket.available() > 0) 
  252
+        {
  253
+            switch (_dhcpUdpSocket.read()) 
  254
+            {
  255
+                case endOption :
  256
+                    break;
  257
+                    
  258
+                case padOption :
  259
+                    break;
  260
+                
  261
+                case dhcpMessageType :
  262
+                    opt_len = _dhcpUdpSocket.read();
  263
+                    type = _dhcpUdpSocket.read();
  264
+                    break;
  265
+                
  266
+                case subnetMask :
  267
+                    opt_len = _dhcpUdpSocket.read();
  268
+                    _dhcpUdpSocket.read(_dhcpSubnetMask, 4);
  269
+                    break;
  270
+                
  271
+                case routersOnSubnet :
  272
+                    opt_len = _dhcpUdpSocket.read();
  273
+                    _dhcpUdpSocket.read(_dhcpGatewayIp, 4);
  274
+                    for (int i = 0; i < opt_len-4; i++)
  275
+                    {
  276
+                        _dhcpUdpSocket.read();
  277
+                    }
  278
+                    break;
  279
+                
  280
+                case dns :
  281
+                    opt_len = _dhcpUdpSocket.read();
  282
+                    _dhcpUdpSocket.read(_dhcpDnsServerIp, 4);
  283
+                    for (int i = 0; i < opt_len-4; i++)
  284
+                    {
  285
+                        _dhcpUdpSocket.read();
  286
+                    }
  287
+                    break;
  288
+                
  289
+                case dhcpServerIdentifier :
  290
+                    opt_len = _dhcpUdpSocket.read();
  291
+                    if( *((uint32_t*)_dhcpDhcpServerIp) == 0 || 
  292
+                        IPAddress(_dhcpDhcpServerIp) == _dhcpUdpSocket.remoteIP() )
  293
+                    {
  294
+                        _dhcpUdpSocket.read(_dhcpDhcpServerIp, sizeof(_dhcpDhcpServerIp));
  295
+                    }
  296
+                    else
  297
+                    {
  298
+                        // Skip over the rest of this option
  299
+                        while (opt_len--)
  300
+                        {
  301
+                            _dhcpUdpSocket.read();
  302
+                        }
  303
+                    }
  304
+                    break;
  305
+                
  306
+                case dhcpIPaddrLeaseTime :
  307
+                default :
  308
+                    opt_len = _dhcpUdpSocket.read();
  309
+                    // Skip over the rest of this option
  310
+                    while (opt_len--)
  311
+                    {
  312
+                        _dhcpUdpSocket.read();
  313
+                    }
  314
+                    break;
  315
+            }
  316
+        }
  317
+    }
  318
+
  319
+    // Need to skip to end of the packet regardless here
  320
+    _dhcpUdpSocket.flush();
  321
+
  322
+    return type;
  323
+}
  324
+
  325
+IPAddress DhcpClass::getLocalIp()
  326
+{
  327
+    return IPAddress(_dhcpLocalIp);
  328
+}
  329
+
  330
+IPAddress DhcpClass::getSubnetMask()
  331
+{
  332
+    return IPAddress(_dhcpSubnetMask);
  333
+}
  334
+
  335
+IPAddress DhcpClass::getGatewayIp()
  336
+{
  337
+    return IPAddress(_dhcpGatewayIp);
  338
+}
  339
+
  340
+IPAddress DhcpClass::getDhcpServerIp()
  341
+{
  342
+    return IPAddress(_dhcpDhcpServerIp);
  343
+}
  344
+
  345
+IPAddress DhcpClass::getDnsServerIp()
  346
+{
  347
+    return IPAddress(_dhcpDnsServerIp);
  348
+}
  349
+
158  ArduinoAtmogram/src/arduino/librairies/Ethernet/Dhcp.h
... ...
@@ -0,0 +1,158 @@
  1
+// DHCP Library v0.3 - April 25, 2009
  2
+// Author: Jordan Terrell - blog.jordanterrell.com
  3
+
  4
+#ifndef Dhcp_h
  5
+#define Dhcp_h
  6
+
  7
+#include "EthernetUdp.h"
  8
+
  9
+/* DHCP state machine. */
  10
+#define STATE_DHCP_START 0
  11
+#define	STATE_DHCP_DISCOVER	1
  12
+#define	STATE_DHCP_REQUEST	2
  13
+#define	STATE_DHCP_LEASED	3
  14
+#define	STATE_DHCP_REREQUEST	4
  15
+#define	STATE_DHCP_RELEASE	5
  16
+
  17
+#define DHCP_FLAGSBROADCAST	0x8000
  18
+
  19
+/* UDP port numbers for DHCP */
  20
+#define	DHCP_SERVER_PORT	67	/* from server to client */
  21
+#define DHCP_CLIENT_PORT	68	/* from client to server */
  22
+
  23
+/* DHCP message OP code */
  24
+#define DHCP_BOOTREQUEST	1
  25
+#define DHCP_BOOTREPLY		2
  26
+
  27
+/* DHCP message type */
  28
+#define	DHCP_DISCOVER		1
  29
+#define DHCP_OFFER		  2
  30
+#define	DHCP_REQUEST		3
  31
+#define	DHCP_DECLINE		4
  32
+#define	DHCP_ACK		    5
  33
+#define DHCP_NAK		    6
  34
+#define	DHCP_RELEASE		7
  35
+#define DHCP_INFORM		  8
  36
+
  37
+#define DHCP_HTYPE10MB		1
  38
+#define DHCP_HTYPE100MB		2
  39
+
  40
+#define DHCP_HLENETHERNET	6
  41
+#define DHCP_HOPS		0
  42
+#define DHCP_SECS		0
  43
+
  44
+#define MAGIC_COOKIE		0x63825363
  45
+#define MAX_DHCP_OPT	16
  46
+
  47
+#define HOST_NAME "WIZnet"
  48
+
  49
+enum
  50
+{
  51
+	padOption		=	0,
  52
+	subnetMask		=	1,
  53
+	timerOffset		=	2,
  54
+	routersOnSubnet		=	3,
  55
+	/* timeServer		=	4,
  56
+	nameServer		=	5,*/
  57
+	dns			=	6,
  58
+	/*logServer		=	7,
  59
+	cookieServer		=	8,
  60
+	lprServer		=	9,
  61
+	impressServer		=	10,
  62
+	resourceLocationServer	=	11,*/
  63
+	hostName		=	12,
  64
+	/*bootFileSize		=	13,
  65
+	meritDumpFile		=	14,*/
  66
+	domainName		=	15,
  67
+	/*swapServer		=	16,
  68
+	rootPath		=	17,
  69
+	extentionsPath		=	18,
  70
+	IPforwarding		=	19,
  71
+	nonLocalSourceRouting	=	20,
  72
+	policyFilter		=	21,
  73
+	maxDgramReasmSize	=	22,
  74
+	defaultIPTTL		=	23,
  75
+	pathMTUagingTimeout	=	24,
  76
+	pathMTUplateauTable	=	25,
  77
+	ifMTU			=	26,
  78
+	allSubnetsLocal		=	27,
  79
+	broadcastAddr		=	28,
  80
+	performMaskDiscovery	=	29,
  81
+	maskSupplier		=	30,
  82
+	performRouterDiscovery	=	31,
  83
+	routerSolicitationAddr	=	32,
  84
+	staticRoute		=	33,
  85
+	trailerEncapsulation	=	34,
  86
+	arpCacheTimeout		=	35,
  87
+	ethernetEncapsulation	=	36,
  88
+	tcpDefaultTTL		=	37,
  89
+	tcpKeepaliveInterval	=	38,
  90
+	tcpKeepaliveGarbage	=	39,
  91
+	nisDomainName		=	40,
  92
+	nisServers		=	41,
  93
+	ntpServers		=	42,
  94
+	vendorSpecificInfo	=	43,
  95
+	netBIOSnameServer	=	44,
  96
+	netBIOSdgramDistServer	=	45,
  97
+	netBIOSnodeType		=	46,
  98
+	netBIOSscope		=	47,
  99
+	xFontServer		=	48,
  100
+	xDisplayManager		=	49,*/
  101
+	dhcpRequestedIPaddr	=	50,
  102
+	dhcpIPaddrLeaseTime	=	51,
  103
+	/*dhcpOptionOverload	=	52,*/
  104
+	dhcpMessageType		=	53,
  105
+	dhcpServerIdentifier	=	54,
  106
+	dhcpParamRequest	=	55,
  107
+	/*dhcpMsg			=	56,
  108
+	dhcpMaxMsgSize		=	57,*/
  109
+	dhcpT1value		=	58,
  110
+	dhcpT2value		=	59,
  111
+	/*dhcpClassIdentifier	=	60,*/
  112
+	dhcpClientIdentifier	=	61,
  113
+	endOption		=	255
  114
+};
  115
+
  116
+typedef struct _RIP_MSG_FIXED
  117
+{
  118
+	uint8_t  op; 
  119
+	uint8_t  htype; 
  120
+	uint8_t  hlen;
  121
+	uint8_t  hops;
  122
+	uint32_t xid;
  123
+	uint16_t secs;
  124
+	uint16_t flags;
  125
+	uint8_t  ciaddr[4];
  126
+	uint8_t  yiaddr[4];
  127
+	uint8_t  siaddr[4];
  128
+	uint8_t  giaddr[4];
  129
+	uint8_t  chaddr[6];
  130
+}RIP_MSG_FIXED;
  131
+
  132
+class DhcpClass {
  133
+private:
  134
+  uint32_t _dhcpInitialTransactionId;
  135
+  uint32_t _dhcpTransactionId;
  136
+  uint8_t  _dhcpMacAddr[6];
  137
+  uint8_t  _dhcpLocalIp[4];
  138
+  uint8_t  _dhcpSubnetMask[4];
  139
+  uint8_t  _dhcpGatewayIp[4];
  140
+  uint8_t  _dhcpDhcpServerIp[4];
  141
+  uint8_t  _dhcpDnsServerIp[4];
  142
+  EthernetUDP _dhcpUdpSocket;
  143
+  
  144
+  void presend_DHCP();
  145
+  void send_DHCP_MESSAGE(uint8_t, uint16_t);
  146
+  
  147
+  uint8_t parseDHCPResponse(unsigned long responseTimeout, uint32_t& transactionId);
  148
+public:
  149
+  IPAddress getLocalIp();
  150
+  IPAddress getSubnetMask();
  151
+  IPAddress getGatewayIp();
  152
+  IPAddress getDhcpServerIp();
  153
+  IPAddress getDnsServerIp();
  154
+  
  155
+  int beginWithDHCP(uint8_t *, unsigned long timeout = 60000, unsigned long responseTimeout = 4000);
  156
+};
  157
+
  158
+#endif
423  ArduinoAtmogram/src/arduino/librairies/Ethernet/Dns.cpp
... ...
@@ -0,0 +1,423 @@
  1
+// Arduino DNS client for WizNet5100-based Ethernet shield
  2
+// (c) Copyright 2009-2010 MCQN Ltd.
  3
+// Released under Apache License, version 2.0
  4
+
  5
+#include "w5100.h"
  6
+#include "EthernetUdp.h"
  7
+#include "util.h"
  8
+
  9
+#include "Dns.h"
  10
+#include <string.h>
  11
+//#include <stdlib.h>
  12
+#include "Arduino.h"
  13
+
  14
+
  15
+#define SOCKET_NONE	255
  16
+// Various flags and header field values for a DNS message
  17
+#define UDP_HEADER_SIZE	8
  18
+#define DNS_HEADER_SIZE	12
  19
+#define TTL_SIZE        4
  20
+#define QUERY_FLAG               (0)
  21
+#define RESPONSE_FLAG            (1<<15)
  22
+#define QUERY_RESPONSE_MASK      (1<<15)
  23
+#define OPCODE_STANDARD_QUERY    (0)
  24
+#define OPCODE_INVERSE_QUERY     (1<<11)
  25
+#define OPCODE_STATUS_REQUEST    (2<<11)
  26
+#define OPCODE_MASK              (15<<11)
  27
+#define AUTHORITATIVE_FLAG       (1<<10)
  28
+#define TRUNCATION_FLAG          (1<<9)
  29
+#define RECURSION_DESIRED_FLAG   (1<<8)
  30
+#define RECURSION_AVAILABLE_FLAG (1<<7)
  31
+#define RESP_NO_ERROR            (0)
  32
+#define RESP_FORMAT_ERROR        (1)
  33
+#define RESP_SERVER_FAILURE      (2)
  34
+#define RESP_NAME_ERROR          (3)
  35
+#define RESP_NOT_IMPLEMENTED     (4)
  36
+#define RESP_REFUSED             (5)
  37
+#define RESP_MASK                (15)
  38
+#define TYPE_A                   (0x0001)
  39
+#define CLASS_IN                 (0x0001)
  40
+#define LABEL_COMPRESSION_MASK   (0xC0)
  41
+// Port number that DNS servers listen on
  42
+#define DNS_PORT        53
  43
+
  44
+// Possible return codes from ProcessResponse
  45
+#define SUCCESS          1
  46
+#define TIMED_OUT        -1
  47
+#define INVALID_SERVER   -2
  48
+#define TRUNCATED        -3
  49
+#define INVALID_RESPONSE -4
  50
+
  51
+void DNSClient::begin(const IPAddress& aDNSServer)
  52
+{
  53
+    iDNSServer = aDNSServer;
  54
+    iRequestId = 0;
  55
+}
  56
+
  57
+
  58
+int DNSClient::inet_aton(const char* aIPAddrString, IPAddress& aResult)
  59
+{
  60
+    // See if we've been given a valid IP address
  61
+    const char* p =aIPAddrString;