-
Forum
-
Hardware
-
Hardware general
-
Tutorials for Arduino Uno with Ethernet Shield
Tutorials for Arduino Uno with Ethernet Shield
Less
More
-
Posts: 1
-
Thank you received: 0
-
-
9 years 1 month ago #2500
by iamkeq
Are there any examples of sensor setups using an ethernet shield on perhaps an UNO or are they all just using the ESP8266?
Please Log in or Create an account to join the conversation.
Less
More
-
Posts: 5
-
Thank you received: 2
-
-
9 years 1 month ago #2501
by ppecuch
I created this: UNO W5100 DS18B20 Virtual NODE
#include <Ethernet.h>
#include <SPI.h>
#include <Base64.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define EIOT_USERNAME "****"
#define EIOT_PASSWORD "****"
#define EIOT_IP_ADDRESS "10.0.0.139"
#define EIOT_PORT 8008
#define EIOT_NODE "N6S0"
#define REPORT_INTERVAL 60 // in sec
#define ONE_WIRE_BUS 3 // DS18B20 pin
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);
#define USER_PWD_LEN 40
char unameenc[USER_PWD_LEN];
float oldTemp;
byte mac[] = { **************** };
IPAddress ip(10, 0, 0, 181);
void setup() {
Serial.begin(115200);
lanConnect();
char uname[USER_PWD_LEN];
String str = String(EIOT_USERNAME)+":"+String(EIOT_PASSWORD);
str.toCharArray(uname, USER_PWD_LEN);
memset(unameenc,0,sizeof(unameenc));
base64_encode(unameenc, uname, strlen(uname));
oldTemp = -1;
}
void loop() {
float temp;
do {
DS18B20.requestTemperatures();
temp = DS18B20.getTempCByIndex(0);
Serial.print("Temperature: ");
Serial.println(temp);
} while (temp == 85.0 || temp == (-127.0));
if (temp != oldTemp)
{
sendTeperature(temp);
oldTemp = temp;
}
int cnt = REPORT_INTERVAL;
while(cnt--)
delay(1000);
}
void lanConnect()
{
EthernetClient client;
Serial.print("Connecting");
Ethernet.begin(mac,ip); {
delay(1000);
Serial.print(".");
}
Serial.println("");
Serial.println("Lan connected");
}
void sendTeperature(float temp)
{
EthernetClient client;
while(!client.connect(EIOT_IP_ADDRESS, EIOT_PORT)) {
Serial.println("connection failed");
lanConnect();
}
String url = "";
url += "/Api/EasyIoT/Control/Module/Virtual/"+ String(EIOT_NODE) + "/ControlLevel/"+String(temp); // generate EasIoT server node URL
Serial.print("POST data to URL: ");
Serial.println(url);
client.print(String("POST ") + url + " HTTP/1.1\r\n" +
"Host: " + String(EIOT_IP_ADDRESS) + "\r\n" +
"Connection: close\r\n" +
"Authorization: Basic " + unameenc + " \r\n" +
"Content-Length: 0\r\n" +
"\r\n");
delay(5000);
while(client.available()){
String line = client.readStringUntil('\r');
Serial.print(line);
}
Serial.println();
Serial.println("Connection closed");
}
Please Log in or Create an account to join the conversation.
-
Forum
-
Hardware
-
Hardware general
-
Tutorials for Arduino Uno with Ethernet Shield
Time to create page: 0.437 seconds