Показать сообщение отдельно
Старый 06.08.2015, 13:21   #1295
kirillno
 
kirillno
 
Адрес: Запорожье Космос
Возраст: 38
Сообщений: 1,776
Машина: Peugeot 307 SW 1.6 & Citroen AX GT 1.4 TU3M
Длина: 20010мкм
Диаметр: 28мм
Отправить сообщение для kirillno с помощью ICQ Отправить сообщение для kirillno с помощью Skype™
По умолчанию

Цитата:
Сообщение от Out_law Посмотреть сообщение
кажи схему
arduino uno
Ethernet Shield W5100 R3
DS18B20




Внутри -  Код:


/*
Temperature Web Server

Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
* DS18S20 attached to pins D2
*/

#include <SPI.h>
#include <Ethernet.h>
#include <OneWire.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,230); //здесь указать IP в сети

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);

int DS18S20_Pin=2;
OneWire ds(DS18S20_Pin);

float maxtemp = -100;
float mintemp = 100;

void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}


// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}


void loop() {
float temperature = getTemp();
if (temperature > maxtemp){
maxtemp = temperature;
}
if (temperature < mintemp){
mintemp = temperature;
}

// listen for incoming clients
EthernetClient client = server.available();
if (client) {
Serial.println("new client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connnection: close");
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.println("<title>");
client.println("TempWebServer");
client.println("</title>");
client.println("<meta http-equiv=\"refresh\" content=\"10\">");
client.print("<h1> <center>");
client.print("Temp: ");
client.print(temperature);
client.print(" &degC");
client.print("</h1> </center>");
client.print("<h1> <center>");
client.print("Max: ");
client.print(maxtemp);
client.print(" &degC");
client.print("</h1> </center>");
client.print("<h1> <center>");
client.print("Min: ");
client.print(mintemp);
client.print(" &degC");
client.print("</h1> </center>");
client.println("<br />");
client.println("</html>");
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
Serial.println("client disonnected");
}
}

float getTemp(){ //returns the temperature from one DS18S20 in DEG Celsius

byte data[12];
byte addr[8];

if ( !ds.search(addr)) {
//no more sensors on chain, reset search
ds.reset_search();
return -1000;
}

if ( OneWire::crc8( addr, 7) != addr[7]) {
Serial.println("CRC is not valid!");
return -1000;
}

if ( addr[0] != 0x10 && addr[0] != 0x28) {
Serial.print("Device is not recognized");
return -1000;
}

ds.reset();
ds.select(addr);
ds.write(0x44,1); // start conversion, with parasite power on at the end

byte present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad


for (int i = 0; i < 9; i++) { // we need 9 bytes
data[i] = ds.read();
}

ds.reset_search();

byte MSB = data[1];
byte LSB = data[0];

float tempRead = ((MSB << 8) | LSB); //using two's compliment
float TemperatureSum = tempRead / 16;

return TemperatureSum;

}
__________________
Жопа она Везде.
kirillno вне форума  
2 (2)