Hello Fellow Homeseer's.
I thought i would share with you the Arduino sketch I have been using, it may or may not be of any specific use to anyone, but basically it allows you to connect an ethernet shield to an Arduino device, and when you add a DHT22 temperature and humidity sensor, and a light meter (which has a resistive output) the sketch allows you to serve a web page with the results.
The initial sketch was modified from the internet, but it seems to work fine for me. Example applications are Greenhouse Monitoring, or anywhere Temperature needs to be monitored. In reality is wouldn't be cheaper than a wireless temperature and humidity sensor but may be of use to someone.
Arduino 1.0 Sketch:
For this to work for you, the IP address, Subnet and Gateway would need to be changed to suit your network, also the DHT sensor is connected in this sketch to Pin 4.
Then the code below, thanks to MrHappy's great work will visit the IP address, download the page and extract the appropiate strings and write them to a log, you could then use Hs.SetDeviceString or Hs.SetDeviceValue to store these if needed. The IP address will need to be changed to suit the IP address you assign the Arduino + Ethernet Shield.
Hope it helps someone, thanks everyone for the help in getting this going.
I thought i would share with you the Arduino sketch I have been using, it may or may not be of any specific use to anyone, but basically it allows you to connect an ethernet shield to an Arduino device, and when you add a DHT22 temperature and humidity sensor, and a light meter (which has a resistive output) the sketch allows you to serve a web page with the results.
The initial sketch was modified from the internet, but it seems to work fine for me. Example applications are Greenhouse Monitoring, or anywhere Temperature needs to be monitored. In reality is wouldn't be cheaper than a wireless temperature and humidity sensor but may be of use to someone.
Arduino 1.0 Sketch:
For this to work for you, the IP address, Subnet and Gateway would need to be changed to suit your network, also the DHT sensor is connected in this sketch to Pin 4.
PHP Code:
/*
http://www.bajdi.com
Web Server showing the values from a DHT22 sensor
*/
#include <SPI.h>
#include <Ethernet.h>
#include <dht.h>
dht DHT;
#define DHTTYPE DHT22 // Sensor type
#define DHT22_PIN 4 // Data pin of DHT22 sensor
int lightLevel;
int temp;
int humi;
byte mac[] = { 0x00, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 2 };
byte gateway[] = { 192, 168, 1, 1 };
byte subnet[] = { 255, 255, 255, 0 };
EthernetServer server(80);
unsigned long lastTime = 0;
void setup()
{
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
delay(2000);
}
void loop()
{
// DHT measurements, max once per 2 seconds
if (millis() - 2000 > lastTime)
{
lastTime += 2000;
int chk = DHT.read22(DHT22_PIN);
temp = DHT.temperature;
humi = DHT.humidity;
}
// multiple analog reads smooths the signal
lightLevel = 0;
for (int i=0; i<16; i++) lightLevel += analogRead(A0);
lightLevel /= 16;
// listen for incoming clients
EthernetClient client = server.available();
if (client)
{
boolean currentLineIsBlank = true;
while (client.connected())
{
if (client.available())
{
char c = client.read();
// 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();
// output the value of the DHT22 sensor
client.print("Arduino powered webserver");
client.println("#<br />");
client.print("Serving temperature and humidity values from a DHT22 sensor");
client.println("#<br />");
client.print("Light : ");
client.print(lightLevel);
client.println(" #<br />");
client.print("Temperature (oC): ");
client.print(temp);
client.println(" #<br />");
client.print("Humidity (%): ");
client.print(humi);
client.println(" #<br />");
}
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(90);
// close the connection:
client.stop();
}
}
PHP Code:
Imports System.Text.RegularExpressions
Sub Main(ByVal Parms As Object)
Dim WebStr As String = "Arduino powered webserver#Serving temperature and humidity values from a DHT22 sensor#Light (Lux):
0#Temperature (oC): -24.40#Humidity (%): +54.00#"
'Dim Path As String = "http://192.168.1.2/"
'Dim WebStr As String = hs.geturl(Path, "/", FALSE, 80)
hs.writelog("RAW", WebStr)
Dim SplitStr() As String = Split(WebStr, "#")
'For i As Integer = 0 To UBound(SplitStr) - 1
'hs.writelog(i, SplitStr(i))
'Next
If UBound(SplitStr) > 0 Then
hs.writelog("Light", convert.todouble(Regex.Replace(SplitStr(2), "[^\d|\.\-]", "")) & " lux")
hs.writelog("Temp", convert.todouble(Regex.Replace(SplitStr(3), "[^\d|\.\-]", "")) & " °C")
hs.writelog("Humidity", convert.todouble(Regex.Replace(SplitStr(4), "[^\d|\.\-]", "")) & " %")
End If
End Sub
Comment