Skip to content

Commit febc2e2

Browse files
author
fpr
committed
Initial source files come from Ethernet library of Arduino 1.8.3
Signed-off-by: fpr <[email protected]>
1 parent 82979e5 commit febc2e2

32 files changed

+4485
-0
lines changed

AUTHORS

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
Alberto Panu https://github.com/bigjohnson
3+
Alasdair Allan https://github.com/aallan
4+
Alice Pintus https://github.com/00alis
5+
Adrian McEwen https://github.com/amcewen
6+
Arduino LLC http://arduino.cc/
7+
Arnie97 https://github.com/Arnie97
8+
Arturo Guadalupi https://github.com/agdl
9+
Bjoern Hartmann https://people.eecs.berkeley.edu/~bjoern/
10+
chaveiro https://github.com/chaveiro
11+
Cristian Maglie https://github.com/cmaglie
12+
David A. Mellis https://github.com/damellis
13+
Dino Tinitigan https://github.com/bigdinotech
14+
Eddy https://github.com/eddyst
15+
Federico Vanzati https://github.com/Fede85
16+
Federico Fissore https://github.com/ffissore
17+
Jack Christensen https://github.com/JChristensen
18+
Johann Richard https://github.com/johannrichard
19+
Jordan Terrell https://github.com/iSynaptic
20+
Justin Paulin https://github.com/interwho
21+
lathoub https://github.com/lathoub
22+
Martino Facchin https://github.com/facchinm
23+
Matthias Hertel https://github.com/mathertel
24+
Matthijs Kooijman https://github.com/matthijskooijman
25+
Matt Robinson https://github.com/ribbons
26+
MCQN Ltd. http://mcqn.com/
27+
Michael Amie https://github.com/michaelamie
28+
Michael Margolis https://github.com/michaelmargolis
29+
Norbert Truchsess https://github.com/ntruchsess
30+
Paul Stoffregen https://github.com/PaulStoffregen
31+
per1234 https://github.com/per1234
32+
Richard Sim
33+
Scott Fitzgerald https://github.com/shfitz
34+
Thibaut Viard https://github.com/aethaniel
35+
Tom Igoe https://github.com/tigoe
36+
WizNet http://www.wiznet.co.kr
37+
Zach Eveland https://github.com/zeveland
38+

