Skip to content

Code updated for Arduino 1.0.1

2013 Mai 16
by Jan

Hey all, just wanted to say that i updated the code so it compiles and uploads in the 1.0.1 IDE. The Arduino guys changed the function name “Client” to “EthernetClient” in the ethernet libraries, and i had to get the updates library for the Dallas Temperature sensors. Miles Burton is doing a good job with this:

Here’s the Code. It reads the sensor data, connects to the server and sends the data nicely.

#include //library for ethernet functions
#include //library for temperature sensors
#include //library for the onewire bus

#define Client EthernetClient
#define ONE_WIRE_BUS 7

// Ethernet settings
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; // mac-adress of arduino
byte ip[] = {192, 168, 0, 177}; // IP-adress of arduino
//byte gwaddr[] = {192, 168, 0, 1}; // IP-adress of gateway for later DNS implementation
//byte subnet[] = {255, 255, 255, 0}; // subnetmask for later DNS implementation
byte server[] = {192, 168, 0, 105}; // IP-adress of server arduino sends data to

EthernetClient client; // make a new instance from type "Client"

OneWire oneWire(ONE_WIRE_BUS); //the onewire bus is connected to pin 7 on arduino
DallasTemperature sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature

int numSensors; // variable to store the number of sensors

bool connectedn = false; // yes-no variable (boolean) to store if the arduino is connected to the server
int i = 0; // variable to count the sendings to the server

void setup(void) // setup-function runs at the startup of the arduino

Serial.begin(9600); // start the serial port service
Serial.println("1-Wire-to-Ethernet Bridge.");
Serial.println("Initializing Ethernet.");
Ethernet. begin(mac, ip); // start up ethernet with defined mac and ip
sensors.begin(); // start up the library

Serial.println("Scanning for 1-Wire sensors.");

int numSensors = sensors.getDeviceCount(); // store the number of sensors to numSensors

if(numSensors > 0) // if there is at least one sensor:
Serial.print("Enumerated "); //print the number of sensors to serial port
Serial.println( " sensors.");

else //if there is no sensor:
Serial.println("No sensors enumerated."); // tell the serial port


void loop(void) // loop function runs over and over again
int numSensors = sensors.getDeviceCount();
int temparray[numSensors]; // array with "numSensors" storage places for the temperature of each sensor

if(!connectedn) { // if "not" connected print: not connected ;)
Serial.println("Not connected");

if (client.connect(server, 80)){ // if connected, set variable connected to "true"
connectedn = true;
sensors.requestTemperatures(); // send the request for temperature to sensors (all sensors)
Serial.println("Connected to Server");
for(i=0; i

No comments yet

Leave a Reply

Note: You can use basic XHTML in your comments. Your email address will never be published.

Subscribe to this comment feed via RSS