Hello. So I have some project.
Here is snippet of code with DHCP using
Serial.println("Attempting to obtain a DHCP lease...");
EthernetDHCP.begin(mac);
const byte* ipAddr = EthernetDHCP.ipAddress();
const byte* gatewayAddr = EthernetDHCP.gatewayIpAddress();
const byte* dnsAddr = EthernetDHCP.dnsIpAddress();
Serial.println("A DHCP lease has been obtained.");
Serial.print("My IP address is ");
Serial.println(ip_to_str(ipAddr));
Serial.print("Gateway IP address is ");
Serial.println(ip_to_str(gatewayAddr));
Serial.print("DNS IP address is ");
Serial.println(ip_to_str(dnsAddr));
It is working normal, but when i add definition of following function
float GetTemp()
{
byte present = 0;
byte data[12];
byte addr[8];
byte E_NoAddress = 201;
byte E_WrongCRC = 202;
byte E_InvalidDevice = 203;
if ( !ds1820.search(addr)) {
Serial.print("No more addresses.\n");
ds1820.reset_search();
return E_NoAddress;
}
Serial.print("R=");
for(byte i = 0; i < 8; i++) {
Serial.print(addr[i], HEX);
Serial.print(" ");
}
if ( OneWire::crc8( addr, 7) != addr[7]) {
Serial.print("CRC is not valid!\n");
return E_WrongCRC;
}
if ( addr[0] != 0x10) {
Serial.print("Device is not a DS18S20 family device.\n");
return E_InvalidDevice;
}
Serial.println("Starting conversion");
ds1820.reset();
ds1820.select(addr);
ds1820.write(0x44);
delay(1000);
Serial.println("Conversion completed, reading RAM...");
present = ds1820.reset();
ds1820.select(addr);
ds1820.write(0xBE);
for (byte i = 0; i < 9; i++)
data[i] = ds1820.read();
Serial.println("Data transmitted, processing...");
int HighByte, LowByte, TReading,SignBit,Whole,Fract,Tc_100;
float ret_val;
LowByte = data[0];
HighByte = data[1];
TReading = (HighByte << 8) + LowByte;
SignBit = TReading & 0x8000; // test most sig bit
if (SignBit) // negative
{
TReading = (TReading ^ 0xffff) + 1; // 2's comp
}
Tc_100 = (TReading*100/2);
Whole = Tc_100 / 100; // separate off the whole and fractional portions
Fract = Tc_100 % 100;
ret_val = Whole + Fract / 100;
Serial.print(" T = ");
if (SignBit)
{
Serial.print("-");
ret_val = - ret_val;
}
Serial.print(Whole);
Serial.print(".");
if (Fract < 10)
Serial.print("0");
Serial.print(Fract);
Serial.println();
return ret_val;
}
DHCP hanging on EthernetDHCP.begin(mac);
The strangest thing that i only define fuinction "GetTemp" not using it anywhere in the code.