README.adoc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
= Ethernet Library for Arduino =
2+
3+
With the Arduino Ethernet Shield, this library allows an Arduino board to connect to the internet.
4+
5+
For more information about this library please visit us at
6+
http://www.arduino.cc/en/Reference/Ethernet
7+
8+
== License ==
9+
10+
Copyright (c) 2010 Arduino LLC. All right reserved.
11+
12+
This library is free software; you can redistribute it and/or
13+
modify it under the terms of the GNU Lesser General Public
14+
License as published by the Free Software Foundation; either
15+
version 2.1 of the License, or (at your option) any later version.
16+
17+
This library is distributed in the hope that it will be useful,
18+
but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20+
Lesser General Public License for more details.
21+
22+
You should have received a copy of the GNU Lesser General Public
23+
License along with this library; if not, write to the Free Software
24+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
Advanced Chat Server
3+
4+
A more advanced server that distributes any incoming messages
5+
to all connected clients but the client the message comes from.
6+
To use, telnet to your device's IP address and type.
7+
You can see the client's input in the serial monitor as well.
8+
Using an Arduino Wiznet Ethernet shield.
9+
10+
Circuit:
11+
* Ethernet shield attached to pins 10, 11, 12, 13
12+
13+
created 18 Dec 2009
14+
by David A. Mellis
15+
modified 9 Apr 2012
16+
by Tom Igoe
17+
redesigned to make use of operator== 25 Nov 2013
18+
by Norbert Truchsess
19+
20+
*/
21+
22+
#include <SPI.h>
23+
#include <Ethernet.h>
24+
25+
// Enter a MAC address and IP address for your controller below.
26+
// The IP address will be dependent on your local network.
27+
// gateway and subnet are optional:
28+
byte mac[] = {
29+
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
30+
};
31+
IPAddress ip(192, 168, 1, 177);
32+
IPAddress myDns(192, 168, 1, 1);
33+
IPAddress gateway(192, 168, 1, 1);
34+
IPAddress subnet(255, 255, 0, 0);
35+
36+
37+
// telnet defaults to port 23
38+
EthernetServer server(23);
39+
40+
EthernetClient clients[4];
41+
42+
void setup() {
43+
// initialize the Ethernet device
44+
Ethernet.begin(mac, ip, myDns, gateway, subnet);
45+
// start listening for clients
46+
server.begin();
47+
// Open serial communications and wait for port to open:
48+
Serial.begin(9600);
49+
while (!Serial) {
50+
; // wait for serial port to connect. Needed for native USB port only
51+
}
52+
53+
54+
Serial.print("Chat server address:");
55+
Serial.println(Ethernet.localIP());
56+
}
57+
58+
void loop() {
59+
// wait for a new client:
60+
EthernetClient client = server.available();
61+
62+
// when the client sends the first byte, say hello:
63+
if (client) {
64+
65+
boolean newClient = true;
66+
for (byte i = 0; i < 4; i++) {
67+
//check whether this client refers to the same socket as one of the existing instances:
68+
if (clients[i] == client) {
69+
newClient = false;
70+
break;
71+
}
72+
}
73+
74+
if (newClient) {
75+
//check which of the existing clients can be overridden:
76+
for (byte i = 0; i < 4; i++) {
77+
if (!clients[i] && clients[i] != client) {
78+
clients[i] = client;
79+
// clear out the input buffer:
80+
client.flush();
81+
Serial.println("We have a new client");
82+
client.print("Hello, client number: ");
83+
client.print(i);
84+
client.println();
85+
break;
86+
}
87+
}
88+
}
89+
90+
if (client.available() > 0) {
91+
// read the bytes incoming from the client:
92+
char thisChar = client.read();
93+
// echo the bytes back to all other connected clients:
94+
for (byte i = 0; i < 4; i++) {
95+
if (clients[i] && (clients[i] != client)) {
96+
clients[i].write(thisChar);
97+
}
98+
}
99+
// echo the bytes to the server as well:
100+
Serial.write(thisChar);
101+
}
102+
}
103+
for (byte i = 0; i < 4; i++) {
104+
if (!(clients[i].connected())) {
105+
// client.stop() invalidates the internal socket-descriptor, so next use of == will allways return false;
106+
clients[i].stop();
107+
}
108+
}
109+
}
Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
/*
2+
SCP1000 Barometric Pressure Sensor Display
3+
4+
Serves the output of a Barometric Pressure Sensor as a web page.
5+
Uses the SPI library. For details on the sensor, see:
6+
http://www.sparkfun.com/commerce/product_info.php?products_id=8161
7+
8+
This sketch adapted from Nathan Seidle's SCP1000 example for PIC:
9+
http://www.sparkfun.com/datasheets/Sensors/SCP1000-Testing.zip
10+
11+
Circuit:
12+
SCP1000 sensor attached to pins 6,7, and 11 - 13:
13+
DRDY: pin 6
14+
CSB: pin 7
15+
MOSI: pin 11
16+
MISO: pin 12
17+
SCK: pin 13
18+
19+
created 31 July 2010
20+
by Tom Igoe
21+
*/
22+
23+
#include <Ethernet.h>
24+
// the sensor communicates using SPI, so include the library:
25+
#include <SPI.h>
26+
27+
28+
// assign a MAC address for the Ethernet controller.
29+
// fill in your address here:
30+
byte mac[] = {
31+
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
32+
};
33+
// assign an IP address for the controller:
34+
IPAddress ip(192, 168, 1, 20);
35+
36+
37+
// Initialize the Ethernet server library
38+
// with the IP address and port you want to use
39+
// (port 80 is default for HTTP):
40+
EthernetServer server(80);
41+
42+
43+
//Sensor's memory register addresses:
44+
const int PRESSURE = 0x1F; //3 most significant bits of pressure
45+
const int PRESSURE_LSB = 0x20; //16 least significant bits of pressure
46+
const int TEMPERATURE = 0x21; //16 bit temperature reading
47+
48+
// pins used for the connection with the sensor
49+
// the others you need are controlled by the SPI library):
50+
const int dataReadyPin = 6;
51+
const int chipSelectPin = 7;
52+
53+
float temperature = 0.0;
54+
long pressure = 0;
55+
long lastReadingTime = 0;
56+
57+
void setup() {
58+
// start the SPI library:
59+
SPI.begin();
60+
61+
// start the Ethernet connection and the server:
62+
Ethernet.begin(mac, ip);
63+
server.begin();
64+
65+
// initalize the data ready and chip select pins:
66+
pinMode(dataReadyPin, INPUT);
67+
pinMode(chipSelectPin, OUTPUT);
68+
69+
Serial.begin(9600);
70+
71+
//Configure SCP1000 for low noise configuration:
72+
writeRegister(0x02, 0x2D);
73+
writeRegister(0x01, 0x03);
74+
writeRegister(0x03, 0x02);
75+
76+
// give the sensor and Ethernet shield time to set up:
77+
delay(1000);
78+
79+
//Set the sensor to high resolution mode tp start readings:
80+
writeRegister(0x03, 0x0A);
81+
82+
}
83+
84+
void loop() {
85+
// check for a reading no more than once a second.
86+
if (millis() - lastReadingTime > 1000) {
87+
// if there's a reading ready, read it:
88+
// don't do anything until the data ready pin is high:
89+
if (digitalRead(dataReadyPin) == HIGH) {
90+
getData();
91+
// timestamp the last time you got a reading:
92+
lastReadingTime = millis();
93+
}
94+
}
95+
96+
// listen for incoming Ethernet connections:
97+
listenForEthernetClients();
98+
}
99+
100+
101+
void getData() {
102+
Serial.println("Getting reading");
103+
//Read the temperature data
104+
int tempData = readRegister(0x21, 2);
105+
106+
// convert the temperature to celsius and display it:
107+
temperature = (float)tempData / 20.0;
108+
109+
//Read the pressure data highest 3 bits:
110+
byte pressureDataHigh = readRegister(0x1F, 1);
111+
pressureDataHigh &= 0b00000111; //you only needs bits 2 to 0
112+
113+
//Read the pressure data lower 16 bits:
114+
unsigned int pressureDataLow = readRegister(0x20, 2);
115+
//combine the two parts into one 19-bit number:
116+
pressure = ((pressureDataHigh << 16) | pressureDataLow) / 4;
117+
118+
Serial.print("Temperature: ");
119+
Serial.print(temperature);
120+
Serial.println(" degrees C");
121+
Serial.print("Pressure: " + String(pressure));
122+
Serial.println(" Pa");
123+
}
124+
125+
void listenForEthernetClients() {
126+
// listen for incoming clients
127+
EthernetClient client = server.available();
128+
if (client) {
129+
Serial.println("Got a client");
130+
// an http request ends with a blank line
131+
boolean currentLineIsBlank = true;
132+
while (client.connected()) {
133+
if (client.available()) {
134+
char c = client.read();
135+
// if you've gotten to the end of the line (received a newline
136+
// character) and the line is blank, the http request has ended,
137+
// so you can send a reply
138+
if (c == '\n' && currentLineIsBlank) {
139+
// send a standard http response header
140+
client.println("HTTP/1.1 200 OK");
141+
client.println("Content-Type: text/html");
142+
client.println();
143+
// print the current readings, in HTML format:
144+
client.print("Temperature: ");
145+
client.print(temperature);
146+
client.print(" degrees C");
147+
client.println("<br />");
148+
client.print("Pressure: " + String(pressure));
149+
client.print(" Pa");
150+
client.println("<br />");
151+
break;
152+
}
153+
if (c == '\n') {
154+
// you're starting a new line
155+
currentLineIsBlank = true;
156+
} else if (c != '\r') {
157+
// you've gotten a character on the current line
158+
currentLineIsBlank = false;
159+
}
160+
}
161+
}
162+
// give the web browser time to receive the data
163+
delay(1);
164+
// close the connection:
165+
client.stop();
166+
}
167+
}
168+
169+
170+
//Send a write command to SCP1000
171+
void writeRegister(byte registerName, byte registerValue) {
172+
// SCP1000 expects the register name in the upper 6 bits
173+
// of the byte:
174+
registerName <<= 2;
175+
// command (read or write) goes in the lower two bits:
176+
registerName |= 0b00000010; //Write command
177+
178+
// take the chip select low to select the device:
179+
digitalWrite(chipSelectPin, LOW);
180+
181+
SPI.transfer(registerName); //Send register location
182+
SPI.transfer(registerValue); //Send value to record into register
183+
184+
// take the chip select high to de-select:
185+
digitalWrite(chipSelectPin, HIGH);
186+
}
187+
188+
189+
//Read register from the SCP1000:
190+
unsigned int readRegister(byte registerName, int numBytes) {
191+
byte inByte = 0; // incoming from the SPI read
192+
unsigned int result = 0; // result to return
193+
194+
// SCP1000 expects the register name in the upper 6 bits
195+
// of the byte:
196+
registerName <<= 2;
197+
// command (read or write) goes in the lower two bits:
198+
registerName &= 0b11111100; //Read command
199+
200+
// take the chip select low to select the device:
201+
digitalWrite(chipSelectPin, LOW);
202+
// send the device the register you want to read:
203+
int command = SPI.transfer(registerName);
204+
// send a value of 0 to read the first byte returned:
205+
inByte = SPI.transfer(0x00);
206+
207+
result = inByte;
208+
// if there's more than one byte returned,
209+
// shift the first byte then get the second byte:
210+
if (numBytes > 1) {
211+
result = inByte << 8;
212+
inByte = SPI.transfer(0x00);
213+
result = result | inByte;
214+
}
215+
// take the chip select high to de-select:
216+
digitalWrite(chipSelectPin, HIGH);
217+
// return the result:
218+
return (result);
219+
}

0 commit comments

Comments
 (0)